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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +1 -2
  4. data/README.md +3 -3
  5. data/currency_cloud.gemspec +3 -3
  6. data/lib/currency_cloud.rb +2 -2
  7. data/lib/currency_cloud/{resources/account.rb → account.rb} +4 -2
  8. data/lib/currency_cloud/actions.rb +13 -0
  9. data/lib/currency_cloud/actions/create.rb +4 -3
  10. data/lib/currency_cloud/actions/current.rb +3 -2
  11. data/lib/currency_cloud/actions/delete.rb +7 -12
  12. data/lib/currency_cloud/actions/find.rb +5 -7
  13. data/lib/currency_cloud/actions/instance_delete.rb +10 -0
  14. data/lib/currency_cloud/actions/retrieve.rb +5 -4
  15. data/lib/currency_cloud/actions/save.rb +5 -4
  16. data/lib/currency_cloud/actions/update.rb +6 -2
  17. data/lib/currency_cloud/{resources/balance.rb → balance.rb} +5 -3
  18. data/lib/currency_cloud/{resources/beneficiary.rb → beneficiary.rb} +7 -8
  19. data/lib/currency_cloud/client.rb +27 -0
  20. data/lib/currency_cloud/{resources/contact.rb → contact.rb} +4 -2
  21. data/lib/currency_cloud/{resources/conversion.rb → conversion.rb} +4 -6
  22. data/lib/currency_cloud/conversion_dates.rb +5 -0
  23. data/lib/currency_cloud/currency.rb +5 -0
  24. data/lib/currency_cloud/pagination.rb +1 -4
  25. data/lib/currency_cloud/{resources/payer.rb → payer.rb} +4 -2
  26. data/lib/currency_cloud/{resources/payment.rb → payment.rb} +4 -5
  27. data/lib/currency_cloud/rate.rb +21 -0
  28. data/lib/currency_cloud/rates.rb +5 -0
  29. data/lib/currency_cloud/reference.rb +26 -0
  30. data/lib/currency_cloud/request_handler.rb +9 -10
  31. data/lib/currency_cloud/resource.rb +52 -50
  32. data/lib/currency_cloud/response_handler.rb +6 -8
  33. data/lib/currency_cloud/session.rb +19 -19
  34. data/lib/currency_cloud/{resources/settlement.rb → settlement.rb} +20 -16
  35. data/lib/currency_cloud/settlement_account.rb +5 -0
  36. data/lib/currency_cloud/{resources/transaction.rb → transaction.rb} +4 -3
  37. data/lib/currency_cloud/version.rb +2 -4
  38. data/spec/currency_cloud/resource_spec.rb +7 -5
  39. data/spec/integration/actions_spec.rb +3 -3
  40. data/spec/integration/authentication_spec.rb +3 -3
  41. data/spec/integration/errors_spec.rb +6 -6
  42. data/spec/integration/rates_spec.rb +3 -3
  43. data/spec/integration/reference_spec.rb +5 -5
  44. data/spec/integration/settlements_spec.rb +8 -8
  45. metadata +20 -15
  46. data/.ruby-gemset +0 -1
  47. data/.ruby-version +0 -1
  48. data/lib/currency_cloud/resources/rate.rb +0 -21
  49. data/lib/currency_cloud/resources/reference.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05d3528f511962b03532b5118e6aa1f12e93dee1
4
- data.tar.gz: 90e96cf501b438ca7f3c93f4b20ee4ba0ac5a16c
3
+ metadata.gz: 56244f4c79912b074416b099f75d2d8b6b64fae8
4
+ data.tar.gz: 9e0a5976808d20873f383eface2acecb96a17554
5
5
  SHA512:
