oxr 0.6.0 → 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 +4 -4
- data/.gitlab-ci.yml +4 -0
- data/.rubocop.yml +0 -3
- data/CHANGELOG.md +5 -0
- data/README.md +3 -2
- data/lib/oxr.rb +7 -3
- data/lib/oxr/configuration.rb +22 -16
- data/lib/oxr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
CHANGED
@@ -3,21 +3,25 @@ before_script:
|
|
3
3
|
- bundle install --jobs="$(nproc)" --retry=3
|
4
4
|
|
5
5
|
build:rubocop:
|
6
|
+
stage: build
|
6
7
|
image: "ruby:3.0"
|
7
8
|
script:
|
8
9
|
- bundle exec rubocop
|
9
10
|
|
10
11
|
test:ruby-2.6:
|
12
|
+
stage: test
|
11
13
|
image: "ruby:2.6"
|
12
14
|
script:
|
13
15
|
- bundle exec rake test
|
14
16
|
|
15
17
|
test:ruby-2.7:
|
18
|
+
stage: test
|
16
19
|
image: "ruby:2.7"
|
17
20
|
script:
|
18
21
|
- bundle exec rake test
|
19
22
|
|
20
23
|
test:ruby-3.0:
|
24
|
+
stage: test
|
21
25
|
image: "ruby:3.0"
|
22
26
|
script:
|
23
27
|
- bundle exec rake test
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -122,8 +122,9 @@ plan allows a limited number of requests per month, you probably want to avoid
|
|
122
122
|
this when running in a test environment. You can stub the responses of specific
|
123
123
|
API calls by configuring the endpoint for specific calls to use a local file
|
124
124
|
instead of an HTTP request. Just provide a JSON file that reflects the payload
|
125
|
-
of an actual API call.
|
126
|
-
|
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.)
|
127
128
|
|
128
129
|
When you're done, you can call `OXR.reset_sources` to restore the default behavior.
|
129
130
|
|
data/lib/oxr.rb
CHANGED
@@ -164,9 +164,13 @@ module OXR
|
|
164
164
|
private
|
165
165
|
|
166
166
|
def call(endpoint)
|
167
|
-
|
168
|
-
|
169
|
-
|
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)
|
172
|
+
|
173
|
+
JSON.parse endpoint.read
|
170
174
|
rescue OpenURI::HTTPError => e
|
171
175
|
raise ApiError, e
|
172
176
|
end
|
data/lib/oxr/configuration.rb
CHANGED
@@ -18,7 +18,11 @@ module OXR
|
|
18
18
|
# you might want deterministic results and do not want to waste real API
|
19
19
|
# requests.
|
20
20
|
class Configuration
|
21
|
-
ENDPOINT
|
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
|
22
26
|
|
23
27
|
##
|
24
28
|
# Get and set the application ID that will be sent to the API server.
|
@@ -30,7 +34,10 @@ module OXR
|
|
30
34
|
|
31
35
|
##
|
32
36
|
# Set respective API endpoints. Use these if you want to sidestep the API
|
33
|
-
# server, e.g., for testing.
|
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.
|
34
41
|
attr_writer :currencies, :historical, :latest, :usage
|
35
42
|
|
36
43
|
def initialize
|
@@ -40,9 +47,7 @@ module OXR
|
|
40
47
|
##
|
41
48
|
# Returns the endpoint for listing known currencies.
|
42
49
|
def currencies
|
43
|
-
@currencies ||
|
44
|
-
uri.query = "app_id=#{app_id}"
|
45
|
-
end.to_s
|
50
|
+
@currencies || append_query(CURRENCIES)
|
46
51
|
end
|
47
52
|
|
48
53
|
##
|
@@ -51,27 +56,19 @@ module OXR
|
|
51
56
|
#
|
52
57
|
# Expects +date+ to respond #strftime.
|
53
58
|
def historical(date)
|
54
|
-
@historical || URI.join(
|
55
|
-
uri.query = "app_id=#{app_id}"
|
56
|
-
uri.query += "&base=#{base}" if base
|
57
|
-
end.to_s
|
59
|
+
@historical || append_query(URI.join(HISTORICAL, "#{date.strftime('%F')}.json"), base: base)
|
58
60
|
end
|
59
61
|
|
60
62
|
##
|
61
63
|
# Returns the endpoint for the latest currency exchange rates.
|
62
64
|
def latest
|
63
|
-
@latest ||
|
64
|
-
uri.query = "app_id=#{app_id}"
|
65
|
-
uri.query += "&base=#{base}" if base
|
66
|
-
end.to_s
|
65
|
+
@latest || append_query(LATEST, base: base)
|
67
66
|
end
|
68
67
|
|
69
68
|
##
|
70
69
|
# Returns the endpoint for fetch current API usage statistics.
|
71
70
|
def usage
|
72
|
-
@usage ||
|
73
|
-
uri.query = "app_id=#{app_id}"
|
74
|
-
end.to_s
|
71
|
+
@usage || append_query(USAGE)
|
75
72
|
end
|
76
73
|
|
77
74
|
##
|
@@ -82,5 +79,14 @@ module OXR
|
|
82
79
|
@latest = nil
|
83
80
|
@usage = nil
|
84
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
|
85
91
|
end
|
86
92
|
end
|
data/lib/oxr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
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: 2021-04-
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|