currency_cloud 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -2
- data/README.md +3 -3
- data/currency_cloud.gemspec +3 -3
- data/lib/currency_cloud.rb +2 -2
- data/lib/currency_cloud/{resources/account.rb → account.rb} +4 -2
- data/lib/currency_cloud/actions.rb +13 -0
- data/lib/currency_cloud/actions/create.rb +4 -3
- data/lib/currency_cloud/actions/current.rb +3 -2
- data/lib/currency_cloud/actions/delete.rb +7 -12
- data/lib/currency_cloud/actions/find.rb +5 -7
- data/lib/currency_cloud/actions/instance_delete.rb +10 -0
- data/lib/currency_cloud/actions/retrieve.rb +5 -4
- data/lib/currency_cloud/actions/save.rb +5 -4
- data/lib/currency_cloud/actions/update.rb +6 -2
- data/lib/currency_cloud/{resources/balance.rb → balance.rb} +5 -3
- data/lib/currency_cloud/{resources/beneficiary.rb → beneficiary.rb} +7 -8
- data/lib/currency_cloud/client.rb +27 -0
- data/lib/currency_cloud/{resources/contact.rb → contact.rb} +4 -2
- data/lib/currency_cloud/{resources/conversion.rb → conversion.rb} +4 -6
- data/lib/currency_cloud/conversion_dates.rb +5 -0
- data/lib/currency_cloud/currency.rb +5 -0
- data/lib/currency_cloud/pagination.rb +1 -4
- data/lib/currency_cloud/{resources/payer.rb → payer.rb} +4 -2
- data/lib/currency_cloud/{resources/payment.rb → payment.rb} +4 -5
- data/lib/currency_cloud/rate.rb +21 -0
- data/lib/currency_cloud/rates.rb +5 -0
- data/lib/currency_cloud/reference.rb +26 -0
- data/lib/currency_cloud/request_handler.rb +9 -10
- data/lib/currency_cloud/resource.rb +52 -50
- data/lib/currency_cloud/response_handler.rb +6 -8
- data/lib/currency_cloud/session.rb +19 -19
- data/lib/currency_cloud/{resources/settlement.rb → settlement.rb} +20 -16
- data/lib/currency_cloud/settlement_account.rb +5 -0
- data/lib/currency_cloud/{resources/transaction.rb → transaction.rb} +4 -3
- data/lib/currency_cloud/version.rb +2 -4
- data/spec/currency_cloud/resource_spec.rb +7 -5
- data/spec/integration/actions_spec.rb +3 -3
- data/spec/integration/authentication_spec.rb +3 -3
- data/spec/integration/errors_spec.rb +6 -6
- data/spec/integration/rates_spec.rb +3 -3
- data/spec/integration/reference_spec.rb +5 -5
- data/spec/integration/settlements_spec.rb +8 -8
- metadata +20 -15
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/lib/currency_cloud/resources/rate.rb +0 -21
- data/lib/currency_cloud/resources/reference.rb +0 -29
@@ -0,0 +1,26 @@
|
|
1
|
+
module CurrencyCloud
|
2
|
+
class Reference
|
3
|
+
include CurrencyCloud::Resource
|
4
|
+
|
5
|
+
resource :reference
|
6
|
+
|
7
|
+
def self.currencies
|
8
|
+
response = client.get("currencies")
|
9
|
+
response['currencies'].map { |c| Currency.new(c)}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.beneficiary_required_details(params={})
|
13
|
+
client.get("beneficiary_required_details", params)["details"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.conversion_dates(params)
|
17
|
+
dates = client.get("conversion_dates", params)
|
18
|
+
ConversionDates.new(dates)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.settlement_accounts(params={})
|
22
|
+
response = client.get("settlement_accounts", params)
|
23
|
+
response['settlement_accounts'].map { |s| SettlementAccount.new(s) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,20 +1,18 @@
|
|
1
1
|
module CurrencyCloud
|
2
|
-
|
3
2
|
class RequestHandler
|
4
|
-
|
5
3
|
attr_reader :session
|
6
|
-
|
4
|
+
|
7
5
|
def initialize(session = CurrencyCloud.session)
|
8
6
|
@session = session
|
9
7
|
end
|
10
|
-
|
8
|
+
|
11
9
|
def get(route, params={}, opts={})
|
12
10
|
retry_authenticate('get', route, params, opts) do |url, params, options|
|
13
11
|
options.merge!(:query => params)
|
14
12
|
HTTParty.get(url, options)
|
15
13
|
end
|
16
14
|
end
|
17
|
-
|
15
|
+
|
18
16
|
def post(route, params={}, opts={})
|
19
17
|
retry_authenticate('post', route, params, opts) do |url, params, options|
|
20
18
|
options.merge!(:body => params)
|
@@ -23,9 +21,10 @@ module CurrencyCloud
|
|
23
21
|
end
|
24
22
|
|
25
23
|
private
|
24
|
+
|
26
25
|
def retry_authenticate(verb, route, params, opts)
|
27
26
|
should_retry = opts[:should_retry].nil? ? true : opts.delete(:should_retry)
|
28
|
-
|
27
|
+
|
29
28
|
params = process_params(params)
|
30
29
|
full_url = build_url(route)
|
31
30
|
|
@@ -56,9 +55,9 @@ module CurrencyCloud
|
|
56
55
|
|
57
56
|
def process_params(params)
|
58
57
|
if session && session.on_behalf_of && CurrencyCloud::UUID_REGEX.match(session.on_behalf_of)
|
59
|
-
params.merge!(on_behalf_of: session.on_behalf_of)
|
58
|
+
params.merge!(on_behalf_of: session.on_behalf_of)
|
60
59
|
end
|
61
|
-
|
60
|
+
|
62
61
|
params
|
63
62
|
end
|
64
63
|
|
@@ -67,9 +66,9 @@ module CurrencyCloud
|
|
67
66
|
headers['X-Auth-Token'] = session.token if session && session.token
|
68
67
|
headers
|
69
68
|
end
|
70
|
-
|
69
|
+
|
71
70
|
def build_url(route)
|
72
|
-
"#{session.environment_url}/#{CurrencyCloud::
|
71
|
+
"#{session.environment_url}/#{CurrencyCloud::API_VERSION}/" + route
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -1,79 +1,81 @@
|
|
1
|
-
require
|
1
|
+
require "set"
|
2
|
+
require_relative "./actions"
|
2
3
|
|
3
4
|
module CurrencyCloud
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def self.resource(resource=nil)
|
8
|
-
@resource ||= resource
|
5
|
+
module Resource
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
9
8
|
end
|
10
|
-
|
11
|
-
def self.actions(*actions)
|
12
|
-
@actions ||= actions
|
13
|
-
@actions.each do |action|
|
14
|
-
self.class_eval do
|
15
|
-
action_module = CurrencyCloud::Actions.const_get(action.to_s.capitalize)
|
16
|
-
self.extend(action_module)
|
17
|
-
end
|
18
9
|
|
19
|
-
|
20
|
-
self.send(:include, CurrencyCloud::Actions::Save) if action == :update
|
21
|
-
self.send(:include, CurrencyCloud::Actions::InstanceDelete) if action == :delete
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
10
|
attr_reader :changed_attributes
|
26
|
-
|
27
|
-
def initialize(
|
28
|
-
@
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
@attributes = attributes
|
29
14
|
@changed_attributes = Set.new
|
30
|
-
set_accessors(
|
31
|
-
end
|
32
|
-
|
33
|
-
def keys
|
34
|
-
@object.keys
|
15
|
+
set_accessors(valid_attributes)
|
35
16
|
end
|
36
17
|
|
37
18
|
def inspect
|
38
|
-
"#<#{self.class}:0x#{self.object_id.to_s(16)} #{@
|
19
|
+
"#<#{self.class}:0x#{self.object_id.to_s(16)} #{@attributes.inspect}>"
|
39
20
|
end
|
40
|
-
|
21
|
+
|
41
22
|
private
|
42
23
|
|
24
|
+
attr_reader :attributes
|
25
|
+
|
26
|
+
def resource
|
27
|
+
self.class.resource
|
28
|
+
end
|
29
|
+
|
30
|
+
def attributes=(new_values)
|
31
|
+
@attributes = new_values.select { |k, _| valid_attributes.include?(k) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid_attributes
|
35
|
+
@attributes.keys
|
36
|
+
end
|
37
|
+
|
43
38
|
def changed?
|
44
39
|
!@changed_attributes.empty?
|
45
40
|
end
|
46
|
-
|
41
|
+
|
42
|
+
def client
|
43
|
+
self.class.client
|
44
|
+
end
|
45
|
+
|
47
46
|
def metaclass
|
48
47
|
class << self; self; end
|
49
48
|
end
|
50
|
-
|
51
|
-
def set_accessors(
|
49
|
+
|
50
|
+
def set_accessors(attributes)
|
52
51
|
metaclass.instance_eval do
|
53
|
-
|
54
|
-
define_method(
|
55
|
-
define_method("#{
|
56
|
-
@
|
57
|
-
@changed_attributes <<
|
52
|
+
attributes.each do |attribute|
|
53
|
+
define_method(attribute) { @attributes[attribute] }
|
54
|
+
define_method("#{attribute}=".to_sym) do |value|
|
55
|
+
@attributes[attribute] = value
|
56
|
+
@changed_attributes << attribute
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def self.post(url, params={})
|
68
|
-
new(request.post(build_url(url), params))
|
69
|
-
end
|
62
|
+
module ClassMethods
|
63
|
+
def resource(resource = nil)
|
64
|
+
@resource ||= resource
|
65
|
+
end
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
def actions(*actions)
|
68
|
+
actions.each do |action|
|
69
|
+
self.class_eval do
|
70
|
+
action_module = CurrencyCloud::Actions.const_get(action.to_s.capitalize)
|
71
|
+
self.extend(action_module)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
def client
|
77
|
+
@client ||= Client.new(resource)
|
78
|
+
end
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
module CurrencyCloud
|
2
|
-
|
3
2
|
class ResponseHandler
|
4
|
-
|
5
3
|
attr_reader :verb, :route, :params, :response
|
6
|
-
|
4
|
+
|
7
5
|
def initialize(verb, route, params, response)
|
8
6
|
@verb = verb
|
9
7
|
@route = route
|
10
8
|
@params = params
|
11
9
|
@response = response
|
12
10
|
end
|
13
|
-
|
11
|
+
|
14
12
|
def process
|
15
13
|
if success?
|
16
14
|
return parsed_response
|
@@ -18,13 +16,13 @@ module CurrencyCloud
|
|
18
16
|
handle_failure
|
19
17
|
end
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
private
|
23
|
-
|
21
|
+
|
24
22
|
def success?
|
25
23
|
[200, 202].include?(response.code)
|
26
24
|
end
|
27
|
-
|
25
|
+
|
28
26
|
def handle_failure
|
29
27
|
error_class = case response.code
|
30
28
|
when 400 then BadRequestError
|
@@ -37,7 +35,7 @@ module CurrencyCloud
|
|
37
35
|
raise error_class.new(verb, route, params, response) if error_class
|
38
36
|
raise UnexpectedError.new(verb, route, params, response)
|
39
37
|
end
|
40
|
-
|
38
|
+
|
41
39
|
def parsed_response
|
42
40
|
@parsed_response ||= JSON.parse(response.body)
|
43
41
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
module CurrencyCloud
|
2
|
-
|
1
|
+
module CurrencyCloud
|
3
2
|
class Session
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
ENVIRONMENTS = {
|
4
|
+
:production => 'https://api.thecurrencycloud.com',
|
5
|
+
:demonstration => 'https://devapi.thecurrencycloud.com',
|
6
|
+
:uat => 'https://api-uat1.ccycloud.com'
|
7
|
+
}
|
8
|
+
|
9
9
|
attr_reader :environment, :login_id, :api_key
|
10
10
|
attr_accessor :token, :on_behalf_of
|
11
|
-
|
11
|
+
|
12
12
|
def self.validate_environment(environment)
|
13
|
-
unless
|
14
|
-
raise CurrencyCloud::GeneralError, "'#{environment}' is not a valid environment, must be one of: #{
|
13
|
+
unless ENVIRONMENTS.keys.include?(environment)
|
14
|
+
raise CurrencyCloud::GeneralError, "'#{environment}' is not a valid environment, must be one of: #{ENVIRONMENTS.keys.join(", ")}"
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def initialize(environment, login_id, api_key, token)
|
19
19
|
@environment = environment
|
20
20
|
@login_id = login_id
|
21
21
|
@api_key = api_key
|
22
|
-
|
22
|
+
|
23
23
|
if token
|
24
24
|
self.class.validate_environment(environment)
|
25
25
|
@token = token
|
@@ -27,16 +27,15 @@ module CurrencyCloud
|
|
27
27
|
authenticate
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def environment_url
|
32
|
-
|
32
|
+
ENVIRONMENTS[environment]
|
33
33
|
end
|
34
34
|
|
35
35
|
def close
|
36
36
|
request.post('authenticate/close_session')
|
37
37
|
end
|
38
|
-
|
39
|
-
|
38
|
+
|
40
39
|
def authenticate
|
41
40
|
validate
|
42
41
|
params = {:login_id => login_id, :api_key => api_key}
|
@@ -47,16 +46,17 @@ module CurrencyCloud
|
|
47
46
|
CurrencyCloud.token = @token = nil
|
48
47
|
authenticate
|
49
48
|
end
|
50
|
-
|
49
|
+
|
51
50
|
private
|
51
|
+
|
52
52
|
def validate
|
53
53
|
self.class.validate_environment(environment)
|
54
54
|
raise CurrencyCloud::GeneralError, "login_id must be set using CurrencyCloud.login_id=" unless login_id
|
55
55
|
raise CurrencyCloud::GeneralError, "api_key must be set using CurrencyCloud.api_key=" unless api_key
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def request
|
59
59
|
RequestHandler.new(self)
|
60
60
|
end
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
@@ -1,44 +1,48 @@
|
|
1
1
|
module CurrencyCloud
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class Settlement
|
3
|
+
include CurrencyCloud::Resource
|
4
|
+
|
5
5
|
resource :settlements
|
6
|
-
|
7
6
|
actions :create, :retrieve, :find, :delete
|
8
7
|
|
9
8
|
def add_conversion(conversion_id)
|
10
9
|
update_attributes(Settlement.add_conversion(id, conversion_id))
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
def remove_conversion(conversion_id)
|
14
13
|
update_attributes(Settlement.remove_conversion(id, conversion_id))
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
def release
|
18
17
|
update_attributes(Settlement.release(id))
|
19
18
|
end
|
20
|
-
|
19
|
+
|
21
20
|
def unrelease
|
22
21
|
update_attributes(Settlement.unrelease(id))
|
23
22
|
end
|
24
23
|
|
25
24
|
def self.add_conversion(settlement_id, conversion_id)
|
26
|
-
post("#{settlement_id}/add_conversion", conversion_id: conversion_id)
|
25
|
+
attrs = client.post("#{settlement_id}/add_conversion", conversion_id: conversion_id)
|
26
|
+
new(attrs)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def self.remove_conversion(settlement_id, conversion_id)
|
30
|
-
post("#{settlement_id}/remove_conversion", conversion_id: conversion_id)
|
30
|
+
attrs = client.post("#{settlement_id}/remove_conversion", conversion_id: conversion_id)
|
31
|
+
new(attrs)
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
def self.release(settlement_id)
|
34
|
-
post("#{settlement_id}/release")
|
35
|
+
attrs = client.post("#{settlement_id}/release")
|
36
|
+
new(attrs)
|
35
37
|
end
|
36
|
-
|
38
|
+
|
37
39
|
def self.unrelease(settlement_id)
|
38
|
-
post("#{settlement_id}/unrelease")
|
39
|
-
|
40
|
+
attrs = client.post("#{settlement_id}/unrelease")
|
41
|
+
new(attrs)
|
42
|
+
end
|
40
43
|
|
41
44
|
private
|
45
|
+
|
42
46
|
def update_attributes(settlement)
|
43
47
|
self.conversion_ids = settlement.conversion_ids
|
44
48
|
self.status = settlement.status
|
@@ -48,4 +52,4 @@ module CurrencyCloud
|
|
48
52
|
self
|
49
53
|
end
|
50
54
|
end
|
51
|
-
end
|
55
|
+
end
|