oxr 0.1.0.1 → 0.6.1
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 +5 -5
- data/.gitlab-ci.yml +27 -0
- data/.rubocop.yml +8 -0
- data/.tool-versions +1 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +17 -0
- data/README.md +139 -16
- data/Rakefile +6 -4
- data/bin/console +3 -3
- data/lib/oxr.rb +164 -30
- data/lib/oxr/configuration.rb +92 -0
- data/lib/oxr/version.rb +4 -2
- data/oxr.gemspec +15 -15
- metadata +38 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b503f70d7b69e03db759d6bd5b2a629f78da39944de835f75db03f1156b4ef73
|
4
|
+
data.tar.gz: f7179b689f98c5a0237ce6639879f4980795ec0b8bdfc49ca65af5c430b4a9d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b080b6d4312340ab657e9e22acb0dd1338a30e966fe250f4a16c77161015cbbea0ed3515a819460d02c246d9a5c027bd2deaedf7053817c102b5b64504322f0
|
7
|
+
data.tar.gz: 4e3e712532f41e8b8c6b6674e8dde2ca20120e8997e5779a78b511002d5e50ad7218e6be21c73770285b2bc4b966adbe01db1e0bee16a55aae96cb37017a0a4d
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
before_script:
|
2
|
+
- gem install bundler --no-document -v '~> 2.2.15'
|
3
|
+
- bundle install --jobs="$(nproc)" --retry=3
|
4
|
+
|
5
|
+
build:rubocop:
|
6
|
+
stage: build
|
7
|
+
image: "ruby:3.0"
|
8
|
+
script:
|
9
|
+
- bundle exec rubocop
|
10
|
+
|
11
|
+
test:ruby-2.6:
|
12
|
+
stage: test
|
13
|
+
image: "ruby:2.6"
|
14
|
+
script:
|
15
|
+
- bundle exec rake test
|
16
|
+
|
17
|
+
test:ruby-2.7:
|
18
|
+
stage: test
|
19
|
+
image: "ruby:2.7"
|
20
|
+
script:
|
21
|
+
- bundle exec rake test
|
22
|
+
|
23
|
+
test:ruby-3.0:
|
24
|
+
stage: test
|
25
|
+
image: "ruby:3.0"
|
26
|
+
script:
|
27
|
+
- bundle exec rake test
|
data/.rubocop.yml
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.0.1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
## OXR 0.6.1 (April 16, 2021) ##
|
2
|
+
|
3
|
+
* Accept endpoints as Pathnames or URIs as well as Strings
|
4
|
+
* Eliminated redundant URI processing for default endpoints
|
5
|
+
|
6
|
+
## OXR 0.6.0 (April 15, 2021) ##
|
7
|
+
|
8
|
+
* Now works on Ruby 3.0
|
9
|
+
* Gem now requires Ruby >= 2.5, only testing >= 2.6
|
10
|
+
* Addressed Rubocop warnings
|
11
|
+
* Code comments
|
12
|
+
|
13
|
+
## OXR 0.5.0 (December 16, 2017) ##
|
14
|
+
|
15
|
+
* Added `base` option for performing queries with custom base currencies.
|
16
|
+
|
17
|
+
*Techbrunch*
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# [](https://badge.fury.io/rb/oxr) [](https://travis-ci.org/jparker/oxr)
|
2
|
+
|
1
3
|
# OXR
|
2
4
|
|
3
|
-
This gem provides a basic interface to the
|
5
|
+
This gem provides a basic interface to the
|
6
|
+
[Open Exchange Rates](https://openexchangerates.org) API. At present, only the
|
7
|
+
API calls available to free plans have been implemented.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -20,51 +24,170 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
If you have not done so already, sign up for account on
|
27
|
+
If you have not done so already, sign up for account on
|
28
|
+
[Open Exchange Rates](https://openexchangerates.org). Once you have an account,
|
29
|
+
go to Your Dashboard and locate your App ID.
|
30
|
+
|
31
|
+
Configure OXR with your App ID by calling `OXR.configure`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
OXR.configure do |config|
|
35
|
+
config.app_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
36
|
+
# config.base = 'USD'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
(If you are using OXR within a Rails application, you will probably want to put
|
41
|
+
this in an initializer.)
|
42
|
+
|
43
|
+
You can get current exchange rates using `OXR.get_rate`:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
OXR.get_rate 'GBP' # => 0.703087
|
47
|
+
OXR.get_rate 'JPY' # => 111.7062
|
48
|
+
```
|
49
|
+
|
50
|
+
You can also use the `OXR.[]` shortcut method.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
OXR['GBP'] # => 0.703087
|
54
|
+
```
|
55
|
+
|
56
|
+
`OXR.get_rate` accepts an optional keyword argument to retrieve historical
|
57
|
+
exchange rates for given dates. The provided date should be an object which
|
58
|
+
responds to `#strftime`.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
OXR.get_rate 'GBP', on: Date.new(2015, 6, 14) # => 0.642607
|
62
|
+
```
|
63
|
+
|
64
|
+
You perform more complex operations by using the lower-level API calls. These
|
65
|
+
methods return the raw JSON responses returned by Open Exchange Rates (parsed
|
66
|
+
using the [json](https://rubygems.org/gems/json) gem).
|
24
67
|
|
25
|
-
|
68
|
+
Get the latest exchange rates with `OXR.latest`.
|
26
69
|
|
27
70
|
```ruby
|
28
|
-
|
71
|
+
OXR.latest
|
29
72
|
```
|
30
73
|
|
31
|
-
|
74
|
+
This will return a JSON object with a structure similar to the following:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
{
|
78
|
+
"disclaimer"=>"Usage subject to terms: https://openexchangerates.org/terms",
|
79
|
+
"license"=>"https://openexchangerates.org/license",
|
80
|
+
"timestamp"=>1512842416,
|
81
|
+
"base"=>"USD",
|
82
|
+
"rates"=>
|
83
|
+
{
|
84
|
+
"AED"=>3.673097,
|
85
|
+
"AFN"=>68.693,
|
86
|
+
"ALL"=>113.595865,
|
87
|
+
# ...
|
88
|
+
"ZAR"=>13.65526,
|
89
|
+
"ZMW"=>10.243477,
|
90
|
+
"ZWL"=>322.355011
|
91
|
+
}
|
92
|
+
}
|
93
|
+
```
|
32
94
|
|
33
|
-
Get
|
95
|
+
Get historical exchange rates for specific dates with `OXR.historical`. This
|
96
|
+
method requires you to provide the date you wish to lookup. The date argument
|
97
|
+
should respond to `#strftime`.
|
34
98
|
|
35
99
|
```ruby
|
36
|
-
|
100
|
+
OXR.historical on: Date.new(2016, 3, 24)
|
37
101
|
```
|
38
102
|
|
39
|
-
|
103
|
+
This will return a JSON object with a structure similar to that returned by `OXR.latest`.
|
104
|
+
|
105
|
+
Get a list of available currencies with `OXR.currencies`.
|
40
106
|
|
41
107
|
```ruby
|
42
|
-
|
108
|
+
OXR.currencies
|
43
109
|
```
|
44
110
|
|
45
|
-
Get
|
111
|
+
Get information about your account including your usage for the current period
|
112
|
+
with `OXR.usage`.
|
46
113
|
|
47
114
|
```ruby
|
48
|
-
|
115
|
+
OXR.usage
|
49
116
|
```
|
50
117
|
|
51
|
-
|
118
|
+
## Testing
|
119
|
+
|
120
|
+
Normally, any API call will send a request to Open Exchange Rates. Since your
|
121
|
+
plan allows a limited number of requests per month, you probably want to avoid
|
122
|
+
this when running in a test environment. You can stub the responses of specific
|
123
|
+
API calls by configuring the endpoint for specific calls to use a local file
|
124
|
+
instead of an HTTP request. Just provide a JSON file that reflects the payload
|
125
|
+
of an actual API call. You may provide this as a Pathname or a URI object, but
|
126
|
+
a plain old String will work as well. (You will find usable JSON files in
|
127
|
+
test/fixtures included with this gem.)
|
128
|
+
|
129
|
+
When you're done, you can call `OXR.reset_sources` to restore the default behavior.
|
130
|
+
|
131
|
+
Below is an example of configuring OXR within a test.
|
52
132
|
|
53
133
|
```ruby
|
134
|
+
class SomeTest < Minitest::Test
|
135
|
+
def setup
|
136
|
+
OXR.configure do |config|
|
137
|
+
config.latest = 'test/fixtures/sample.json'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def teardown
|
142
|
+
OXR.reset_sources
|
143
|
+
end
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
(You might consider doing this in your development environment as well.)
|
148
|
+
|
149
|
+
## Upgrading
|
150
|
+
|
151
|
+
The interface has changed between the 0.2.0 and 0.3.0 tags. It is no longer
|
152
|
+
necessary to instantiate an OXR object. The API calls are available as class
|
153
|
+
methods directly on the OXR module.
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
# Before
|
157
|
+
oxr = OXR.new 'YOUR_APP_ID'
|
158
|
+
oxr['JPY']
|
54
159
|
oxr.usage
|
160
|
+
|
161
|
+
# Now
|
162
|
+
OXR.configure do |config|
|
163
|
+
config.app_id = 'YOUR_APP_ID'
|
164
|
+
end
|
165
|
+
OXR['JPY']
|
166
|
+
OXR.usage
|
55
167
|
```
|
56
168
|
|
169
|
+
(You can still call `OXR.new`, but this behavior will generate a deprecation
|
170
|
+
warning.)
|
171
|
+
|
57
172
|
## Development
|
58
173
|
|
59
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
174
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
175
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
176
|
+
prompt that will allow you to experiment.
|
60
177
|
|
61
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
178
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
179
|
+
release a new version, update the version number in `version.rb`, and then run
|
180
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
181
|
+
git commits and tags, and push the `.gem` file to
|
182
|
+
[rubygems.org](https://rubygems.org).
|
62
183
|
|
63
184
|
## Contributing
|
64
185
|
|
65
|
-
Bug reports and pull requests are welcome on GitHub at
|
186
|
+
Bug reports and pull requests are welcome on GitHub at
|
187
|
+
https://github.com/jparker/oxr.
|
66
188
|
|
67
189
|
|
68
190
|
## License
|
69
191
|
|
70
|
-
The gem is available as open source under the terms of the [MIT
|
192
|
+
The gem is available as open source under the terms of the [MIT
|
193
|
+
License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
7
9
|
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
data/bin/console
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'oxr'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
require
|
10
|
+
require 'pry'
|
11
11
|
Pry.start
|
12
12
|
|
13
13
|
# require "irb"
|
data/lib/oxr.rb
CHANGED
@@ -1,44 +1,178 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oxr/version'
|
4
|
+
require 'oxr/configuration'
|
2
5
|
|
3
6
|
require 'date'
|
4
7
|
require 'json'
|
5
8
|
require 'open-uri'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
##
|
11
|
+
# All use of OXR takes place through module methods.
|
12
|
+
#
|
13
|
+
# Before you can make API calls, you must configure OXR with your Open Exchange
|
14
|
+
# Rates App ID. Visit https://openexchangerates.org to sign up and generate one.
|
15
|
+
#
|
16
|
+
# OXR.configure do |config|
|
17
|
+
# config.app_id = 'XXXX'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# Optionally you may also specify the base currency for the conversion rates.
|
21
|
+
# The default base currency is USD.
|
22
|
+
#
|
23
|
+
# OXR.configure do |config|
|
24
|
+
# config.app_id = 'XXXX'
|
25
|
+
# config.base = 'JPY'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# If you will be using OXR in a test environment, you may want to test the
|
29
|
+
# substitute local files for the API endpoints to provide deterministic results
|
30
|
+
# and avoid running over your Open Exchange Rates API request quota.
|
31
|
+
#
|
32
|
+
# class ThisIsATest < Minitest::Test
|
33
|
+
# def setup
|
34
|
+
# OXR.configure do |config|
|
35
|
+
# config.latest = 'test/fixtures/sample.json'
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# def teardown
|
40
|
+
# OXR.reset_sources
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# To quickly get an exchange rate from the base currency to a given currency,
|
45
|
+
# use `OXR.get_rate`.
|
46
|
+
#
|
47
|
+
# OXR.get_rate 'GBP' # => 0.703087
|
48
|
+
# OXR.get_rate 'JPY' # => 111.7062
|
49
|
+
#
|
50
|
+
# This method is aliased as `OXR.[]`.
|
51
|
+
#
|
52
|
+
# OXR['GBP'] # => 0.703087
|
53
|
+
#
|
54
|
+
# Pass the `:on` keyword argument to get an historical exchange rate on a given
|
55
|
+
# date.
|
56
|
+
#
|
57
|
+
# OXR.get_rate 'GBP', on: Date.new(2015, 6, 14) # => 0.642607
|
58
|
+
#
|
59
|
+
module OXR
|
60
|
+
class Error < StandardError
|
12
61
|
end
|
13
62
|
|
14
|
-
|
63
|
+
##
|
64
|
+
# ApiError is raised when OXR encounters an error connecting to the Open
|
65
|
+
# Exchange Rates API server.
|
66
|
+
class ApiError < Error
|
67
|
+
def message
|
68
|
+
cause.message
|
69
|
+
end
|
15
70
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# Only allowed for paid plans
|
20
|
-
endpoint.query += "&symbols=#{Array(only).join ','}" if only
|
21
|
-
JSON.load open endpoint
|
22
|
-
end
|
71
|
+
def description
|
72
|
+
response['description']
|
73
|
+
end
|
23
74
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
endpoint.query = "app_id=#{app_id}"
|
28
|
-
# Only allowed for paid plans
|
29
|
-
endpoint.query += "&symbols=#{Array(only).join ','}" if only
|
30
|
-
JSON.load open endpoint
|
75
|
+
def response
|
76
|
+
@response ||= JSON.parse cause.io.read
|
77
|
+
end
|
31
78
|
end
|
32
79
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
80
|
+
class << self
|
81
|
+
##
|
82
|
+
# DEPRECATED: TO BE REMOVED IN 0.7.
|
83
|
+
#
|
84
|
+
# OXR should no longer be instantiated explicitly.
|
85
|
+
#
|
86
|
+
# Call OXR.configure to specify the application ID and use the module
|
87
|
+
# methods below to access the different API endpoints.
|
88
|
+
def new(app_id)
|
89
|
+
warn '[DEPRECATION] OXR.new is deprecated and will be removed from 0.7.' \
|
90
|
+
" Use OXR class methods instead (from #{caller(1..1).first})."
|
91
|
+
configure do |config|
|
92
|
+
config.app_id = app_id
|
93
|
+
end
|
94
|
+
self
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Get the latest exchange rate for currency identified by +code+.
|
99
|
+
#
|
100
|
+
# If the optional +on+ keyword is provided, it instead returns the
|
101
|
+
# historical exchange rate on the given date.
|
102
|
+
def get_rate(code, on: nil)
|
103
|
+
data = if on
|
104
|
+
historical on: on
|
105
|
+
else
|
106
|
+
latest
|
107
|
+
end
|
108
|
+
data['rates'][code.to_s]
|
109
|
+
end
|
110
|
+
|
111
|
+
alias [] get_rate
|
112
|
+
|
113
|
+
##
|
114
|
+
# Returns a Hash mapping currency codes to full currency names.
|
115
|
+
def currencies
|
116
|
+
call configuration.currencies
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Returns a Hash mapping currency codes to their historical exchange rate
|
121
|
+
# on the date given by the +on+ keyword argument.
|
122
|
+
#
|
123
|
+
# The exchange rate is relative to the configured base currency.
|
124
|
+
def historical(on:)
|
125
|
+
call configuration.historical on
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# Returns a Hash mapping currency codes to their latest exchange rate.
|
130
|
+
#
|
131
|
+
# The exchange rate is relative to the configured base currency.
|
132
|
+
def latest
|
133
|
+
call configuration.latest
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Returns a Hash containinng details about the Open Exchange Rates account
|
138
|
+
# and current usage statistics.
|
139
|
+
def usage
|
140
|
+
call configuration.usage
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Resets API endpoints to their defaults.
|
145
|
+
def reset_sources
|
146
|
+
configure(&:reset_sources)
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Returns the OXR configuration struct.
|
151
|
+
#
|
152
|
+
# If given a block, the configuration will be yielded to the block.
|
153
|
+
def configure
|
154
|
+
yield configuration if block_given?
|
155
|
+
configuration
|
156
|
+
end
|
157
|
+
|
158
|
+
##
|
159
|
+
# Returns the OXR configuration struct.
|
160
|
+
def configuration
|
161
|
+
@configuration ||= Configuration.new
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def call(endpoint)
|
167
|
+
# This method makes it possible for a user to provide an endpoint path as
|
168
|
+
# either a String, Pathname, or URI. We will massage it until we have
|
169
|
+
# something that responds to #read.
|
170
|
+
endpoint = URI.parse(endpoint.to_s) unless endpoint.respond_to?(:read)
|
171
|
+
endpoint = File.open(endpoint.path) unless endpoint.respond_to?(:read)
|
38
172
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
173
|
+
JSON.parse endpoint.read
|
174
|
+
rescue OpenURI::HTTPError => e
|
175
|
+
raise ApiError, e
|
176
|
+
end
|
43
177
|
end
|
44
178
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module OXR
|
6
|
+
##
|
7
|
+
# A container for OXR configuration options.
|
8
|
+
#
|
9
|
+
# Stores the API application ID and the base currency for which to request
|
10
|
+
# exchange rates.
|
11
|
+
#
|
12
|
+
# Also stores the URI endpoints for fetching currencies, the latest exchange
|
13
|
+
# ranges, historical exchange rates, and current account usage statistics.
|
14
|
+
#
|
15
|
+
# By default, endpoints are generated dynamically, allowing them to
|
16
|
+
# automatically adapte to changes to the app_id, but they may be set to a
|
17
|
+
# fixed path, including a local file path. This is useful during testing when
|
18
|
+
# you might want deterministic results and do not want to waste real API
|
19
|
+
# requests.
|
20
|
+
class Configuration
|
21
|
+
ENDPOINT = 'https://openexchangerates.org/api/'
|
22
|
+
LATEST = URI.join(ENDPOINT, 'latest.json').freeze
|
23
|
+
HISTORICAL = URI.join(ENDPOINT, 'historical/').freeze
|
24
|
+
USAGE = URI.join(ENDPOINT, 'usage.json').freeze
|
25
|
+
CURRENCIES = URI.join(ENDPOINT, 'currencies.json').freeze
|
26
|
+
|
27
|
+
##
|
28
|
+
# Get and set the application ID that will be sent to the API server.
|
29
|
+
attr_accessor :app_id
|
30
|
+
|
31
|
+
##
|
32
|
+
# Get and set the base currency to be used when fetching exchange rates.
|
33
|
+
attr_accessor :base
|
34
|
+
|
35
|
+
##
|
36
|
+
# Set respective API endpoints. Use these if you want to sidestep the API
|
37
|
+
# server, e.g., for testing. The endpoint may be provided as a URI,
|
38
|
+
# Pathname, or String.
|
39
|
+
#
|
40
|
+
# Setting an endpoint to +nil+ will restore the default value.
|
41
|
+
attr_writer :currencies, :historical, :latest, :usage
|
42
|
+
|
43
|
+
def initialize
|
44
|
+
reset_sources
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Returns the endpoint for listing known currencies.
|
49
|
+
def currencies
|
50
|
+
@currencies || append_query(CURRENCIES)
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Returns the endpoint for historical currency exchange rates on the given
|
55
|
+
# date.
|
56
|
+
#
|
57
|
+
# Expects +date+ to respond #strftime.
|
58
|
+
def historical(date)
|
59
|
+
@historical || append_query(URI.join(HISTORICAL, "#{date.strftime('%F')}.json"), base: base)
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Returns the endpoint for the latest currency exchange rates.
|
64
|
+
def latest
|
65
|
+
@latest || append_query(LATEST, base: base)
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Returns the endpoint for fetch current API usage statistics.
|
70
|
+
def usage
|
71
|
+
@usage || append_query(USAGE)
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Resets all API endpoints back to their default (dynamic generation).
|
76
|
+
def reset_sources
|
77
|
+
@currencies = nil
|
78
|
+
@historical = nil
|
79
|
+
@latest = nil
|
80
|
+
@usage = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def append_query(uri, base: nil)
|
86
|
+
uri.dup.tap do |u|
|
87
|
+
u.query = "app_id=#{app_id}"
|
88
|
+
u.query += "&base=#{base}" if base
|
89
|
+
end.to_s
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/oxr/version.rb
CHANGED
data/oxr.gemspec
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'oxr/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'oxr'
|
8
7
|
spec.version = OXR::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['John Parker']
|
9
|
+
spec.email = ['jparker@urgetopunt.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
11
|
+
spec.summary = 'Interface for Open Exchange Rates API.'
|
12
|
+
spec.description = 'A ruby interface to the Open Exchange Rates API.'
|
13
|
+
spec.homepage = 'https://github.com/jparker/oxr'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'exe'
|
19
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
21
20
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.5'
|
23
22
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
23
|
+
spec.add_development_dependency 'bundler', '>= 1.17'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
25
|
spec.add_development_dependency 'pry'
|
28
|
-
spec.add_development_dependency '
|
26
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
27
|
+
spec.add_development_dependency 'rubocop'
|
28
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
29
29
|
|
30
30
|
spec.add_dependency 'json'
|
31
31
|
end
|
metadata
CHANGED
@@ -1,59 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Parker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.17'
|
20
20
|
type: :development
|
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: '1.
|
26
|
+
version: '1.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.0'
|
34
34
|
type: :development
|
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: '
|
40
|
+
version: '5.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '13.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '13.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -70,16 +84,16 @@ dependencies:
|
|
70
84
|
name: webmock
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
89
|
+
version: '3.0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
96
|
+
version: '3.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: json
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +116,11 @@ extensions: []
|
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
118
|
- ".gitignore"
|
119
|
+
- ".gitlab-ci.yml"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".tool-versions"
|
105
122
|
- ".travis.yml"
|
123
|
+
- CHANGELOG.md
|
106
124
|
- Gemfile
|
107
125
|
- LICENSE.txt
|
108
126
|
- README.md
|
@@ -110,6 +128,7 @@ files:
|
|
110
128
|
- bin/console
|
111
129
|
- bin/setup
|
112
130
|
- lib/oxr.rb
|
131
|
+
- lib/oxr/configuration.rb
|
113
132
|
- lib/oxr/version.rb
|
114
133
|
- oxr.gemspec
|
115
134
|
homepage: https://github.com/jparker/oxr
|
@@ -124,15 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
143
|
requirements:
|
125
144
|
- - ">="
|
126
145
|
- !ruby/object:Gem::Version
|
127
|
-
version: '2.
|
146
|
+
version: '2.5'
|
128
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
148
|
requirements:
|
130
149
|
- - ">="
|
131
150
|
- !ruby/object:Gem::Version
|
132
151
|
version: '0'
|
133
152
|
requirements: []
|
134
|
-
|
135
|
-
rubygems_version: 2.5.2
|
153
|
+
rubygems_version: 3.2.15
|
136
154
|
signing_key:
|
137
155
|
specification_version: 4
|
138
156
|
summary: Interface for Open Exchange Rates API.
|