money-oxr 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4bd37837495d074315c1d36f74eda52210f8500
4
- data.tar.gz: 974de53313238e11c02da30fb18a39c45beca679
3
+ metadata.gz: f22f763f8ab1e4b42d2c5e3e0b63f7f8e560279b
4
+ data.tar.gz: 816d4178467ce2d53353f351a69cef092eb3126a
5
5
  SHA512:
6
- metadata.gz: 59c86351dab9217c7554a81817f79591e3f227424ee70a3923ea4c50ed1e8a18ff06a8b0f6dd0f1ab61148e0b2c7d9305ca2a18413458abb7fd0840e0e054f61
7
- data.tar.gz: 56934936045e5a15bba1d470afc0807ef48be130a15b1f08d72408324858363b1c2d4463c92f4494ece67073614a289c14f2496914721b3a12a00b03c2eee0a5
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
- # Money::Oxr
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "money-oxr"
5
- spec.version = "0.1.0"
5
+ spec.version = "0.2.0"
6
6
  spec.authors = ["Ed Lebert"]
7
7
 
8
8
  spec.summary = %q{A Money-compatible rate store that uses exchange rates from openexchangerates.org.}
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.1.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