riksbank_currency 0.1.1 → 0.1.2
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/README.md +31 -32
- data/lib/riksbank_currency/fetcher/date_fetcher.rb +2 -2
- data/lib/riksbank_currency/rates.rb +3 -3
- data/lib/riksbank_currency/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff68a1ec03900b93f309ef1314e2977686c84f76
|
|
4
|
+
data.tar.gz: 10a41e49061cd1d6b4e97ffd99c5522fedf98c8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e5109179f68b0d75482f8caddca6c830a7a0fb4b2ff2418ccbee6d72bbb406483399861495cf246a90959adda205ec5e2fc2f0568394423806561aa42a20d3d
|
|
7
|
+
data.tar.gz: f68f82dadb2d0660d857a66deeaaff455b7a12942d8998c5b9940ecb94418f398ffe16c6ebfb92615e6eba446747ef95085de24caf3605579a49f8ad4270ad10
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Riksbank Exchange Rates
|
|
2
2
|
|
|
3
|
-
Simple wrapper for Riksbank API that returns currency exchange rates for
|
|
3
|
+
Simple wrapper for Riksbank API that returns currency exchange rates for specific date.
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
@@ -29,15 +29,15 @@ Or install it yourself as:
|
|
|
29
29
|
|
|
30
30
|
Initializer options:
|
|
31
31
|
|
|
32
|
-
* `date` -
|
|
33
|
-
* `base` - base currency (by default
|
|
32
|
+
* `date` - specific date we want to get exchange rates for. It should be a valid `Date` object
|
|
33
|
+
* `base` - base currency (`SEK` is used by default)
|
|
34
34
|
* `rates` - you can pass your own hash with rates. Can be useful for caching purposes
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
### Retrieve a specific rate
|
|
38
38
|
|
|
39
39
|
```ruby
|
|
40
|
-
#
|
|
40
|
+
# How many euros in one american dollar?
|
|
41
41
|
bank.rate('USD', 'EUR').to_f # => 0.80607
|
|
42
42
|
|
|
43
43
|
# by default it converts to SEK
|
|
@@ -56,42 +56,48 @@ Get all rates
|
|
|
56
56
|
bank.rates # => { 'NOK' => 105.556298, 'INR' => 13.619511, … }
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### Rates from holidays / weekends
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
bank
|
|
61
|
+
Exchange rates are not changed during holidays or weekends.
|
|
62
|
+
If you query bank API directly, you will get an empty hash in response.
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
So, therefore at 3 o'clock of morning bank doensn't have fresh rates and we should use
|
|
66
|
-
rates from prevoius day.
|
|
67
|
-
|
|
68
|
-
This gem deals with all of this problems:
|
|
64
|
+
To avoid that, this gem provides last known rates:
|
|
69
65
|
|
|
70
66
|
```ruby
|
|
71
|
-
# 20.01.2018 is Saturday, bank
|
|
67
|
+
# 20.01.2018 is Saturday, bank is closed
|
|
72
68
|
holiday_bank = RiksbankCurrency::Rates.new(date: Date.new(2018, 1, 20))
|
|
73
69
|
|
|
74
|
-
# rates will be
|
|
70
|
+
# Last known rates will be fetched instead (from Friday).
|
|
75
71
|
holiday_bank.rate_date # Fri, 19 Jan 2018
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
````
|
|
73
|
+
|
|
74
|
+
### Riksbank updates rates twice a day (in the morning and in the evening)
|
|
75
|
+
|
|
76
|
+
If you try to fetch rates at 03.00 in the morning, then you will get an empty hash from the bank.
|
|
77
|
+
Therefore gem will return rates from a previous date.
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
81
80
|
# Time.current => Fri, 26 Jan 2018 03:00:00 UTC +00:00
|
|
82
81
|
morning_bank = RiksbankCurrency::Rates.new
|
|
83
82
|
|
|
84
|
-
#
|
|
85
|
-
#
|
|
83
|
+
# It's too early, bank doensn't work at this time
|
|
84
|
+
# Yesterday's rates will be used instead
|
|
86
85
|
morning_bank.rate_date # Thu, 25 Jan 2018
|
|
87
86
|
```
|
|
88
87
|
|
|
89
|
-
|
|
88
|
+
#### Default currencies
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
```ruby
|
|
91
|
+
%w(AUD BRL CAD CHF CNY CZK DKK EUR GBP HKD HUF IDR INR ISK JPY
|
|
92
|
+
KRW MAD MXN NOK NZD PLN RUB SAR SGD THB TRY USD ZAR)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Additional currencies
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
Check bank page to get a fresh list of provided currencies [official bank page](http://www.riksbank.se/en/Interest-and-exchange-rates/Series-for-web-services/).
|
|
98
|
+
|
|
99
|
+
By default this gem is only using existing currencies from 2018.
|
|
100
|
+
For example, FIM (Finland Marka) has published rates until 2002.
|
|
95
101
|
|
|
96
102
|
So, if you wanna get information about FIM exchange rate in 2001 you should
|
|
97
103
|
change the gem defaults:
|
|
@@ -106,13 +112,6 @@ change the gem defaults:
|
|
|
106
112
|
today_bank.rate('FIM') # nil
|
|
107
113
|
```
|
|
108
114
|
|
|
109
|
-
#### Default currencies
|
|
110
|
-
|
|
111
|
-
```ruby
|
|
112
|
-
%w(AUD BRL CAD CHF CNY CZK DKK EUR GBP HKD HUF IDR INR ISK JPY
|
|
113
|
-
KRW MAD MXN NOK NZD PLN RUB SAR SGD THB TRY USD ZAR)
|
|
114
|
-
```
|
|
115
|
-
|
|
116
115
|
## Legal
|
|
117
116
|
|
|
118
117
|
The author of this gem is not affiliated with the Riksbank.
|
|
@@ -3,8 +3,8 @@ module RiksbankCurrency
|
|
|
3
3
|
#
|
|
4
4
|
# @see https://swea.riksbank.se/sweaWS/docs/api/call/getInterestAndExchangeRates.htm
|
|
5
5
|
#
|
|
6
|
-
# IMPORTANT! The date should be less than current date.
|
|
7
|
-
#
|
|
6
|
+
# IMPORTANT! The date should be less than current date.
|
|
7
|
+
# To get current rates - check TodayFetcher
|
|
8
8
|
class DateFetcher
|
|
9
9
|
def initialize(date)
|
|
10
10
|
@date = date
|
|
@@ -33,11 +33,11 @@ module RiksbankCurrency
|
|
|
33
33
|
@rates ||= fetcher.to_hash
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
# Sometimes date passed to the initializer
|
|
37
|
-
# It
|
|
36
|
+
# Sometimes date passed to the initializer is different from last available exchange date.
|
|
37
|
+
# It could be because of holidays, weekends or bank closing hours.
|
|
38
38
|
#
|
|
39
39
|
# For example, if we want to get rates for the `1st of January 2018` then rate date
|
|
40
|
-
# will be `27th of December 2017`
|
|
40
|
+
# will be `27th of December 2017`, because `1st of January` is a holiday.
|
|
41
41
|
# @return [Date]
|
|
42
42
|
def rate_date
|
|
43
43
|
@rate_date ||= fetcher.rate_date
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: riksbank_currency
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrey Yakovlev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-01-
|
|
11
|
+
date: 2018-01-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|