ecb_exchange_rates_api 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cb5c9800e1d65a7b7d83ec1d75ef044ee75a236ef44ac79a2234deeca7f8f67
4
- data.tar.gz: 29e3c2959768e8fed2a5d8c0e54cb8444b59c0d9f5392d70bc93c3b2114f5787
3
+ metadata.gz: cd746f263ae1db257c0ea6ef795be4461128902969eede9dbb3a700a662e6770
4
+ data.tar.gz: 745564a9cde6f767458d347abb4cb4d4b6e2a9d51241c195c97a6288cb778808
5
5
  SHA512:
6
- metadata.gz: 3adbc5cc561c3c56f3ace910af8e1383726b568a1088c0d12f9993b57bf418bcfb6211a5b4416a17947c5bc9fd939d9ddd4123e87610b30c4ca436078c7f1032
7
- data.tar.gz: dc05cf1e7b8882efc8fd503686cd5f51a8eec450c28f01924a389679575196cc52e29b0df102fe6bddae77f47ec78deeed55ecdda8a3fab6d10f72e6d02ede91
6
+ metadata.gz: f7175a63d08cc539fc69313b5dc64b608b8091b4862112ea899f45d74f7e414be34a0b843bc7dbc690d05ed3bd4eaee9cb5c75fa7fa23eeb594c88c707dc4bb8
7
+ data.tar.gz: 5e140841b9363eede405c3e694b5ea933a2afad36a5b661f9f592512603b2665e234d355074468e668675c07acfffd4545318bcc1776723800a32659b2abf191
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.7
3
+ SuggestExtensions: false
4
+ NewCops: enable
3
5
 
4
6
  Metrics/BlockLength:
5
7
  Exclude:
data/Gemfile.lock CHANGED
@@ -1,29 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecb_exchange_rates_api (0.1.1)
5
- activesupport
6
- httparty
4
+ ecb_exchange_rates_api (0.1.3)
5
+ activesupport (~> 6.1.1)
6
+ httparty (~> 0.18.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.2.4.1)
11
+ activesupport (6.1.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
16
17
  addressable (2.7.0)
17
18
  public_suffix (>= 2.0.2, < 5.0)
18
- ast (2.4.0)
19
- coderay (1.1.2)
20
- concurrent-ruby (1.1.5)
21
- crack (0.4.3)
22
- safe_yaml (~> 1.0.0)
23
- diff-lcs (1.3)
24
- ffi (1.11.3)
19
+ ast (2.4.2)
20
+ coderay (1.1.3)
21
+ concurrent-ruby (1.1.8)
22
+ crack (0.4.5)
23
+ rexml
24
+ diff-lcs (1.4.4)
25
+ ffi (1.14.2)
25
26
  formatador (0.2.5)
26
- guard (2.16.1)
27
+ guard (2.16.2)
27
28
  formatador (>= 0.2.4)
28
29
  listen (>= 2.7, < 4.0)
29
30
  lumberjack (>= 1.0.12, < 2.0)
@@ -37,82 +38,86 @@ GEM
37
38
  guard (~> 2.1)
38
39
  guard-compat (~> 1.1)
39
40
  rspec (>= 2.99.0, < 4.0)
40
- hashdiff (1.0.0)
41
- httparty (0.17.3)
41
+ hashdiff (1.0.1)
42
+ httparty (0.18.1)
42
43
  mime-types (~> 3.0)
43
44
  multi_xml (>= 0.5.2)
44
- i18n (1.8.1)
45
+ i18n (1.8.8)
45
46
  concurrent-ruby (~> 1.0)
46
- jaro_winkler (1.5.4)
47
- listen (3.2.1)
47
+ listen (3.4.1)
48
48
  rb-fsevent (~> 0.10, >= 0.10.3)
49
49
  rb-inotify (~> 0.9, >= 0.9.10)
50
- lumberjack (1.1.1)
51
- method_source (0.9.2)
50
+ lumberjack (1.2.8)
51
+ method_source (1.0.0)
52
52
  mime-types (3.3.1)
53
53
  mime-types-data (~> 3.2015)
54
- mime-types-data (3.2019.1009)
55
- minitest (5.13.0)
54
+ mime-types-data (3.2020.1104)
55
+ minitest (5.14.3)
56
56
  multi_xml (0.6.0)
57
57
  nenv (0.3.0)
58
58
  notiffany (0.1.3)
59
59
  nenv (~> 0.1)
60
60
  shellany (~> 0.0)
61
- parallel (1.19.1)
62
- parser (2.7.0.2)
63
- ast (~> 2.4.0)
64
- pry (0.12.2)
65
- coderay (~> 1.1.0)
66
- method_source (~> 0.9.0)
67
- public_suffix (4.0.3)
61
+ parallel (1.20.1)
62
+ parser (3.0.0.0)
63
+ ast (~> 2.4.1)
64
+ pry (0.13.1)
65
+ coderay (~> 1.1)
66
+ method_source (~> 1.0)
67
+ public_suffix (4.0.6)
68
68
  rainbow (3.0.0)
69
- rb-fsevent (0.10.3)
69
+ rb-fsevent (0.10.4)
70
70
  rb-inotify (0.10.1)
71
71
  ffi (~> 1.0)
72
- rspec (3.9.0)
73
- rspec-core (~> 3.9.0)
74
- rspec-expectations (~> 3.9.0)
75
- rspec-mocks (~> 3.9.0)
76
- rspec-core (3.9.1)
77
- rspec-support (~> 3.9.1)
78
- rspec-expectations (3.9.0)
72
+ regexp_parser (2.0.3)
73
+ rexml (3.2.4)
74
+ rspec (3.10.0)
75
+ rspec-core (~> 3.10.0)
76
+ rspec-expectations (~> 3.10.0)
77
+ rspec-mocks (~> 3.10.0)
78
+ rspec-core (3.10.1)
79
+ rspec-support (~> 3.10.0)
80
+ rspec-expectations (3.10.1)
79
81
  diff-lcs (>= 1.2.0, < 2.0)
80
- rspec-support (~> 3.9.0)
81
- rspec-mocks (3.9.1)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-mocks (3.10.2)
82
84
  diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.9.0)
