ccy_convertor 0.0.1 → 0.0.2
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 +5 -13
- data/README.md +15 -12
- data/lib/ccy_convertor/rate_providers/currency_layer.rb +14 -0
- data/lib/ccy_convertor/rate_providers/rate_provider.rb +2 -2
- data/lib/ccy_convertor/version.rb +1 -1
- data/lib/ccy_convertor.rb +1 -1
- metadata +11 -10
- data/lib/ccy_convertor/rate_providers/json_rate.rb +0 -13
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZWYyN2JmMjU3M2QxMTM4ZTRmZWU3OTNkMDBlNDg0OTkxMTM0MTVhMw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cd5bc29c2df00a8629ba57024c388232494f90c
|
4
|
+
data.tar.gz: a4ef3c9b93ae1f0ce86987f110f964f81a610dbd
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ODdiOTEzMTUzZTdiYjk1NWZhNTRhNTEyYTk0ZjI5ZTg3OWQ4ZmM0MmYyNDc0
|
11
|
-
NDY0YTBkYjBjZmE1ZTkzOTBhMjEwODM1Y2FkOTU4NGE4Y2M0MmI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MjRkODRkN2Q0NjFiMDYxNDRmMDE3MDZiNzg0ZTQwZmQ4MDY4ZTA3ZDY5NGEx
|
14
|
-
OWYyYWIxN2JkYWFiNzNjNThkZTVmNTk0OGQ2OGEzZWNjOGM3MGYwYWJmNjMz
|
15
|
-
NTgzMmFmMDNmNzk4NGI5ODEzYjljODczZjBmMzY4M2I2ZWI4Mzc=
|
6
|
+
metadata.gz: 96976f7e8d1aa9f0e9acbe5251a631a43197d11ea058d660ec252f2298767b4a1a7ce063bc6d569fbd4692e0a8677f329d36d0cbc00a87695757aa0c852ce322
|
7
|
+
data.tar.gz: bea4e021e2bacef892d284c63321ab6d75fdec76913bba22695e155f14e3ffbd7343069d8aa9646d7118a54d42fd7cb9bad268e4d2cb488f14f34fb363a66ad4
|
data/README.md
CHANGED
@@ -29,20 +29,20 @@ Note: Default rate provider is CcyConvertor::YahooFinance. You can change defau
|
|
29
29
|
Rate provider can also be provided as a parameter. Rate provider is a class which provides rate by using rest_api
|
30
30
|
```ruby
|
31
31
|
CcyConvertor.rate(from_ccy: 'USD', to_ccy: 'NZD', rate_provider: CcyConvertor::OpenExchangeRate)
|
32
|
-
CcyConvertor.rate(from_ccy: 'USD', to_ccy: 'NZD', rate_provider: CcyConvertor::
|
32
|
+
CcyConvertor.rate(from_ccy: 'USD', to_ccy: 'NZD', rate_provider: CcyConvertor::CurrencyLayer)
|
33
33
|
```
|
34
34
|
You can also directly use rate provider class as follows.
|
35
35
|
```ruby
|
36
36
|
CcyConvertor::OpenExchangeRate.rate('USD', 'INR') # will return USD/INR rate
|
37
37
|
```
|
38
|
-
Note: CcyConvertor::OpenExchangeRate and CcyConvertor::
|
38
|
+
Note: CcyConvertor::OpenExchangeRate and CcyConvertor::CurrencyLayer requires api_key. You can register at respective websites to get a api key
|
39
39
|
|
40
40
|
#### Rate Providers
|
41
41
|
| Rate provider class name | rest api source | Api key required |
|
42
42
|
|---|---|---|
|
43
43
|
| CcyConvertor::YahooFinance | 'yahoo.finance.xchange' table yql | no |
|
44
44
|
| CcyConvertor::OpenExchangeRate | www.openexchangerates.org | yes |
|
45
|
-
| CcyConvertor::
|
45
|
+
| CcyConvertor::CurrencyLayer | www.currencylayer.com | yes |
|
46
46
|
|
47
47
|
Api key can be provided individually to this classes as
|
48
48
|
|
@@ -65,18 +65,21 @@ Below code will use default rate provider. Default rate provider is configurable
|
|
65
65
|
CcyConvertor.convert(from_ccy: 'USD', to_ccy: 'NZD', amount: 10)
|
66
66
|
10.usd.to_nzd
|
67
67
|
```
|
68
|
-
You can also get all
|
68
|
+
You can also get all currency rate (rate matrix) with respect to USD in single request for OpenExchangeRate and CurrencyLayer rate provider
|
69
69
|
```ruby
|
70
70
|
Ccyconvertor::OpenExchangeRate.rate_matrix
|
71
|
+
Ccyconvertor::CurrencyLayer.rate_matrix
|
71
72
|
```
|
72
73
|
Above method will return hash with currency code as key and rate as value. All rates would be with respect to USD. OpenExchangeRate do not allow us to specify other base currency and USD is always the base currency.
|
73
74
|
|
74
|
-
For Ccyconvertor::
|
75
|
+
While For Ccyconvertor::CurrencyLayer we can specify the base currency
|
75
76
|
```ruby
|
76
|
-
Ccyconvertor::
|
77
|
+
Ccyconvertor::CurrencyLayer.rate_matrix('NZD')
|
77
78
|
```
|
78
79
|
All rates returned would be with respect to NZD. If no parameter is given then base currency is USD by default
|
79
|
-
|
80
|
+
|
81
|
+
Note:
|
82
|
+
You cannot provide base currency for free account at currencylayer.com. By defualt base currency will be USD. You need a paid account at currencylayer.com to supply base currency. And Ccyconvertor::YahooFinance do not support rate_matrix method
|
80
83
|
|
81
84
|
## Configuration
|
82
85
|
|
@@ -84,7 +87,7 @@ You can configure following parameters
|
|
84
87
|
|
85
88
|
1. default_rate-provider: Default rate provider is the rate provider which is used when no rate provider is species. Rate provider is a api service that this gem uses to provide rate. By default default rate provider is CcyConvertor::YahooFinance. Check rate providers details [here](#rate-providers)
|
86
89
|
|
87
|
-
2. api_keys: CcyConvertor::OpenExchangeRate and CcyConvertor::
|
90
|
+
2. api_keys: CcyConvertor::OpenExchangeRate and CcyConvertor::CurrencyLayer provider requires api_key. You can register at there respective sites to get the api_key
|
88
91
|
|
89
92
|
3. cache_duration: specifies the time for which the response would be cached. By default this time is zero seconds i.e no caching is done by default. If cache_duration is 60 seconds and if you want a exchange rate of USD/INR multiple times in your application, request to rate provider would be made only once in 60 seconds and after 60 seconds next request would be made.
|
90
93
|
ActiveSupport::Cache is used for caching
|
@@ -98,15 +101,15 @@ Sample configuration:
|
|
98
101
|
CcyConvertor.configure do |config|
|
99
102
|
config.round_up_rate = 4
|
100
103
|
config.round_up_amount = 4
|
101
|
-
config.default_rate_provider = CcyConvertor::
|
104
|
+
config.default_rate_provider = CcyConvertor::CurrencyLayer
|
102
105
|
config.api_keys = {
|
103
106
|
open_exchange_rate: 'XXXXXXXXX',
|
104
|
-
|
107
|
+
currency_layer: 'XXXXXX'
|
105
108
|
}
|
106
109
|
config.cache_duration = {
|
107
110
|
open_exchange_rate: 20,
|
108
111
|
yahoo_finance: 30,
|
109
|
-
|
112
|
+
currency_layer: 20
|
110
113
|
}
|
111
114
|
end
|
112
115
|
```
|
@@ -151,7 +154,7 @@ Above method should return url for geting exchange rate between from_ccy and to_
|
|
151
154
|
```ruby
|
152
155
|
rate(from_ccy, to_ccy)
|
153
156
|
```
|
154
|
-
Above method should return exchange rate(Numeric type) between from_ccy and to_ccy. You can call ```rate_response(from_ccy, to_ccy)``` inside ```rate(from_ccy, to_ccy)``` to get response from url returned by ```rest_url_for_rate(from_ccy, to_ccy)```
|
157
|
+
Above method should return exchange rate(Numeric type) between from_ccy and to_ccy. You can call ```rate_response(from_ccy, to_ccy)``` inside ```rate(from_ccy, to_ccy)``` to get response from url returned by ```rest_url_for_rate(from_ccy, to_ccy)```
|
155
158
|
|
156
159
|
Now you can directly use new rate provider added by you as an existing rate provider present in the gem. You can also use all the cofiguration present for th rate provider. If rate provider added by you require api_key, you can provide it as metioned in configurtion section.
|
157
160
|
If you want to use api_key inside you rate provider class, you can use class method api_key to access it.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CcyConvertor
|
2
|
+
class CurrencyLayer < CcyConvertor::RateProvider
|
3
|
+
class << self
|
4
|
+
def rest_url_for_rate_matrix(base_ccy)
|
5
|
+
"http://apilayer.net/api/live?access_key=#{api_key}&source=#{base_ccy || 'USD'}&format=1"
|
6
|
+
end
|
7
|
+
|
8
|
+
def rate_matrix(base_ccy = nil)
|
9
|
+
rates = rate_matrix_response(base_ccy)['quotes']
|
10
|
+
rates.inject({}) { |acc, (k, v)| acc[k[3, 3]] = v; acc }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -27,11 +27,11 @@ module CcyConvertor
|
|
27
27
|
cache_key = cache_key(request_url)
|
28
28
|
return cache.read(cache_key) if cache.exist?(cache_key)
|
29
29
|
response = HTTParty.get(request_url).parsed_response
|
30
|
-
|
30
|
+
cache.write(cache_key, response, expires_in: cache_duration)
|
31
31
|
response
|
32
32
|
end
|
33
33
|
|
34
|
-
def rate_matrix_response(base_ccy
|
34
|
+
def rate_matrix_response(base_ccy=nil)
|
35
35
|
response_hash(rest_url_for_rate_matrix(base_ccy))
|
36
36
|
end
|
37
37
|
|
data/lib/ccy_convertor.rb
CHANGED
@@ -14,7 +14,7 @@ require 'ccy_convertor/process_and_validate_option'
|
|
14
14
|
require 'ccy_convertor/rate_providers/rate_provider'
|
15
15
|
require 'ccy_convertor/rate_providers/yahoo_finance'
|
16
16
|
require 'ccy_convertor/rate_providers/open_exchange_rate'
|
17
|
-
require 'ccy_convertor/rate_providers/
|
17
|
+
require 'ccy_convertor/rate_providers/currency_layer'
|
18
18
|
|
19
19
|
module CcyConvertor
|
20
20
|
class << self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccy_convertor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rohan Pujari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,28 +42,28 @@ dependencies:
|
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: httparty
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: CcyConvertor provides live currency rate for various currencies and allows
|
@@ -89,7 +89,7 @@ files:
|
|
89
89
|
- lib/ccy_convertor/money.rb
|
90
90
|
- lib/ccy_convertor/process_and_validate_option.rb
|
91
91
|
- lib/ccy_convertor/rate_cache.rb
|
92
|
-
- lib/ccy_convertor/rate_providers/
|
92
|
+
- lib/ccy_convertor/rate_providers/currency_layer.rb
|
93
93
|
- lib/ccy_convertor/rate_providers/open_exchange_rate.rb
|
94
94
|
- lib/ccy_convertor/rate_providers/rate_provider.rb
|
95
95
|
- lib/ccy_convertor/rate_providers/yahoo_finance.rb
|
@@ -104,19 +104,20 @@ require_paths:
|
|
104
104
|
- lib
|
105
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- -
|
112
|
+
- - '>='
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.4.8
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: CcyConvertor provides live currency rate for various currencies and allows
|
121
121
|
to convert money from one currency to other
|
122
122
|
test_files: []
|
123
|
+
has_rdoc:
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module CcyConvertor
|
2
|
-
class JSONRate < CcyConvertor::RateProvider
|
3
|
-
class << self
|
4
|
-
def rest_url_for_rate_matrix(base_ccy)
|
5
|
-
"http://jsonrates.com/get/?apiKey=#{api_key}&base=#{base_ccy || 'USD'}"
|
6
|
-
end
|
7
|
-
|
8
|
-
def rate_matrix(base_ccy = nil)
|
9
|
-
JSON.parse(rate_matrix_response(base_ccy))['rates']
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|