money-openexchangerates-bank 0.1.2 → 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/README.md +21 -17
- data/lib/money/bank/openexchangerates_bank.rb +12 -5
- data/test/openexchangerates_bank_test.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4498e13a45822f61f922f9c67bcc7afb691b9ab03b833cae8b199fc4894dd086
|
4
|
+
data.tar.gz: a58e8db08d219c37dc4c9b4da8bacdb1318ef93e623ea2e5b8c273e8874ad283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 217ccded63ec3489ce1a99381f6bfa21d4e572a236d06147d47ce75586d3893952d12782f37e5172246105bb61ae77a230ceda7654ca5d537bdc9a0cdcf1b540
|
7
|
+
data.tar.gz: 9924c90ac64d7bc335f68c129a83281374e59021693a2c2b2757dfc15c032e4cb25250fb6d415d8c64056475a601f5b3d5fb26f1598db9c16cf59e7c5df744e3
|
data/README.md
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/money-openexchangerates-bank.svg)](https://rubygems.org/gems/money-openexchangerates-bank)
|
4
4
|
[![Gem](https://img.shields.io/gem/dt/money-openexchangerates-bank.svg?maxAge=2592000)](https://rubygems.org/gems/money-openexchangerates-bank)
|
5
5
|
[![Build Status](https://secure.travis-ci.org/phlegx/money-openexchangerates-bank.svg?branch=master)](https://travis-ci.org/phlegx/money-openexchangerates-bank)
|
6
|
-
[![Code Climate](
|
7
|
-
[![Inline Docs](
|
8
|
-
[![Dependency Status](https://gemnasium.com/phlegx/money-openexchangerates-bank.svg)](https://gemnasium.com/phlegx/money-openexchangerates-bank)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/phlegx/money-openexchangerates-bank.svg)](https://codeclimate.com/github/phlegx/money-openexchangerates-bank)
|
7
|
+
[![Inline Docs](https://inch-ci.org/github/phlegx/money-openexchangerates-bank.svg?branch=master)](http://inch-ci.org/github/phlegx/money-openexchangerates-bank)
|
9
8
|
[![License](https://img.shields.io/github/license/phlegx/money-openexchangerates-bank.svg)](http://opensource.org/licenses/MIT)
|
10
9
|
|
11
10
|
A gem that calculates the exchange rate using published rates from
|
@@ -33,7 +32,7 @@ See more about Openexchangerates product plans on https://openexchangerates.org/
|
|
33
32
|
|
34
33
|
## Features
|
35
34
|
|
36
|
-
* supports
|
35
|
+
* supports over 200 currencies
|
37
36
|
* includes cryptocurrencies
|
38
37
|
* precision of rates up to 6 digits after point
|
39
38
|
* uses fast and reliable json api
|
@@ -61,36 +60,41 @@ Or install it yourself as:
|
|
61
60
|
## Usage
|
62
61
|
|
63
62
|
~~~ ruby
|
64
|
-
# Minimal requirements
|
63
|
+
# Minimal requirements.
|
65
64
|
require 'money/bank/openexchangerates_bank'
|
66
65
|
moxb = Money::Bank::OpenexchangeratesBank.new
|
67
66
|
moxb.access_key = 'your access_key from https://openexchangerates.com/signup'
|
68
67
|
|
69
|
-
# Update rates (get new rates from remote if expired or access rates from cache)
|
70
|
-
moxb.update_rates
|
71
|
-
|
72
|
-
# Force update rates from remote and store in cache
|
73
|
-
# moxb.update_rates(true)
|
74
|
-
|
75
68
|
# (optional)
|
76
69
|
# Set the base currency for all rates. By default, USD is used.
|
77
70
|
# OpenexchangeratesBank only allows USD as base currency for the free plan users.
|
78
71
|
moxb.source = 'EUR'
|
79
72
|
|
80
73
|
# (optional)
|
81
|
-
# Set the seconds after than the current rates are automatically expired
|
82
|
-
#
|
74
|
+
# Set the seconds after than the current rates are automatically expired.
|
75
|
+
# By default, they never expire, in this example 1 day.
|
83
76
|
moxb.ttl_in_seconds = 86400
|
84
77
|
|
85
78
|
# (optional)
|
86
|
-
# Use https to fetch rates from OpenexchangeratesBank
|
79
|
+
# Use https to fetch rates from OpenexchangeratesBank.
|
87
80
|
# OpenexchangeratesBank only allows http as connection for the free plan users.
|
88
81
|
moxb.secure_connection = true
|
89
82
|
|
90
|
-
# Define cache (string or pathname)
|
83
|
+
# Define cache (string or pathname).
|
91
84
|
moxb.cache = 'path/to/file/cache'
|
92
85
|
|
93
|
-
#
|
86
|
+
# Update rates (get new rates from remote if expired or access rates from cache).
|
87
|
+
# Be sure to define the cache first before updating the rates.
|
88
|
+
moxb.update_rates
|
89
|
+
|
90
|
+
# Force update rates from remote and store in cache.
|
91
|
+
# Be sure to define the cache first before updating the rates.
|
92
|
+
# moxb.update_rates(true)
|
93
|
+
|
94
|
+
# Set money rounding mode.
|
95
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
96
|
+
|
97
|
+
# Set money default bank to Openexchangerates bank.
|
94
98
|
Money.default_bank = moxb
|
95
99
|
~~~
|
96
100
|
|
@@ -222,4 +226,4 @@ bundle exec rake
|
|
222
226
|
|
223
227
|
The MIT License
|
224
228
|
|
225
|
-
Copyright (c)
|
229
|
+
Copyright (c) 2022 Phlegx Systems OG
|
@@ -294,11 +294,18 @@ class Money
|
|
294
294
|
# @param straight [Boolean] true for straight, default is careful
|
295
295
|
# @return [Hash] key is country code (ISO 3166-1 alpha-3) value Float
|
296
296
|
def exchange_rates(straight = false)
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
297
|
+
rates = if straight
|
298
|
+
raw_rates_straight
|
299
|
+
else
|
300
|
+
raw_rates_careful
|
301
|
+
end
|
302
|
+
if rates.key?('rates')
|
303
|
+
@rates = rates['rates']
|
304
|
+
elsif rates.key?('error')
|
305
|
+
raise Error, rates['description']
|
306
|
+
else
|
307
|
+
raise Error, 'Unknown rates situation!'
|
308
|
+
end
|
302
309
|
end
|
303
310
|
|
304
311
|
# Get raw exchange rates from cache and then from url
|
@@ -4,6 +4,7 @@
|
|
4
4
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
5
5
|
|
6
6
|
describe Money::Bank::OpenexchangeratesBank do
|
7
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
7
8
|
subject { Money::Bank::OpenexchangeratesBank.new }
|
8
9
|
let(:url) { Money::Bank::OpenexchangeratesBank::CL_URL }
|
9
10
|
let(:secure_url) { Money::Bank::OpenexchangeratesBank::CL_SECURE_URL }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-openexchangerates-bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Egon Zemmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: money
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
rubygems_version: 3.2.
|
188
|
+
rubygems_version: 3.2.24
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: A gem that calculates the exchange rate using published rates from openexchangerates.org.
|