84
- rspec-support (3.9.2)
85
- rubocop (0.79.0)
86
- jaro_winkler (~> 1.5.1)
85
+ rspec-support (~> 3.10.0)
86
+ rspec-support (3.10.2)
87
+ rubocop (1.9.1)
87
88
  parallel (~> 1.10)
88
- parser (>= 2.7.0.1)
89
+ parser (>= 3.0.0.0)
89
90
  rainbow (>= 2.2.2, < 4.0)
91
+ regexp_parser (>= 1.8, < 3.0)
92
+ rexml
93
+ rubocop-ast (>= 1.2.0, < 2.0)
90
94
  ruby-progressbar (~> 1.7)
91
- unicode-display_width (>= 1.4.0, < 1.7)
92
- ruby-progressbar (1.10.1)
93
- safe_yaml (1.0.5)
95
+ unicode-display_width (>= 1.4.0, < 3.0)
96
+ rubocop-ast (1.4.1)
97
+ parser (>= 2.7.1.5)
98
+ ruby-progressbar (1.11.0)
94
99
  shellany (0.0.1)
95
- thor (1.0.1)
96
- thread_safe (0.3.6)
97
- tzinfo (1.2.6)
98
- thread_safe (~> 0.1)
99
- unicode-display_width (1.6.0)
100
- vcr (5.0.0)
101
- webmock (3.7.6)
100
+ thor (1.1.0)
101
+ tzinfo (2.0.4)
102
+ concurrent-ruby (~> 1.0)
103
+ unicode-display_width (2.0.0)
104
+ vcr (6.0.0)
105
+ webmock (3.11.2)
102
106
  addressable (>= 2.3.6)
103
107
  crack (>= 0.3.2)
104
108
  hashdiff (>= 0.4.0, < 2.0.0)
109
+ zeitwerk (2.4.2)
105
110
 
106
111
  PLATFORMS
107
112
  ruby
108
113
 
109
114
  DEPENDENCIES
110
115
  ecb_exchange_rates_api!
111
- guard-rspec
112
- rspec
113
- rubocop
114
- vcr
115
- webmock
116
+ guard-rspec (~> 4.7.3)
117
+ rspec (>= 2.99.0)
118
+ rubocop (~> 1.9.1)
119
+ vcr (~> 6.0.0)
120
+ webmock (~> 3.11.2)
116
121
 
117
122
  BUNDLED WITH
