money-oxr 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f22f763f8ab1e4b42d2c5e3e0b63f7f8e560279b
4
- data.tar.gz: 816d4178467ce2d53353f351a69cef092eb3126a
3
+ metadata.gz: 6d40cd83560c6539f8aab07757780f58fe9fa78d
4
+ data.tar.gz: 100dfdab0c1e84cfe0bbe736913aca1bb2382571
5
5
  SHA512:
6
- metadata.gz: 1c53e24461edcf82f5d28b967ea764416cb183835af9450abc092e8ab93cd6a3f23e7069471e1a4a1172958266f6142780d085cf672108941f90f8e34552a432
7
- data.tar.gz: 05a503ea60a6c0782ec6ad9982704f7e8d33d41487749142d66301984c1a22581056a5e6e6f6fc49c99bb7eff1038e195fd285272a5b93bc62699815111b7800
6
+ metadata.gz: 2b985081fda88720bede03904f2533002a66d09da3eaa0c085e198267c69103d3e812c1f582f07731c5db9c2bda87c3bc942ea5e85b5263ae3ecc21839d2dc42
7
+ data.tar.gz: f6e6bef059fb61f9828bb4eb91557f50a4d3530a1dfe6dc31c5c57a580f8c1ef7ce8afba05cd597d64a4ba954ce5a9f42221f9b226624f51befe5c76853ac55e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  [How to use a CHANGELOG](http://keepachangelog.com/)
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [0.3.0] - 2018-03-21
10
+ ### Changed
11
+ - Return nil in RateStore if rate is unknown.
12
+ - Updated Money dependency to ~> 6.6
13
+
7
14
  ## [0.2.0] - 2018-03-19
8
15
  ### Added
9
16
  - Added safe handling of API request errors.
data/README.md CHANGED
@@ -28,17 +28,15 @@ Or install it yourself as:
28
28
 
29
29
  With the gem, you do not need to manually add exchange rates. Calling load will
30
30
  load the rates from the cache file or download the rates from the API depending
31
- on your options. The :source option defaults to
31
+ on your options.
32
32
 
33
33
  ``` ruby
34
34
  require 'money_oxr/bank'
35
- oxr_bank = MoneyOXR::Bank.new(
35
+ Money.default_bank = MoneyOXR::Bank.new(
36
36
  app_id: 'abcd1234',
37
- cache_path: 'tmp/oxr.json',
37
+ cache_path: 'config/oxr.json',
38
38
  max_age: 86400
39
39
  )
40
- oxr_bank.store.load
41
- Money.default_bank = oxr_bank
42
40
  ```
43
41
 
44
42
  If you only want to load data from a file without ever fetching from the API,
@@ -46,26 +44,24 @@ the :app_id and :max_age options are not necessary.
46
44
 
47
45
  ``` ruby
48
46
  require 'money_oxr/bank'
49
- oxr_bank = MoneyOXR::Bank.new(
47
+ Money.default_bank = MoneyOXR::Bank.new(
50
48
  cache_path: 'config/oxr.json'
51
49
  )
52
- oxr_bank.store.load
53
- Money.default_bank = oxr_bank
54
50
  ```
55
51
 
52
+ ### :source
53
+
56
54
  If you are on a paid plan from openexchangerates.org and you wish to use a different
57
- source currency, you may provide it with the :source option.
55
+ source currency, you may provide it with the :source option. The default is `USD`.
58
56
 
59
57
  ``` ruby
60
58
  require 'money_oxr/bank'
61
- oxr_bank = MoneyOXR::Bank.new(
59
+ Money.default_bank = MoneyOXR::Bank.new(
62
60
  app_id: 'abcd1234',
63
- cache_path: 'tmp/oxr.json',
61
+ cache_path: 'config/oxr.json',
64
62
  max_age: 86400,
65
63
  source: 'GBP'
66
64
  )
67
- oxr_bank.store.load
68
- Money.default_bank = oxr_bank
69
65
  ```
70
66
 
71
67
  ## Development
@@ -6,8 +6,6 @@ require 'open-uri'
6
6
  module MoneyOXR
7
7
  class RatesStore < Money::RatesStore::Memory
8
8
 
9
- class UnsupportedCurrency < StandardError; end
10
-
11
9
  attr_reader :app_id, :source, :cache_path, :last_updated_at, :max_age, :on_api_failure
12
10
 
13
11
  def initialize(*)
@@ -23,15 +21,15 @@ module MoneyOXR
23
21
  load
24
22
  super || begin
25
23
  if iso_from == source
26
- raise UnsupportedCurrency.new(iso_to)
24
+ nil
27
25
  elsif inverse_rate = super(iso_to, iso_from)
28
26
  add_rate(iso_from, iso_to, 1 / inverse_rate)
29
27
  elsif iso_to == source
30
- raise UnsupportedCurrency.new(iso_from)
28
+ nil
31
29
  else
32
30
  rate1 = get_rate(iso_from, source)
33
31
  rate2 = get_rate(source, iso_to)
34
- add_rate(iso_from, iso_to, rate1 * rate2)
32
+ rate1 && rate2 && add_rate(iso_from, iso_to, rate1 * rate2)
35
33
  end
36
34
  end
37
35
  end
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.2.0"
5
+ spec.version = "0.3.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.}
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  end
15
15
  spec.require_paths = ["lib"]
16
16
 
17
- spec.add_dependency "money", "~> 6.0"
17
+ spec.add_dependency "money", "~> 6.6"
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.15"
20
20
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-oxr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Lebert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-19 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: money
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '6.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '6.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement