money-oxr 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +3 -3
- data/lib/money_oxr/rates_store.rb +8 -1
- data/money-oxr.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f22f763f8ab1e4b42d2c5e3e0b63f7f8e560279b
|
4
|
+
data.tar.gz: 816d4178467ce2d53353f351a69cef092eb3126a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c53e24461edcf82f5d28b967ea764416cb183835af9450abc092e8ab93cd6a3f23e7069471e1a4a1172958266f6142780d085cf672108941f90f8e34552a432
|
7
|
+
data.tar.gz: 05a503ea60a6c0782ec6ad9982704f7e8d33d41487749142d66301984c1a22581056a5e6e6f6fc49c99bb7eff1038e195fd285272a5b93bc62699815111b7800
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
|
5
|
+
[How to use a CHANGELOG](http://keepachangelog.com/)
|
6
|
+
|
7
|
+
## [0.2.0] - 2018-03-19
|
8
|
+
### Added
|
9
|
+
- Added safe handling of API request errors.
|
10
|
+
|
11
|
+
|
12
|
+
## [0.1.0] - 2018-03-19
|
13
|
+
### Changed
|
14
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# MoneyOXR
|
2
2
|
|
3
|
-
A Money-compatible rate store that uses exchange rates from openexchangerates.org.
|
3
|
+
A [Money](https://github.com/RubyMoney/money)-compatible rate store that uses exchange rates from openexchangerates.org.
|
4
4
|
|
5
|
-
A few improvements over the existing money-open-exchange-rates gem:
|
5
|
+
A few improvements over the existing [money-open-exchange-rates](https://github.com/spk/money-open-exchange-rates) gem:
|
6
6
|
|
7
7
|
* Uses BigDecimal instead of Float for exchange rates.
|
8
8
|
* Automatically caches API results to file if a :cache_path option is provided.
|
@@ -8,7 +8,7 @@ module MoneyOXR
|
|
8
8
|
|
9
9
|
class UnsupportedCurrency < StandardError; end
|
10
10
|
|
11
|
-
attr_reader :app_id, :source, :cache_path, :last_updated_at, :max_age
|
11
|
+
attr_reader :app_id, :source, :cache_path, :last_updated_at, :max_age, :on_api_failure
|
12
12
|
|
13
13
|
def initialize(*)
|
14
14
|
super
|
@@ -16,6 +16,7 @@ module MoneyOXR
|
|
16
16
|
@source = options[:source] || 'USD'
|
17
17
|
@cache_path = options[:cache_path]
|
18
18
|
@max_age = options[:max_age]
|
19
|
+
@on_api_failure = options[:on_api_failure] || :warn
|
19
20
|
end
|
20
21
|
|
21
22
|
def get_rate(iso_from, iso_to)
|
@@ -57,6 +58,8 @@ module MoneyOXR
|
|
57
58
|
|
58
59
|
def load_from_api
|
59
60
|
json = get_json_from_api
|
61
|
+
# Protect against saving or loading nil/bad data from API.
|
62
|
+
return unless json && json =~ /rates/
|
60
63
|
if cache_path
|
61
64
|
write_cache_file(json)
|
62
65
|
load_from_cache_path
|
@@ -67,6 +70,10 @@ module MoneyOXR
|
|
67
70
|
|
68
71
|
def get_json_from_api
|
69
72
|
open(api_uri).read
|
73
|
+
rescue OpenURI::HTTPError, SocketError
|
74
|
+
raise unless on_api_failure == :warn
|
75
|
+
warn "#{$!.class}: #{$!.message}"
|
76
|
+
nil
|
70
77
|
end
|
71
78
|
|
72
79
|
def api_uri
|
data/money-oxr.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-oxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Lebert
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- ".gitignore"
|
90
90
|
- ".rspec"
|
91
91
|
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|