118
- 2.0.2
123
+ 2.1.4
data/Guardfile CHANGED
@@ -17,7 +17,7 @@
17
17
  #
18
18
  # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
19
 
20
- # Note: The cmd option is now required due to the increasing number of ways
20
+ # NOTE: The cmd option is now required due to the increasing number of ways
21
21
  # rspec may be run, below are examples of the most common uses.
22
22
  # * bundler: 'bundle exec rspec'
23
23
  # * bundler binstubs: 'bin/rspec'
data/README.md CHANGED
@@ -29,8 +29,8 @@ Since the CurrencyExchangeAPI does not require API keys or authentication in ord
29
29
  Fetch the latest exchange rates from the European Central Bank:
30
30
 
31
31
  ```ruby
32
- query = ECBExchangeRatesApi::Client.new
33
- query.fetch
32
+ client = ECBExchangeRatesApi::Client.new
33
+ client.fetch
34
34
  ```
35
35
 
36
36
  ### Historical data:
@@ -38,13 +38,13 @@ query.fetch
38
38
  Get historical rates for any day since 1999:
39
39
 
40
40
  ```ruby
41
- query.at("2010-09-21").fetch
41
+ client.at("2010-09-21").fetch
42
42
  ```
43
43
 
44
44
  or specify some date range:
45
45
 
46
46
  ```ruby
47
- query.from("2010-09-21").to("2010-10-21").fetch
47
+ client.from("2010-09-21").to("2010-10-21").fetch
48
48
  ```
49
49
 
50
50
  ### Set the base currency:
@@ -52,16 +52,31 @@ query.from("2010-09-21").to("2010-10-21").fetch
52
52
  By default, the base currency is set to Euro (EUR), but it can be changed:
53
53
 
54
54
  ```ruby
55
- query.with_base("USD").fetch
55
+ client.with_base("USD").fetch
56
56
  ```
57
57
 
58
58
  currency code should be passed as an ISO 4217 code.
59
59
 
60
60
  ### Fetch specific rates:
61
- If you do not want all current rates, it's possible to specify only the currencies you want using `for_rate(symbol)` or `for_rates(array_of_symbols)`. The following code fetches only the exchange rate between GBP and EUR:
61
+ If you do not want all current rates, it's possible to specify only the currencies you want using with `for_rate(symbol)` or `for_rates(array_of_symbols)`. The following code fetches only the exchange rate between GBP and EUR:
62
62
 
63
63
  ```ruby
64
- query.with_base("GBP").for_rate("EUR").fetch
64
+ client.with_base("GBP").for_rate("EUR").fetch
65
+ ```
66
+
67
+ ### Convert
68
+
69
+ It is useful not just to check the exchange rates but also to calculate the amount of money for them. This is the case where the `convert` method comes into play. You can specify options with the method arguments `convert(amount, base, symbols, specific_data)` or use the preconfigured client as follow:
70
+
71
+ ```ruby
72
+ client.convert(100, "USD", %w(EUR SEK), "2018-02-01")
73
+ #or
74
+ base_client = ECBExchangeRatesApi::Client.new do |c|
75
+ c.with_base "USD"
76
+ c.for_rates %w(EUR SEK)
77
+ c.at "2018-02-01"
78
+ end
79
+ base_client.convert(100)
65
80
  ```
66
81
 
67
82
  Please refer to the [API website](https://exchangeratesapi.io/) for further information and full API docs.
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  DESCRIPTION
16
16
  spec.homepage = "https://github.com/overchind/ECBExchangeRatesApi"
17
17
  spec.license = "MIT"
18
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.1")
19
19
 
20
20
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
21
 
@@ -31,12 +31,12 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_dependency "activesupport"
35
- spec.add_dependency "httparty"
34
+ spec.add_dependency "activesupport", "~> 6.1.1"
35
+ spec.add_dependency "httparty", "~> 0.18.1"
36
36
 
37
- spec.add_development_dependency "guard-rspec"
38
- spec.add_development_dependency "rspec"
39
- spec.add_development_dependency "rubocop"
40
- spec.add_development_dependency "vcr"
41
- spec.add_development_dependency "webmock"
37
+ spec.add_development_dependency "guard-rspec", "~> 4.7.3"
38
+ spec.add_development_dependency "rspec", "~> 3.10.1"
39
+ spec.add_development_dependency "rubocop", "~> 1.9.1"
40
+ spec.add_development_dependency "vcr", "~> 6.0.0"
41
+ spec.add_development_dependency "webmock", "~> 3.11.2"
42
42
  end
@@ -25,7 +25,7 @@ module ECBExchangeRatesApi
25
25
 
26
26
  def fetch
27
27
  response = self.class.get(path, query: options.to_params)
28
- ECBExchangeRatesApi::Result.new(response.parsed_response, status: response.code)
28
+ create_result(response.parsed_response, response.code)
29
29
  end
30
30
 
31
31
  def from(date)
@@ -58,6 +58,17 @@ module ECBExchangeRatesApi
58
58
  self
59
59
  end
60
60
 
61
+ def convert(amount, base_code = nil, codes = nil, date = nil)
62
+ response = self.class.new do |client|
63
+ client.with_base presented_base(base_code)
64
+ client.for_rates presented_symbols(codes)
65
+ client.at presented_date(date)
66
+ end.fetch
67
+
68
+ response.rates.transform_values! { |v| v * amount }
69
+ response
70
+ end
71
+
61
72
  def currency_is_supported?(code)
62
73
  supported_currency?(validated_currency_code(code))
63
74
  end
@@ -77,5 +88,21 @@ module ECBExchangeRatesApi
77
88
 
78
89
  "/latest"
79
90
  end
91
+
92
+ def create_result(response, status)
93
+ ECBExchangeRatesApi::Result.new(response, status: status)
94
+ end
95
+
96
+ def presented_base(base_from_params)
97
+ base_from_params || base || default_base
98
+ end
99
+
100
+ def presented_symbols(codes)
101
+ (codes && Array.wrap(codes)) || symbols || []
102
+ end
103
+
104
+ def presented_date(date)
105
+ date || specific_date || current_date
106
+ end
80
107
  end
81
108
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module ECBExchangeRatesApi
4
4
  module Constants
5
+ DEFAULT_BASE = "EUR"
5
6
  CURRENCIES = %w[USD GBP EUR JPY BGN CZK DKK HUF PLN RON
6
7
  SEK CHF ISK NOK HRK RUB TRY AUD BRL CAD
7
8
  CNY HKD IDR ILS INR KRW MXN MYR NZD PHP
@@ -8,6 +8,7 @@ module ECBExchangeRatesApi
8
8
  include SharedMethods
9
9
 
10
10
  attr_reader :start_at, :end_at, :specific_date, :base, :symbols
11
+
11
12
  date_attr_writer :start_at, :end_at, :specific_date
12
13
  code_attr_writer :base
13
14
 
@@ -31,7 +32,7 @@ module ECBExchangeRatesApi
31
32
 
32
33
  def options_params
33
34
  instance_variables.each_with_object({}) do |var, hash|
34
- key = var.to_s[1..-1].to_sym
35
+ key = var.to_s[1..].to_sym
35
36
  variable = instance_variable_get(var)
36
37
  value = key == :symbols ? variable&.join(",") : variable
37
38
  hash[key] = value
@@ -15,6 +15,14 @@ module ECBExchangeRatesApi
15
15
 
16
16
  private
17
17
 
18
+ def default_base
19
+ ECBExchangeRatesApi::Constants::DEFAULT_BASE
20
+ end
21
+
22
+ def current_date
23
+ represent_date(Time.now)
24
+ end
25
+
18
26
  def represent_date(date)
19
27
  return date.strftime("%Y-%m-%d") if time_or_date_instance?(date)
20
28
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ECBExchangeRatesApi
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,113 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecb_exchange_rates_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Ovcharov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 6.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 6.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.18.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.18.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: guard-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 4.7.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 4.7.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.10.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.10.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.9.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.9.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: vcr
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 6.0.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 6.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 3.11.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 3.11.2
111
111
  description: |2
112
112
  This is an unofficial wrapper for the awesome, free ExchangeRatesAPI,
113
113
  which provides exchange rate lookups courtesy of the Central European Bank."
@@ -153,15 +153,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
- version: 2.3.0
156
+ version: 2.7.1
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
159
  - - ">="
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.7.6
163
+ rubygems_version: 3.1.2
165
164
  signing_key:
166
165
  specification_version: 4
167
166
  summary: Client library for ExchangeRates API