6
- metadata.gz: 8fada2f9e4281e22a143fbe0339f3b0d9379fc18195ac189524c3ea5ddd1ace4709601cb492174e0f6a19f39f902e0a640b50e684296ad2992e4845280cf3331
7
- data.tar.gz: e2a7fd923bc03e71561a4e70efa055e1aac5226045d6ca1fd51091d7fa7b2cf56337ea5a43cd1da7ee66498c7cb6b0933bcffda41f3907dc0357f1d0485c0f66
6
+ metadata.gz: 8a46e98ba3b1f58a7ea720d6637fd90f9d000b898365fa47328b923d527ac1ff8ab164a326008489889e4d9ac7196a47365446e3e8cd1001fb7875358a909237
7
+ data.tar.gz: 6d22fdca021e1c1eded5def2e69ae701fa77bdbf9b4c68ff0e2cf723203fbe6437b91e8b4d4d27b8f064e14a1d60f4d70db7e1f54cf7796ceefca9b999efe0d6
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
2
  *.gem
3
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
-
4
3
  gem 'sinatra'
5
4
  gem 'guard-rspec', require: false
6
5
 
7
- gemspec
6
+ gemspec
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Currency Cloud
4
4
 
5
- This is the official Ruby SDK for v2 of Currency Cloud's API. Additional documentation
5
+ This is the official Ruby SDK for v2 of Currency Cloud's API. Additional documentation
6
6
  for each API endpoint can be found at [connect.currencycloud.com][connect]. If you have any queries or you require support, please contact our implementation team at implementation@currencycloud.com.
7
7
 
8
8
  ## Installation
@@ -59,7 +59,7 @@ balances = CurrencyCloud::Balance.find
59
59
  ```
60
60
 
61
61
  ## On Behalf Of
62
- If you want to make calls on behalf of another user (e.g. someone who has a sub-account with you), you
62
+ If you want to make calls on behalf of another user (e.g. someone who has a sub-account with you), you
63
63
  can execute certain commands 'on behalf of' the user's contact_id. Here is an example:
64
64
 
65
65
  ```ruby
@@ -126,7 +126,7 @@ error in any correspondence can be very helpful.
126
126
 
127
127
  # Development
128
128
 
129
- Test cases can be run with: `bundle exec rspec`. There is also a `Guardfile` that
129
+ Test cases can be run with: `bundle exec rspec`. There is also a `Guardfile` that
130
130
  is useful for continuously rerunning tests while you develop.
131
131
 
132
132
  ## Dependencies
@@ -4,7 +4,7 @@ require 'currency_cloud/version'
4
4
 
5
5
  spec = Gem::Specification.new do |s|
6
6
  s.name = 'currency_cloud'
7
- s.version = CurrencyCloud::Version
7
+ s.version = CurrencyCloud::VERSION
8
8
  s.summary = 'Ruby SDK for the Currency Cloud API'
9
9
  s.description = 'Ruby SDK for the Currency Cloud API - https://connect.currencycloud.com/'
10
10
  s.authors = ['Liam McAndrew', 'Richard Nienaber']
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |s|
15
15
 
16
16
  s.add_dependency('httparty', '~> 0.13')
17
17
  s.add_dependency('json', '~> 1.8')
18
-
18
+
19
19
  s.add_development_dependency('rspec', '~> 3.1')
20
20
  s.add_development_dependency('rake', '~> 10.3')
21
21
  s.add_development_dependency('webmock', '~> 1.21')
@@ -25,4 +25,4 @@ spec = Gem::Specification.new do |s|
25
25
  s.test_files = `git ls-files -- spec/*`.split("\n")
26
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
27
  s.require_paths = ['lib']
28
- end
28
+ end
@@ -13,7 +13,7 @@ module CurrencyCloud
13
13
  class << self
14
14
  attr_accessor :environment, :login_id, :api_key, :token
15
15
  end
16
-
16
+
17
17
  def self.session
18
18
  @session ||= CurrencyCloud::Session.new(environment, login_id, api_key, token)
19
19
  end
@@ -22,7 +22,7 @@ module CurrencyCloud
22
22
  @session.close if @session
23
23
  true
24
24
  end
25
-
25
+
26
26
  def self.reset_session
27
27
  @session = nil
28
28
  @token = nil
@@ -1,6 +1,8 @@
1
1
  module CurrencyCloud
2
- class Account < Resource
2
+ class Account
3
+ include CurrencyCloud::Resource
4
+
3
5
  resource :accounts
4
6
  actions :create, :retrieve, :find, :update, :current
