Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc6aa1b

Browse files
author
hamzatayeb
committed
v. 0.1.2 - support of Objects 'create' method and more
1 parent 0b10fb0 commit fc6aa1b

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Unreleased
2+
3+
# 0.1.2 - April 14, 2016
4+
5+
- Add support for Objects `create` method
6+
- Better formatting for `APIError` exceptions
7+
- Add Transactions `get_order` method
8+
19
# 0.1.1 - February 6, 2016
210

311
- Update documentation

lib/ontraport.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def self.clear_describe_cache!
4444
@objects_meta_cache = nil
4545
end
4646

47-
# @!group Accessor methods
47+
# @!group "Objects" Methods
4848

4949
# Retrieve a single object of the specified type.
5050
#
@@ -74,8 +74,20 @@ def self.get_objects object_type, params={}
7474
objects_call :get, object_type, endpoint: '/objects', data: params
7575
end
7676

77-
# @!endgroup
78-
# @!group Modifier methods
77+
# Create an object with the given data
78+
#
79+
# @example
80+
# Ontraport.create :contact, { email: '[email protected]', firstname: 'Foo' }
81+
# #=> #<Ontraport::Response @data=...>
82+
#
83+
# @see https://api.ontraport.com/doc/#!/objects/createObject API docs
84+
#
85+
# @param object_type [Symbol] the type of object
86+
# @param params [Hash] input data
87+
# @return [Response]
88+
def self.create object_type, params
89+
objects_call :post, object_type, endpoint: '/objects', data: params
90+
end
7991

8092
# Create an object with the given data, or merge if the unique field matches another row.
8193
#
@@ -139,6 +151,19 @@ def self.untag_objects object_type, object:, tag:
139151
objects_call :delete, object_type, endpoint: '/objects/tag', data: params
140152
end
141153

154+
# @!endgroup
155+
# @!group "Transactions" Methods
156+
157+
# Get full information about an order
158+
#
159+
# @see https://api.ontraport.com/doc/#!/transactions/getOrder API docs
160+
#
161+
# @param order_id [Integer] Id of the order
162+
# @return [Response]
163+
def self.get_order order_id
164+
request_with_authentication :get, endpoint: '/transaction/order', data: { id: order_id }
165+
end
166+
142167
# @!endgroup
143168

144169
private
@@ -154,7 +179,8 @@ def self.request_with_authentication method, endpoint:, data: nil
154179
response = HTTParty.send *args, **kwargs
155180

156181
unless response.code.eql? 200
157-
raise APIError.new response.body
182+
error = "#{response.code} #{response.msg}"
183+
raise APIError.new(response.body.present? ? "#{error} - #{response.body}" : error)
158184
end
159185

160186
Response.new **response.parsed_response.symbolize_keys

lib/ontraport/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Ontraport
2-
VERSION = '0.1.1'
2+
VERSION = '0.1.2'
33
end

ontraport.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
1818
s.files = Dir.glob("{lib}/**/*") + s.extra_rdoc_files
1919
s.homepage = 'https://github.com/hamzatayeb/ontraport-ruby'
2020
s.license = 'MIT'
21-
s.required_ruby_version = '~> 2.1.8'
21+
s.required_ruby_version = '~> 2'
2222
s.add_dependency 'httparty', ['~> 0.13']
2323
end

0 commit comments

Comments
 (0)