money-currencylayer-bank 0.4.0 → 0.4.1

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: 37108e2aeabffc38f2c89a1db5161ca94d52e00e
4
- data.tar.gz: 345f18d20d8cac0d4aa1a9b401021ec93af72301
3
+ metadata.gz: 2c5a08a77bda99cbfcd572fbd6aec7d24a30e4ea
4
+ data.tar.gz: 17c697f0262bdedadf2c5bb9019364b10b3b8417
5
5
  SHA512:
6
- metadata.gz: b10c6233f280ced125b6646341eac9b2e9859581154f8643d1ac984f44ad2018f1a2f53869d0e28d8b8be0fd6758bdc7680fda8880f683c51a35779c8a23e1d8
7
- data.tar.gz: 334f01cd4f112a59adad4596b5f105dcaf2bf068c3077abd4f8d16936e6f9c25beed962cbff4f44a3ca654166fe4f43466e3786de95602763c432cc07659ea44
6
+ metadata.gz: 8afffad25d2b2fe4ae7253d903487253fb838b3a8fe260dda2f2160d80cc896102c4afe1654ca0436e0785ab90178832048088d66761d6c2af1c7a5c6dc8a475
7
+ data.tar.gz: 033896568dfbe42df8e55042a7255390a2ed93a7257397e04cedd5d9357c2663f130cb5840193f24db752e706f3585e56276400b62574854bff7ee13d65907e2
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Money Currencylayer Bank
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/money-currencylayer-bank.svg)](https://rubygems.org/gems/money-currencylayer-bank)
4
+ [![Build Status](https://secure.travis-ci.org/phlegx/money-currencylayer-bank.svg?branch=master)](https://travis-ci.org/phlegx/money-currencylayer-bank)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/phlegx/money-currencylayer-bank.svg)](https://codeclimate.com/github/phlegx/money-currencylayer-bank)
6
+ [![Inline docs](http://inch-ci.org/github/phlegx/money-currencylayer-bank.svg?branch=master)](http://inch-ci.org/github/phlegx/money-currencylayer-bank)
7
+ [![License](https://img.shields.io/github/license/phlegx/money-currencylayer-bank.svg)](http://opensource.org/licenses/MIT)
8
+
3
9
  A gem that calculates the exchange rate using published rates from
4
10
  [currencylayer.com](https://currencylayer.com/)
5
11
 
@@ -99,10 +105,3 @@ bundle exec rake
99
105
  The MIT License
100
106
 
101
107
  Copyright (c) 2015 Phlegx Systems OG
102
-
103
- ---
104
- [![Gem Version](https://badge.fury.io/rb/money-currencylayer-bank.svg)](https://rubygems.org/gems/money-currencylayer-bank)
105
- [![Build Status](https://secure.travis-ci.org/phlegx/money-currencylayer-bank.svg?branch=master)](https://travis-ci.org/phlegx/money-currencylayer-bank)
106
- [![Code Climate](http://img.shields.io/codeclimate/github/phlegx/money-currencylayer-bank.svg)](https://codeclimate.com/github/phlegx/money-currencylayer-bank)
107
- [![Inline docs](http://inch-ci.org/github/phlegx/money-currencylayer-bank.svg?branch=master)](http://inch-ci.org/github/phlegx/money-currencylayer-bank)
108
- [![License](https://img.shields.io/github/license/phlegx/money-currencylayer-bank.svg)](http://opensource.org/licenses/MIT)
@@ -23,7 +23,8 @@ class Money
23
23
  CL_SOURCE = 'USD'
24
24
 
25
25
  # Use https to fetch rates from CurrencylayerBank
26
- # CurrencylayerBank only allows http as connection for the free plan users.
26
+ # CurrencylayerBank only allows http as connection
27
+ # for the free plan users.
27
28
  attr_accessor :secure_connection
28
29
 
29
30
  # API must have a valid access_key
@@ -42,7 +43,8 @@ class Money
42
43
  attr_reader :ttl_in_seconds
43
44
 
44
45
  # Set the base currency for all rates. By default, USD is used.
45
- # CurrencylayerBank only allows USD as base currency for the free plan users.
46
+ # CurrencylayerBank only allows USD as base currency
47
+ # for the free plan users.
46
48
  #
47
49
  # @example
48
50
  # source = 'USD'
@@ -178,7 +180,15 @@ class Money
178
180
  # Get expire rates, first from cache and then from url
179
181
  # @return [Hash] key is country code (ISO 3166-1 alpha-3) value Float
180
182
  def exchange_rates
181
- doc = JSON.parse(read_from_cache) rescue doc = JSON.parse(read_from_url) rescue doc = { 'quotes' => {}}
183
+ begin
184
+ doc = JSON.parse(read_from_cache.to_s)
185
+ rescue JSON::ParserError
186
+ begin
187
+ doc = JSON.parse(read_from_url)
188
+ rescue JSON::ParserError
189
+ doc = { 'quotes' => {} }
190
+ end
191
+ end
182
192
  @cl_rates = doc['quotes']
183
193
  end
184
194
 
@@ -0,0 +1 @@
1
+ your access_key from https://currencylayer.com/product
@@ -65,10 +65,10 @@ describe Money::Bank::CurrencylayerBank do
65
65
  before do
66
66
  subject.cache = nil
67
67
  subject.access_key = TEST_ACCESS_KEY
68
+ stub(subject).read_from_url { File.read cache_path }
68
69
  end
69
70
 
70
71
  it 'should get from url' do
71
- stub(OpenURI::OpenRead).open(url) { File.read cache_path }
72
72
  subject.update_rates
73
73
  subject.cl_rates.wont_be_empty
74
74
  end
@@ -82,19 +82,22 @@ describe Money::Bank::CurrencylayerBank do
82
82
  it "should use the non-secure http url if secure_connection isn't set" do
83
83
  subject.secure_connection = nil
84
84
  subject.access_key = TEST_ACCESS_KEY
85
- subject.source_url.must_equal "#{url}?source=#{source}&access_key=#{TEST_ACCESS_KEY}"
85
+ subject.source_url.must_equal "#{url}?source=#{source}&"\
86
+ "access_key=#{TEST_ACCESS_KEY}"
86
87
  end
87
88
 
88
89
  it 'should use the non-secure http url if secure_connection is false' do
89
90
  subject.secure_connection = false
90
91
  subject.access_key = TEST_ACCESS_KEY
91
- subject.source_url.must_equal "#{url}?source=#{source}&access_key=#{TEST_ACCESS_KEY}"
92
+ subject.source_url.must_equal "#{url}?source=#{source}&"\
93
+ "access_key=#{TEST_ACCESS_KEY}"
92
94
  end
93
95
 
94
96
  it 'should use the secure https url if secure_connection is set to true' do
95
97
  subject.secure_connection = true
96
98
  subject.access_key = TEST_ACCESS_KEY
97
- subject.source_url.must_equal "#{secure_url}?source=#{source}&access_key=#{TEST_ACCESS_KEY}"
99
+ subject.source_url.must_equal "#{secure_url}?source=#{source}&"\
100
+ "access_key=#{TEST_ACCESS_KEY}"
98
101
  subject.source_url.must_include 'https://'
99
102
  end
100
103
  end
@@ -103,10 +106,10 @@ describe Money::Bank::CurrencylayerBank do
103
106
  before do
104
107
  subject.cache = "space_dir#{rand(999_999_999)}/out_space_file.json"
105
108
  subject.access_key = TEST_ACCESS_KEY
109
+ stub(subject).read_from_url { File.read cache_path }
106
110
  end
107
111
 
108
112
  it 'should get from url' do
109
- stub(OpenURI::OpenRead).open(url) { File.read cache_path }
110
113
  subject.update_rates
111
114
  subject.cl_rates.wont_be_empty
112
115
  end
@@ -149,6 +152,7 @@ describe Money::Bank::CurrencylayerBank do
149
152
  before do
150
153
  subject.access_key = TEST_ACCESS_KEY
151
154
  subject.cache = cache_path
155
+ stub(subject).read_from_url { File.read cache_path }
152
156
  subject.update_rates
153
157
  end
154
158
 
@@ -211,7 +215,7 @@ describe Money::Bank::CurrencylayerBank do
211
215
  before do
212
216
  subject.access_key = TEST_ACCESS_KEY
213
217
  subject.cache = temp_cache_path
214
- stub(OpenURI::OpenRead).open(url) { File.read cache_path }
218
+ stub(subject).read_from_url { File.read cache_path }
215
219
  subject.save_rates
216
220
  end
217
221
 
data/test/test_helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'monetize'
6
6
  require 'timecop'
7
7
  require 'pry'
8
8
 
9
- TEST_ACCESS_KEY_PATH = File.join(File.dirname(__FILE__), '..', 'TEST_ACCESS_KEY')
9
+ TEST_ACCESS_KEY_PATH = File.join(File.dirname(__FILE__), 'TEST_ACCESS_KEY')
10
10
  TEST_ACCESS_KEY = ENV['TEST_ACCESS_KEY'] || File.read(TEST_ACCESS_KEY_PATH)
11
11
 
12
12
  if TEST_ACCESS_KEY.nil? || TEST_ACCESS_KEY.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-currencylayer-bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egon Zemmer
@@ -176,6 +176,7 @@ files:
176
176
  - LICENSE
177
177
  - README.md
178
178
  - lib/money/bank/currencylayer_bank.rb
179
+ - test/TEST_ACCESS_KEY
179
180
  - test/currencylayer_bank_test.rb
180
181
  - test/live.json
181
182
  - test/test_helper.rb