xe_client 0.2.1 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f1177833638b0c28803459d8331025da54f2fae6
4
- data.tar.gz: 57b01c71dcfdae7394d4d7b1f175c8f27d435166
2
+ SHA256:
3
+ metadata.gz: faccd61a405fbd11dfb9873a31a602e8b6b088500d420061318d8dd4525eae9a
4
+ data.tar.gz: ad0f22f7e5fd44f582a81250ef7415db193b0ccc066ac6de540e0a1f98a22463
5
5
  SHA512:
6
- metadata.gz: a7db6850029ca84dd8df1d9e0f604d512dd6dc930f1d7a975ede64d42fe068c8b1beae4c9cfd8b945258cdd85089e624b7f62a4f85b7529469152b78bf7adaa9
7
- data.tar.gz: 2883328f43a6d02323be5341ceb5f04728b8fa20f78c8ab060a3f1bec8e74f3d7f1b5bd11957d97e76ec47c3c64295d6eaf5acf7d20d16f67d0652577b5f452f
6
+ metadata.gz: e6d9a02af3aeee2f477861297ea8a5f7b26dc3b6f35a09c1c11cd9de0b8e3566a4a14f1203ef5c6e03819c6ddaab0131ecdab8d942c14d5732725ccc1e268653
7
+ data.tar.gz: 45335dc7e9974c01744871f769043c4e4ef00bb9daf1301207c9c280217b8b3d7a90271c3a9e67f7ddefb76fbf7ab787d06446eb30d314ee8c23301719facf15
@@ -1,5 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.12.5
4
+ - 2.6.3
5
+ before_install: gem install bundler:2.0
6
+ before_script:
7
+ - cp spec/config.yml{.sample,}
@@ -2,6 +2,17 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [1.0.0] - 2020-06-30
6
+ ### Changed
7
+ - Changed `url` to `host` fot the XE API host (defaults to https://xecdapi.xe.com)
8
+ - Changed `#convert_from` to accept keyword args named more like the API's param names:
9
+ - `from` instead of the first argument aka `base_currency`
10
+ - `to` instead of the second argument aka `counter_currencies`
11
+ - `amount` instead of the third argument
12
+ - No longer raise exception when XE's response contains an error. Developer should use `#success?` on the response instead and inspect `#error` to see details.
13
+ ### Added
14
+ - `historic_rate_period` call to get historic rates over a period
15
+
5
16
  ## [0.2.1] - 2016-08-11
6
17
  ### Fixed
7
18
  - Fix issue when accessing ConvertFromResponse#to and error was raised
data/README.md CHANGED
@@ -30,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
30
30
 
31
31
  ## Contributing
32
32
 
33
- Bug reports and pull requests are welcome on [GitHub](https://github.com/imacchiato/xe_client-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
33
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/bloom-solutions/xe_client-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
34
 
35
35
 
36
36
  ## License
@@ -1,24 +1,35 @@
1
1
  require "xe_client/version"
2
+ require "api_client_base"
2
3
  require "active_model"
4
+ require "dry-validation"
3
5
  require "virtus"
4
6
  require "httparty"
5
7
  require "active_support/core_ext/hash/indifferent_access"
8
+ require "active_support/core_ext/date_time"
9
+ require "active_support/core_ext/string/conversions"
6
10
  require "xe_client/indifferent_hash"
7
11
  require "xe_client/models/quote"
8
12
  require "xe_client/client"
9
13
  require "xe_client/requests/base_request"
10
14
  require "xe_client/requests/convert_from_request"
15
+ require "xe_client/requests/historic_rate_period_request"
11
16
  require "xe_client/responses/base_response"
12
17
  require "xe_client/responses/convert_from_response"
18
+ require "xe_client/responses/historic_rate_period_response"
19
+ require "xe_client/schemas/convert_from_request_schema"
13
20
  require "xe_client/errors/error"
14
21
  require "xe_client/errors/authentication_error"
15
22
 
16
23
  module XEClient
17
24
 
18
- def self.new(opts)
19
- client = Client.new(opts)
20
- raise ArgumentError, client.errors.full_messages if client.invalid?
21
- client
25
+ include APIClientBase::Base.module
26
+
27
+ DEFAULT_HOST = "https://xecdapi.xe.com"
28
+
29
+ with_configuration do
30
+ has :host, classes: String, default: DEFAULT_HOST
31
+ has :account_id, classes: String
32
+ has :api_key, classes: String
22
33
  end
23
34
 
24
35
  end
@@ -1,30 +1,18 @@
1
1
  module XEClient
2
2
  class Client
3
3
 
4
- DEFAULT_URL = "https://xecdapi.xe.com"
5
-
6
- include Virtus.model
4
+ include APIClientBase::Client.module(default_opts: :default_opts)
5
+ attribute :host, String
7
6
  attribute :account_id, String
8
7
  attribute :api_key, String
9
- attribute :url, String, default: DEFAULT_URL
10
-
11
- include ActiveModel::Validations
12
- validates :account_id, :api_key, presence: true
13
8
 
14
- def convert_from(base_currency, counter_currencies, amount)
15
- args = default_args.merge(
16
- base_currency: base_currency,
17
- counter_currencies: counter_currencies,
18
- amount: amount,
19
- )
20
- raw_response = ConvertFromRequest.(args)
21
- ConvertFromResponse.(raw_response)
22
- end
9
+ api_action :convert_from
10
+ api_action :historic_rate_period
23
11
 
24
12
  private
25
13
 
26
- def default_args
27
- attributes.slice(:account_id, :api_key, :url)
14
+ def default_opts
15
+ { host: host, account_id: account_id, api_key: api_key }
28
16
  end
29
17
 
30
18
  end
@@ -4,6 +4,7 @@ module XEClient
4
4
  include Virtus.model
5
5
  attribute :quotecurrency, String
6
6
  attribute :mid, Float
7
+ attribute :timestamp, DateTime
7
8
 
8
9
  end
9
10
  end
@@ -1,16 +1,13 @@
1
1
  module XEClient
2
2
  class BaseRequest
3
3
 
4
- include Virtus.model
4
+ include APIClientBase::Request.module
5
+ attribute :host, String
5
6
  attribute :account_id, String
6
7
  attribute :api_key, String
7
- attribute :url, String
8
8
 
9
- include ActiveModel::Validations
10
- validates :account_id, :api_key, :url, presence: true
11
-
12
- def self.call(opts)
13
- self.new(opts).call
9
+ def typhoeus_options
10
+ { userpwd: [account_id, api_key].join(":") }
14
11
  end
15
12
 
16
13
  end
@@ -1,37 +1,20 @@
1
1
  module XEClient
2
2
  class ConvertFromRequest < BaseRequest
3
3
 
4
- DEFAULT_PATH = "/v1/convert_from.json"
5
- attribute :base_currency, String
6
- attribute :counter_currencies, Array[String]
4
+ attribute :from, String
5
+ attribute :to, Array[String]
7
6
  attribute :amount, Float
8
- attribute :endpoint, String, lazy: true, default: :default_endpoint
9
7
 
10
- validates(
11
- :base_currency,
12
- :counter_currencies,
13
- :amount,
14
- presence: true,
15
- )
16
-
17
- def call
18
- HTTParty.get(
19
- endpoint,
20
- query: {
21
- from: base_currency,
22
- to: counter_currencies.join(","),
23
- amount: amount,
24
- },
25
- basic_auth: { username: account_id, password: api_key },
26
- )
8
+ def path
9
+ "/v1/convert_from.json"
27
10
  end
28
11
 
29
- private
30
-
31
- def default_endpoint
32
- uri = URI.parse(url)
33
- uri.path = DEFAULT_PATH
34
- uri.to_s
12
+ def params
13
+ {
14
+ from: from,
15
+ to: to.join(","),
16
+ amount: amount,
17
+ }
35
18
  end
36
19
 
37
20
  end
@@ -0,0 +1,29 @@
1
+ module XEClient
2
+ class HistoricRatePeriodRequest < BaseRequest
3
+
4
+ attribute :from, String
5
+ attribute :to, Array[String]
6
+ attribute :start_timestamp, DateTime
7
+ attribute :end_timestamp, DateTime
8
+ attribute :interval, String
9
+ attribute :per_page, Integer
10
+ attribute :page, Integer
11
+
12
+ def path
13
+ "/v1/historic_rate/period.json"
14
+ end
15
+
16
+ def params
17
+ {
18
+ from: from,
19
+ to: to.join(","),
20
+ start_timestamp: start_timestamp,
21
+ end_timestamp: end_timestamp,
22
+ interval: interval,
23
+ per_page: per_page,
24
+ page: page,
25
+ }
26
+ end
27
+
28
+ end
29
+ end
@@ -1,7 +1,7 @@
1
1
  module XEClient
2
2
  class BaseResponse
3
3
 
4
- include Virtus.model
4
+ include APIClientBase::Response.module
5
5
  attribute :raw_response
6
6
  attribute(:response_body, IndifferentHash, {
7
7
  lazy: true,
@@ -11,12 +11,6 @@ module XEClient
11
11
  attribute :message, String, lazy: true, default: :default_message
12
12
  attribute :error, Object, lazy: true, default: :default_error
13
13
 
14
- def self.call(raw_response)
15
- response = self.new(raw_response: raw_response)
16
- raise response.error if response.error.present?
17
- response
18
- end
19
-
20
14
  private
21
15
 
22
16
  def default_code
@@ -35,5 +29,9 @@ module XEClient
35
29
  JSON.parse(raw_response.body)
36
30
  end
37
31
 
32
+ def default_success
33
+ error.blank?
34
+ end
35
+
38
36
  end
39
37
  end
@@ -0,0 +1,22 @@
1
+ module XEClient
2
+ class HistoricRatePeriodResponse < BaseResponse
3
+
4
+ attribute :from, String, lazy: true, default: :default_from
5
+ attribute :to, Array, lazy: true, default: :default_to
6
+
7
+ private
8
+
9
+ def default_from
10
+ response_body[:from]
11
+ end
12
+
13
+ def default_to
14
+ response_body[:to].each_with_object([]) do |(currency, quote_args), arr|
15
+ quote_args.each do |quote_arg|
16
+ arr << Quote.new(quote_arg.merge(quotecurrency: currency))
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module MyGem
2
+ ConvertFromRequestSchema = Dry::Validation.Schema do
3
+ required(:account_id).filled(:str?)
4
+ required(:api_key).filled(:str?)
5
+ required(:host).filled(:str?)
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module XEClient
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["ramon.tayag@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Ruby wrapper for XE's REST API}
13
- spec.homepage = "https://github.com/imacchiato/xe_client-ruby"
13
+ spec.homepage = "https://github.com/bloom-solutions/xe_client-ruby"
14
14
  spec.license = "MIT"
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -30,8 +30,11 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "activemodel", ">= 3.0"
31
31
  spec.add_dependency "virtus", "~> 1.0"
32
32
  spec.add_dependency "httparty"
33
+ spec.add_dependency "api_client_base", "~> 1.9"
34
+ spec.add_dependency "dry-validation", "< 1.0"
35
+ spec.add_dependency "typhoeus", "~> 1.0"
33
36
 
34
- spec.add_development_dependency "bundler", "~> 1.12"
37
+ spec.add_development_dependency "bundler", "~> 2.0"
35
38
  spec.add_development_dependency "rake", "~> 10.0"
36
39
  spec.add_development_dependency "rspec", "~> 3.0"
37
40
  spec.add_development_dependency "shoulda-matchers", "~> 3.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xe_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,20 +66,62 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: api_client_base
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dry-validation
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "<"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: typhoeus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: bundler
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - "~>"
74
116
  - !ruby/object:Gem::Version
75
- version: '1.12'
117
+ version: '2.0'
76
118
  type: :development
77
119
  prerelease: false
78
120
  version_requirements: !ruby/object:Gem::Requirement
79
121
  requirements:
80
122
  - - "~>"
81
123
  - !ruby/object:Gem::Version
82
- version: '1.12'
124
+ version: '2.0'
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: rake
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +192,7 @@ dependencies:
150
192
  - - "~>"
151
193
  - !ruby/object:Gem::Version
152
194
  version: '2.0'
153
- description:
195
+ description:
154
196
  email:
155
197
  - ramon.tayag@gmail.com
156
198
  executables: []
@@ -177,16 +219,19 @@ files:
177
219
  - lib/xe_client/models/quote.rb
178
220
  - lib/xe_client/requests/base_request.rb
179
221
  - lib/xe_client/requests/convert_from_request.rb
222
+ - lib/xe_client/requests/historic_rate_period_request.rb
180
223
  - lib/xe_client/responses/base_response.rb
181
224
  - lib/xe_client/responses/convert_from_response.rb
225
+ - lib/xe_client/responses/historic_rate_period_response.rb
226
+ - lib/xe_client/schemas/convert_from_request_schema.rb
182
227
  - lib/xe_client/version.rb
183
228
  - xe_client.gemspec
184
- homepage: https://github.com/imacchiato/xe_client-ruby
229
+ homepage: https://github.com/bloom-solutions/xe_client-ruby
185
230
  licenses:
186
231
  - MIT
187
232
  metadata:
188
233
  allowed_push_host: https://rubygems.org
189
- post_install_message:
234
+ post_install_message:
190
235
  rdoc_options: []
191
236
  require_paths:
192
237
  - lib
@@ -201,9 +246,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
246
  - !ruby/object:Gem::Version
202
247
  version: '0'
203
248
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.5.1
206
- signing_key:
249
+ rubygems_version: 3.0.8
250
+ signing_key:
207
251
  specification_version: 4
208
252
  summary: Ruby wrapper for XE's REST API
209
253
  test_files: []