5
7
  end
6
- end
8
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "actions/create"
2
+ require_relative "actions/current"
3
+ require_relative "actions/delete"
4
+ require_relative "actions/find"
5
+ require_relative "actions/instance_delete"
6
+ require_relative "actions/retrieve"
7
+ require_relative "actions/save"
8
+ require_relative "actions/update"
9
+
10
+ module CurrencyCloud
11
+ module Actions
12
+ end
13
+ end
@@ -1,9 +1,10 @@
1
1
  module CurrencyCloud
2
2
  module Actions
3
3
  module Create
4
- def create(params={})
5
- post("create", params)
4
+ def create(params = {})
5
+ attrs = client.post("create", params)
6
+ new(attrs)
6
7
  end
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -2,8 +2,9 @@ module CurrencyCloud
2
2
  module Actions
3
3
  module Current
4
4
  def current
5
- get('current')
5
+ attrs = client.get("current")
6
+ new(attrs)
6
7
  end
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -1,21 +1,16 @@
1
1
  module CurrencyCloud
2
2
  module Actions
3
-
4
3
  module Delete
4
+ def self.extended(base)
5
+ base.send(:include, InstanceDelete) # Private before Ruby 2.1
6
+ end
5
7
 
6
8
  # TODO: Set state to be deleted
7
9
  # TODO: Disable all actionable methods / freeze?
8
-
9
10
  def delete(id)
10
- post("#{id}/delete")
11
- end
12
- end
13
-
14
- module InstanceDelete
15
- def delete
16
- self.class.delete(id)
17
- self
18
- end
11
+ attrs = client.post("#{id}/delete")
12
+ new(attrs)
13
+ end
19
14
  end
20
15
  end
21
- end
16
+ end
@@ -1,17 +1,15 @@
1
1
  module CurrencyCloud
2
2
  module Actions
3
-
3
+
4
4
  module Find
5
5
 
6
6
  def find(params={})
7
- response = request.get("#{self.resource}/find", params)
7
+ response = client.get("find", params)
8
8
  mixin_class.new(self.resource, self, response)
9
9
  end
10
-
11
- def first(params={})
12
- entities = find((params || {}).merge(per_page: 1))
13
- return nil if entities.empty?
14
10
 
11
+ def first(params={})
12
+ entities = find(params.merge(per_page: 1)) || []
15
13
  entities.first
16
14
  end
17
15
 
@@ -24,4 +22,4 @@ module CurrencyCloud
24
22
  end
25
23
  end
26
24
  end
27
- end
25
+ end
@@ -0,0 +1,10 @@
1
+ module CurrencyCloud
2
+ module Actions
3
+ module InstanceDelete
4
+ def delete
5
+ self.class.delete(id)
6
+ self
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,9 +1,10 @@
1
1
  module CurrencyCloud
2
- module Actions
2
+ module Actions
3
3
  module Retrieve
4
4
  def retrieve(id)
5
- get(id)
6
- end
5
+ attrs = client.get(id)
6
+ new(attrs)
7
+ end
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -3,12 +3,13 @@ module CurrencyCloud
3
3
  module Save
4
4
  def save
5
5
  return self if changed_attributes.empty?
6
-
7
- params = Hash[changed_attributes.map { |k| [k, self.send(k)] }]
8
- post(id, params)
6
+
7
+ params = attributes.select { |attr| changed_attributes.include?(attr) }
8
+ attrs = client.post(id, params)
9
9
  changed_attributes.clear
10
+ self.attributes = attrs
10
11
  self
11
12
  end
12
13
  end
13
14
  end
14
- end
15
+ end
@@ -1,12 +1,16 @@
1
1
  module CurrencyCloud
2
2
  module Actions
3
3
  module Update
4
+ def self.extended(base)
5
+ base.send(:include, Save) # Private before Ruby 2.1
6
+ end
4
7
 
5
8
  # TODO: Add .save instance method, which calls update on changed attributes
6
9
 
7
10
  def update(id, params)
8
- post("#{id}", params)
11
+ attrs = client.post("#{id}", params)
12
+ new(attrs)
9
13
  end
