nbppl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fixtures/vcr_cassettes/exchangerates_rates_a_EUR_2021-06-01.yml +45 -0
- data/fixtures/vcr_cassettes/exchangerates_rates_a_EUR_2021-06-05.yml +41 -0
- data/fixtures/vcr_cassettes/exchangerates_rates_a_EUR_2021-06-08.yml +43 -0
- data/fixtures/vcr_cassettes/exchangerates_rates_a_FOO_2021-06-01.yml +41 -0
- data/fixtures/vcr_cassettes/exchangerates_rates_a_USD_2021-06-06_2021-06-05_2021-06-04.yml +122 -0
- data/lib/nbppl.rb +57 -0
- data/lib/nbppl/version.rb +3 -0
- data/nbppl.gemspec +37 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 021daa349e280b6855747ce23ad5758493a308a265f0a13264def3ae5127f00f
|
4
|
+
data.tar.gz: 5c696eea0fc2def853e07dcd4b28b132de8674bc149bc7501d4738b0fb65cecc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7c95614bca886cb7a95df917a7303ced2cfa46234296a8f0f90fc57af2d6c21249560555288a8610b7ae4b6b54f13de76a7e9ca36b7d0552890805c4003d095
|
7
|
+
data.tar.gz: 1004741d86ed10885af3ea2457a35a9bdda7b761aacb072c417a40c749e6d4db301df533ac9a79470be5ccb670002dd39a72a25df73de635cc4d37326f91ae15
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nbppl (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.7.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
coderay (1.1.3)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
14
|
+
hashdiff (1.0.1)
|
15
|
+
method_source (1.0.0)
|
16
|
+
minitest (5.14.4)
|
17
|
+
pry (0.14.1)
|
18
|
+
coderay (~> 1.1)
|
19
|
+
method_source (~> 1.0)
|
20
|
+
public_suffix (4.0.6)
|
21
|
+
rake (10.5.0)
|
22
|
+
rexml (3.2.5)
|
23
|
+
vcr (6.0.0)
|
24
|
+
webmock (3.13.0)
|
25
|
+
addressable (>= 2.3.6)
|
26
|
+
crack (>= 0.3.2)
|
27
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
x86_64-darwin-20
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 2.0)
|
34
|
+
minitest (~> 5.0)
|
35
|
+
nbppl!
|
36
|
+
pry (~> 0.14)
|
37
|
+
rake (~> 10.0)
|
38
|
+
vcr (~> 6.0)
|
39
|
+
webmock (~> 3.13)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.2.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Mateusz Juraszek
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Nbppl
|
2
|
+
|
3
|
+
Simple API client to fetch exchange rate to PLN for selected currency and date from http://api.nbp.pl
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nbppl'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nbppl
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# fetch mid rate for specific currency and date
|
25
|
+
Nbppl::Client.new.fetch_mid_rate("EUR", Date.parse("2021-06-01"))
|
26
|
+
|
27
|
+
# fetch mid rate from closest date in the past
|
28
|
+
Nbppl::Client.new.closest_mid_rate("USD", Date.parse("2021-06-06"))
|
29
|
+
=> [3.6931, #<Date: 2021-06-04 ((2459370j,0s,0n),+0s,2299161j)>]
|
30
|
+
|
31
|
+
# use caching by making multiple calls with same class instance
|
32
|
+
client = Nbppl::Client.new
|
33
|
+
client.fetch_mid_rate(a)
|
34
|
+
client.fetch_mid_rate(a) # no unnecessary api call
|
35
|
+
# or by using Nbppl::Client.current
|
36
|
+
Nbppl::Client.current.fetch_mid_rate(a)
|
37
|
+
Nbppl::Client.current.fetch_mid_rate(a) # no unnecessary api call
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/meceo/nbppl.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nbppl"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/EUR/2021-06-01?format=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- api.nbp.pl
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Sun, 06 Jun 2021 10:23:28 GMT
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Pragma:
|
28
|
+
- no-cache
|
29
|
+
Content-Type:
|
30
|
+
- application/json; charset=utf-8
|
31
|
+
Expires:
|
32
|
+
- "-1"
|
33
|
+
Etag:
|
34
|
+
- '"5V/T79V9dugcUYjpDoz9OF8pleRSjLUTCXNxSGp2AyY="'
|
35
|
+
Vary:
|
36
|
+
- Accept-Encoding
|
37
|
+
Set-Cookie:
|
38
|
+
- ee3la5eizeiY4Eix=jei1Xah3; path=/
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
body:
|
42
|
+
encoding: ASCII-8BIT
|
43
|
+
string: '{"table":"A","currency":"euro","code":"EUR","rates":[{"no":"104/A/NBP/2021","effectiveDate":"2021-06-01","mid":4.4749}]}'
|
44
|
+
recorded_at: Sun, 06 Jun 2021 10:23:28 GMT
|
45
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/EUR/2021-06-05?format=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- api.nbp.pl
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 404
|
21
|
+
message: Not Found - Brak danych
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Sun, 06 Jun 2021 10:23:28 GMT
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Pragma:
|
28
|
+
- no-cache
|
29
|
+
Content-Length:
|
30
|
+
- '38'
|
31
|
+
Content-Type:
|
32
|
+
- text/plain; charset=utf-8
|
33
|
+
Expires:
|
34
|
+
- "-1"
|
35
|
+
Set-Cookie:
|
36
|
+
- ee3la5eizeiY4Eix=ud5ahSho; path=/
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: 404 NotFound - Not Found - Brak danych
|
40
|
+
recorded_at: Sun, 06 Jun 2021 10:23:28 GMT
|
41
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/EUR/2021-06-08?format=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- api.nbp.pl
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 400
|
21
|
+
message: !binary |-
|
22
|
+
QrPqZG55IHpha3JlcyBkYXQgLyBJbnZhbGlkIGRhdGUgcmFuZ2U=
|
23
|
+
headers:
|
24
|
+
Date:
|
25
|
+
- Sun, 06 Jun 2021 10:26:19 GMT
|
26
|
+
Cache-Control:
|
27
|
+
- no-cache
|
28
|
+
Pragma:
|
29
|
+
- no-cache
|
30
|
+
Content-Length:
|
31
|
+
- '57'
|
32
|
+
Content-Type:
|
33
|
+
- text/plain; charset=utf-8
|
34
|
+
Expires:
|
35
|
+
- "-1"
|
36
|
+
Set-Cookie:
|
37
|
+
- ee3la5eizeiY4Eix=iePaevi0; path=/
|
38
|
+
body:
|
39
|
+
encoding: ASCII-8BIT
|
40
|
+
string: !binary |-
|
41
|
+
NDAwIEJhZFJlcXVlc3QgLSBCxYLEmWRueSB6YWtyZXMgZGF0IC8gSW52YWxpZCBkYXRlIHJhbmdl
|
42
|
+
recorded_at: Sun, 06 Jun 2021 10:26:20 GMT
|
43
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/FOO/2021-06-01?format=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- api.nbp.pl
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 404
|
21
|
+
message: Not Found - Brak danych
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Sun, 06 Jun 2021 10:23:28 GMT
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Pragma:
|
28
|
+
- no-cache
|
29
|
+
Content-Length:
|
30
|
+
- '38'
|
31
|
+
Content-Type:
|
32
|
+
- text/plain; charset=utf-8
|
33
|
+
Expires:
|
34
|
+
- "-1"
|
35
|
+
Set-Cookie:
|
36
|
+
- ee3la5eizeiY4Eix=Naew5Ohp; path=/
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: 404 NotFound - Not Found - Brak danych
|
40
|
+
recorded_at: Sun, 06 Jun 2021 10:23:28 GMT
|
41
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,122 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/USD/2021-06-06?format=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- api.nbp.pl
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 404
|
21
|
+
message: Not Found - Brak danych
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Sun, 06 Jun 2021 11:08:30 GMT
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Pragma:
|
28
|
+
- no-cache
|
29
|
+
Content-Length:
|
30
|
+
- '38'
|
31
|
+
Content-Type:
|
32
|
+
- text/plain; charset=utf-8
|
33
|
+
Expires:
|
34
|
+
- "-1"
|
35
|
+
Set-Cookie:
|
36
|
+
- ee3la5eizeiY4Eix=iePaevi0; path=/
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: 404 NotFound - Not Found - Brak danych
|
40
|
+
recorded_at: Sun, 06 Jun 2021 11:08:29 GMT
|
41
|
+
- request:
|
42
|
+
method: get
|
43
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/USD/2021-06-05?format=json
|
44
|
+
body:
|
45
|
+
encoding: US-ASCII
|
46
|
+
string: ''
|
47
|
+
headers:
|
48
|
+
Accept-Encoding:
|
49
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
50
|
+
Accept:
|
51
|
+
- "*/*"
|
52
|
+
User-Agent:
|
53
|
+
- Ruby
|
54
|
+
Host:
|
55
|
+
- api.nbp.pl
|
56
|
+
response:
|
57
|
+
status:
|
58
|
+
code: 404
|
59
|
+
message: Not Found - Brak danych
|
60
|
+
headers:
|
61
|
+
Date:
|
62
|
+
- Sun, 06 Jun 2021 11:08:30 GMT
|
63
|
+
Cache-Control:
|
64
|
+
- no-cache
|
65
|
+
Pragma:
|
66
|
+
- no-cache
|
67
|
+
Content-Length:
|
68
|
+
- '38'
|
69
|
+
Content-Type:
|
70
|
+
- text/plain; charset=utf-8
|
71
|
+
Expires:
|
72
|
+
- "-1"
|
73
|
+
Set-Cookie:
|
74
|
+
- ee3la5eizeiY4Eix=Naew5Ohp; path=/
|
75
|
+
body:
|
76
|
+
encoding: UTF-8
|
77
|
+
string: 404 NotFound - Not Found - Brak danych
|
78
|
+
recorded_at: Sun, 06 Jun 2021 11:08:29 GMT
|
79
|
+
- request:
|
80
|
+
method: get
|
81
|
+
uri: http://api.nbp.pl/api/exchangerates/rates/a/USD/2021-06-04?format=json
|
82
|
+
body:
|
83
|
+
encoding: US-ASCII
|
84
|
+
string: ''
|
85
|
+
headers:
|
86
|
+
Accept-Encoding:
|
87
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
88
|
+
Accept:
|
89
|
+
- "*/*"
|
90
|
+
User-Agent:
|
91
|
+
- Ruby
|
92
|
+
Host:
|
93
|
+
- api.nbp.pl
|
94
|
+
response:
|
95
|
+
status:
|
96
|
+
code: 200
|
97
|
+
message: OK
|
98
|
+
headers:
|
99
|
+
Date:
|
100
|
+
- Sun, 06 Jun 2021 11:08:29 GMT
|
101
|
+
Cache-Control:
|
102
|
+
- no-cache
|
103
|
+
Pragma:
|
104
|
+
- no-cache
|
105
|
+
Content-Type:
|
106
|
+
- application/json; charset=utf-8
|
107
|
+
Expires:
|
108
|
+
- "-1"
|
109
|
+
Etag:
|
110
|
+
- '"+/l91iuNqONjHTHtn9Ia638Afj6O5HR2Wt8xfn7mGZo="'
|
111
|
+
Vary:
|
112
|
+
- Accept-Encoding
|
113
|
+
Set-Cookie:
|
114
|
+
- ee3la5eizeiY4Eix=ud5ahSho; path=/
|
115
|
+
Transfer-Encoding:
|
116
|
+
- chunked
|
117
|
+
body:
|
118
|
+
encoding: ASCII-8BIT
|
119
|
+
string: !binary |-
|
120
|
+
eyJ0YWJsZSI6IkEiLCJjdXJyZW5jeSI6ImRvbGFyIGFtZXJ5a2HFhHNraSIsImNvZGUiOiJVU0QiLCJyYXRlcyI6W3sibm8iOiIxMDYvQS9OQlAvMjAyMSIsImVmZmVjdGl2ZURhdGUiOiIyMDIxLTA2LTA0IiwibWlkIjozLjY5MzF9XX0=
|
121
|
+
recorded_at: Sun, 06 Jun 2021 11:08:29 GMT
|
122
|
+
recorded_with: VCR 6.0.0
|
data/lib/nbppl.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nbppl/version"
|
4
|
+
require "date"
|
5
|
+
require "uri"
|
6
|
+
require "net/http"
|
7
|
+
require "json"
|
8
|
+
|
9
|
+
module Nbppl
|
10
|
+
class ErrorResponse < StandardError; end
|
11
|
+
class Client
|
12
|
+
NPB_PL_API_URL = "http://api.nbp.pl/api"
|
13
|
+
|
14
|
+
def self.current
|
15
|
+
@current ||= Client.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@cache = Hash.new { |h,k| h[k] = {} }
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_mid_rate(currency, date = Date.today)
|
23
|
+
if @cache[currency].has_key?(date.to_s)
|
24
|
+
return @cache[currency][date.to_s]
|
25
|
+
end
|
26
|
+
|
27
|
+
url = "#{NPB_PL_API_URL}/exchangerates/rates/a/#{currency}/#{date}?format=json"
|
28
|
+
uri = URI(url)
|
29
|
+
response = Net::HTTP.get_response(uri)
|
30
|
+
|
31
|
+
rate = parse_response(response)
|
32
|
+
@cache[currency][date.to_s] = rate && rate["rates"].first["mid"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def closest_mid_rate(currency, date = Date.today)
|
36
|
+
rate = nil
|
37
|
+
until rate = fetch_mid_rate(currency, date)
|
38
|
+
date -= 1
|
39
|
+
end
|
40
|
+
[rate, date]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def parse_response(response)
|
46
|
+
case response.code
|
47
|
+
when "404"
|
48
|
+
nil
|
49
|
+
when "200"
|
50
|
+
JSON.parse(response.body)
|
51
|
+
else
|
52
|
+
message = "#{response.code}, #{response.body}".force_encoding("UTF-8")
|
53
|
+
raise ErrorResponse.new(message)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/nbppl.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "nbppl/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "nbppl"
|
7
|
+
spec.version = Nbppl::VERSION
|
8
|
+
spec.authors = ["Mateusz Juraszek"]
|
9
|
+
spec.email = ["meceo00@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Simple API client for NBP PL exchange rate service}
|
12
|
+
spec.description = %q{Provides simple API client to fetch exchange rate to PLN for selected currency and date from http://api.nbp.pl}
|
13
|
+
spec.homepage = "http://github.com/meceo/nbppl"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "http://github.com/meceo/nbppl"
|
20
|
+
spec.metadata["changelog_uri"] = "http://github.com/meceo/nbppl"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "pry", "~> 0.14"
|
33
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
34
|
+
spec.add_development_dependency "webmock", "~> 3.13"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nbppl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mateusz Juraszek
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: vcr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
description: Provides simple API client to fetch exchange rate to PLN for selected
|
98
|
+
currency and date from http://api.nbp.pl
|
99
|
+
email:
|
100
|
+
- meceo00@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".ruby-version"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- fixtures/vcr_cassettes/exchangerates_rates_a_EUR_2021-06-01.yml
|
116
|
+
- fixtures/vcr_cassettes/exchangerates_rates_a_EUR_2021-06-05.yml
|
117
|
+
- fixtures/vcr_cassettes/exchangerates_rates_a_EUR_2021-06-08.yml
|
118
|
+
- fixtures/vcr_cassettes/exchangerates_rates_a_FOO_2021-06-01.yml
|
119
|
+
- fixtures/vcr_cassettes/exchangerates_rates_a_USD_2021-06-06_2021-06-05_2021-06-04.yml
|
120
|
+
- lib/nbppl.rb
|
121
|
+
- lib/nbppl/version.rb
|
122
|
+
- nbppl.gemspec
|
123
|
+
homepage: http://github.com/meceo/nbppl
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata:
|
127
|
+
allowed_push_host: https://rubygems.org
|
128
|
+
homepage_uri: http://github.com/meceo/nbppl
|
129
|
+
source_code_uri: http://github.com/meceo/nbppl
|
130
|
+
changelog_uri: http://github.com/meceo/nbppl
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubygems_version: 3.2.3
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Simple API client for NBP PL exchange rate service
|
150
|
+
test_files: []
|