10
14
  end
11
15
  end
12
- end
16
+ end
@@ -1,10 +1,12 @@
1
1
  module CurrencyCloud
2
- class Balance < Resource
2
+ class Balance
3
+ include CurrencyCloud::Resource
4
+
3
5
  resource :balances
4
6
  actions :find
5
7
 
6
8
  def self.currency(ccy)
7
- get(ccy)
9
+ new(client.get(ccy))
8
10
  end
9
11
  end
10
- end
12
+ end
@@ -1,13 +1,12 @@
1
1
  module CurrencyCloud
2
-
3
- class Beneficiary < Resource
4
-
2
+ class Beneficiary
3
+ include CurrencyCloud::Resource
4
+
5
5
  resource :beneficiaries
6
-
7
6
  actions :create, :retrieve, :find, :update, :delete
8
-
7
+
9
8
  def self.validate(params)
10
- post('validate', params)
11
- end
9
+ new(client.post("validate", params))
10
+ end
12
11
  end
13
- end
12
+ end
@@ -0,0 +1,27 @@
1
+ module CurrencyCloud
2
+ class Client
3
+ def initialize(resource)
4
+ @resource = resource
5
+ end
6
+
7
+ def get(url, params={})
8
+ request.get(build_url(url), params)
9
+ end
10
+
11
+ def post(url, params={})
12
+ request.post(build_url(url), params)
13
+ end
14
+
15
+ def build_url(url)
16
+ "#{resource}/#{url}"
17
+ end
18
+
19
+ def request
20
+ RequestHandler.new
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :resource
26
+ end
27
+ end
@@ -1,6 +1,8 @@
1
1
  module CurrencyCloud
2
- class Contact < Resource
2
+ class Contact
3
+ include CurrencyCloud::Resource
4
+
3
5
  resource :contacts
4
6
  actions :create, :retrieve, :find, :update, :current
5
7
  end
6
- end
8
+ end
@@ -1,10 +1,8 @@
1
1
  module CurrencyCloud
2
-
3
- class Conversion < Resource
4
-
2
+ class Conversion
3
+ include CurrencyCloud::Resource
4
+
5
5
  resource :conversions
6
-
7
6
  actions :create, :retrieve, :find
8
-
9
7
  end
10
- end
8
+ end
@@ -0,0 +1,5 @@
1
+ module CurrencyCloud
2
+ class ConversionDates
3
+ include CurrencyCloud::Resource
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module CurrencyCloud
2
+ class Currency
3
+ include CurrencyCloud::Resource
4
+ end
5
+ end
@@ -1,7 +1,4 @@
1
1
  module CurrencyCloud
2
-
3
2
  class Pagination < OpenStruct
4
-
5
3
  end
6
-
7
- end
4
+ end
@@ -1,6 +1,8 @@
1
1
  module CurrencyCloud
2
- class Payer < Resource
2
+ class Payer
3
+ include CurrencyCloud::Resource
4
+
3
5
  resource :payers
4
6
  actions :retrieve
5
7
  end
6
- end
8
+ end
@@ -1,9 +1,8 @@
1
1
  module CurrencyCloud
2
-
3
- class Payment < Resource
4
-
2
+ class Payment
3
+ include CurrencyCloud::Resource
4
+
5
5
  resource :payments
6
-
7
6
  actions :create, :retrieve, :find, :delete, :update
8
7
  end
9
- end
8
+ end
@@ -0,0 +1,21 @@
1
+ module CurrencyCloud
2
+ class Rate
3
+ include CurrencyCloud::Resource
4
+
5
+ resource :rates
6
+
7
+ def self.find(params)
8
+ response = client.get("find", params)
9
+
10
+ rates = response["rates"].map do |currency_pair, (bid, offer)|
11
+ new(currency_pair: currency_pair, bid: bid, offer: offer)
12
+ end
13
+
14
+ Rates.new(currencies: rates, unavailable: response["unavailable"])
15
+ end
16
+
17
+ def self.detailed(params)
18
+ new(client.get("detailed", params))
19
+ end
20
+ end
21
+ end