bank_exchange_api 1.0.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +62 -10
- data/lib/bank_exchange_api.rb +4 -0
- data/lib/bank_exchange_api/config.rb +1 -1
- data/lib/bank_exchange_api/param.rb +7 -5
- data/lib/bank_exchange_api/request/bank.rb +2 -2
- data/lib/bank_exchange_api/request/base.rb +30 -2
- data/lib/bank_exchange_api/response/base.rb +16 -0
- data/lib/bank_exchange_api/response/json.rb +9 -1
- data/lib/bank_exchange_api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddbe43ca58c823d4d48a69fa48a4110fe92aa742
|
4
|
+
data.tar.gz: 45fcb1be71365bb05dd71e4f4db62615a0c7ff38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49f85a0d17821e66ece907e32ea9c17f55ede337b8c28a8f346ca115588b21b6aa7d7d76e9db5038e950ba06d6dcc75ee41f09fbe8345095da318403312ddbb1
|
7
|
+
data.tar.gz: 22d2a030ad788101ce06fa2eb4687c4f45c8b24f18e899f587d8d9e63d5375d4d38ee44cdb26b1c545bd6aaf3d4bedeaef781dcef5e4bb3180bf8a805f353501
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
## 1.0.1
|
2
|
+
|
3
|
+
* REMOVALS
|
4
|
+
* Outdated param `countries` was renamed to `iso_to` in `@cli.bank`
|
5
|
+
* BUG FIXES
|
6
|
+
* Fix `instance variable is not initialized` warning
|
7
|
+
* ENHANCEMENTS
|
8
|
+
* Add pagination to some endpoints. Example: `@cli.rates{ |response| puts response.data }`
|
data/README.md
CHANGED
@@ -2,10 +2,16 @@
|
|
2
2
|
|
3
3
|
[](https://semaphoreci.com/shlima/bank_exchange_ruby_api) [](https://codeclimate.com/github/BankExchange/bank_exchange_ruby_api) [](https://gemnasium.com/BankExchange/bank_exchange_ruby_api)
|
4
4
|
|
5
|
-
|
5
|
+
## RUBY EXCHANGE RATES API
|
6
6
|
|
7
7
|
This is the Ruby API client for the BankExchange service. Please read the official documentation to get further information http://bank.exchange/documentation
|
8
8
|
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install bank_exchange_api
|
13
|
+
```
|
14
|
+
|
9
15
|
## Configuration
|
10
16
|
|
11
17
|
```ruby
|
@@ -28,7 +34,22 @@ This is the Ruby API client for the BankExchange service. Please read the offici
|
|
28
34
|
@cli.ping #=> true
|
29
35
|
```
|
30
36
|
|
31
|
-
##
|
37
|
+
## Response methods
|
38
|
+
```
|
39
|
+
request = @cli.banks(countries: ['US'])
|
40
|
+
response = request.json
|
41
|
+
|
42
|
+
response.data # root-data of the endpoint
|
43
|
+
response.body # whole response data
|
44
|
+
reponse.params # request params in response
|
45
|
+
response.pagination # pagination params
|
46
|
+
response.next_page_url # next page URL if resource is paginatable
|
47
|
+
response.paginatable? # if resource is paginatable and next page exists
|
48
|
+
response.not_paginatable?
|
49
|
+
response.success? #=> true if response status code is 2xx
|
50
|
+
```
|
51
|
+
|
52
|
+
## Banks list
|
32
53
|
|
33
54
|
```ruby
|
34
55
|
# @option countries [Array]
|
@@ -39,10 +60,6 @@ This is the Ruby API client for the BankExchange service. Please read the offici
|
|
39
60
|
response = request.json
|
40
61
|
```
|
41
62
|
|
42
|
-
```ruby
|
43
|
-
response.success? #=> true
|
44
|
-
```
|
45
|
-
|
46
63
|
```ruby
|
47
64
|
# @return [Hash]
|
48
65
|
response.params
|
@@ -65,15 +82,15 @@ This is the Ruby API client for the BankExchange service. Please read the offici
|
|
65
82
|
|
66
83
|
```ruby
|
67
84
|
# @param swift [String]
|
68
|
-
# @option
|
85
|
+
# @option iso_to [Array]
|
69
86
|
# @option date [Date,String]
|
70
87
|
# @option fallback_days [Integer]
|
71
|
-
response = @cli.bank("XXXXXXXX", date: Date.today,
|
88
|
+
response = @cli.bank("XXXXXXXX", date: Date.today, iso_to: ['EUR']).json
|
72
89
|
```
|
73
90
|
|
74
91
|
```ruby
|
75
92
|
response.params
|
76
|
-
{"swift"=>"XXXXXXXX", "
|
93
|
+
{"swift"=>"XXXXXXXX", "iso_to"=>["EUR"], "date"=>"2016-03-22", "fallback_days"=>5}
|
77
94
|
```
|
78
95
|
|
79
96
|
```ruby
|
@@ -83,7 +100,19 @@ This is the Ruby API client for the BankExchange service. Please read the offici
|
|
83
100
|
|
84
101
|
```ruby
|
85
102
|
response.body
|
86
|
-
{"params"=>{"swift"=>"XXXXXXXX", "
|
103
|
+
{"params"=>{"swift"=>"XXXXXXXX", "iso_to"=>["EUR"], "date"=>"2016-03-22", "fallback_days"=>4}, "bank"=>{"swift"=>"XXXXXXXX", "name"=>"Board of Governors of the Federal Reserve System", "country"=>"US", "currency"=>"USD", "website"=>"http://www.federalreserve.gov"}, "rates"=>[{"iso_from"=>"USD", "iso_to"=>"EUR", "rate"=>0.885582713425434, "inverse_rate"=>1.1292, "date"=>"2016-03-18"}]}
|
104
|
+
```
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
response.pagination
|
108
|
+
{"current_page"=>1, "last_page"=>true, "per_page"=>200, "next_page_url"=>nil}
|
109
|
+
```
|
110
|
+
|
111
|
+
:warning: Please use pagination by providing a block. Otherwise first page returns.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
data = []
|
115
|
+
@cli.bank("XXXXXXXX").json{ |response| data.concat(response.data) }
|
87
116
|
```
|
88
117
|
|
89
118
|
## Rates list
|
@@ -112,6 +141,18 @@ This is the Ruby API client for the BankExchange service. Please read the offici
|
|
112
141
|
{"params"=>{"date"=>"2016-03-24", "swift"=>[], "iso_from"=>["BYR"], "iso_to"=>["USD"], "fallback_days"=>5}, "rates"=>[{"iso_from"=>"BYR", "iso_to"=>"USD", "rate"=>4.96007142502852e-05, "inverse_rate"=>20161.0, "swift"=>"NBRBBY2X", "date"=>"2016-03-24"}]}
|
113
142
|
```
|
114
143
|
|
144
|
+
```ruby
|
145
|
+
response.pagination
|
146
|
+
{"current_page"=>1, "last_page"=>false, "per_page"=>200, "next_page_url"=>"http://api.bank.exchange/rates?iso_from=&iso_to=&page=2&swift="}
|
147
|
+
```
|
148
|
+
|
149
|
+
:warning: Please use pagination by providing a block. Otherwise first page returns.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
data = []
|
153
|
+
@cli.rates.json{ |response| data.concat(response.data) }
|
154
|
+
```
|
155
|
+
|
115
156
|
## Rate overview
|
116
157
|
|
117
158
|
```ruby
|
@@ -138,3 +179,14 @@ This is the Ruby API client for the BankExchange service. Please read the offici
|
|
138
179
|
{"params"=>{"iso_code"=>"BYR", "date"=>"2016-03-25", "iso_from"=>["BYR"], "iso_to"=>["RUB"], "fallback_days"=>5}, "rates"=>[{"iso_from"=>"BYR", "iso_to"=>"RUB", "rate"=>0.00340193910529002, "inverse_rate"=>293.95, "swift"=>"NBRBBY2X", "date"=>"2016-03-25"}]}
|
139
180
|
```
|
140
181
|
|
182
|
+
```ruby
|
183
|
+
response.pagination
|
184
|
+
{"current_page"=>1, "last_page"=>true, "per_page"=>200, "next_page_url"=>nil}
|
185
|
+
```
|
186
|
+
|
187
|
+
:warning: Please use pagination by providing a block. Otherwise first page returns.
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
data = []
|
191
|
+
@cli.rate('BYR').json{ |response| data.concat(response.data) }
|
192
|
+
```
|
data/lib/bank_exchange_api.rb
CHANGED
@@ -8,16 +8,18 @@ module BankExchangeApi
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def #{name}
|
11
|
+
value = @#{name} if defined?(@#{name})
|
12
|
+
|
11
13
|
@_#{name}_ ||= case #{klass}.name
|
12
14
|
when 'Array'
|
13
|
-
Array(
|
15
|
+
Array(value)
|
14
16
|
when 'String'
|
15
|
-
String(
|
17
|
+
String(value) if value
|
16
18
|
when 'Integer'
|
17
|
-
Integer(
|
19
|
+
Integer(value) if value
|
18
20
|
when 'Date'
|
19
|
-
if
|
20
|
-
|
21
|
+
if value
|
22
|
+
value.is_a?(Date) ? value : Date.parse(value.to_s)
|
21
23
|
end
|
22
24
|
else
|
23
25
|
raise UnsupportedParamClass, "Provide #{klass} class processing"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module BankExchangeApi::Request
|
2
2
|
class Bank < Base
|
3
3
|
param :swift, String
|
4
|
-
param :
|
4
|
+
param :iso_to, Array
|
5
5
|
param :date, Date
|
6
6
|
param :fallback_days, Integer
|
7
7
|
|
@@ -11,7 +11,7 @@ module BankExchangeApi::Request
|
|
11
11
|
|
12
12
|
def params
|
13
13
|
{
|
14
|
-
|
14
|
+
iso_to: iso_to.join(','),
|
15
15
|
date: date,
|
16
16
|
fallback_days: fallback_days,
|
17
17
|
}
|
@@ -18,8 +18,14 @@ module BankExchangeApi
|
|
18
18
|
cli.connection.get(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
def json(root: nil)
|
22
|
-
BankExchangeApi::Response::Json.new(get(
|
21
|
+
def json(root: nil, &block)
|
22
|
+
paginator = -> (uri=query) { BankExchangeApi::Response::Json.new(get(uri), root: root) }
|
23
|
+
|
24
|
+
if block_given?
|
25
|
+
paginate(paginator) { |response| yield(response) }
|
26
|
+
else
|
27
|
+
paginate(paginator)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
def params
|
@@ -29,6 +35,28 @@ module BankExchangeApi
|
|
29
35
|
def endpoint
|
30
36
|
raise NotImplementedError, __method__
|
31
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# @param paginator [Proc] should accept next page uri
|
42
|
+
# @block if not given - first response return
|
43
|
+
def paginate(paginator)
|
44
|
+
response = paginator.call
|
45
|
+
|
46
|
+
unless block_given?
|
47
|
+
if response.paginatable?
|
48
|
+
cli.warn('Requested resource contains a pagination, please provide a block to process each page. Initial page returned.')
|
49
|
+
end
|
50
|
+
return response
|
51
|
+
end
|
52
|
+
|
53
|
+
yield(response)
|
54
|
+
|
55
|
+
while response.paginatable? do
|
56
|
+
response = paginator.call(response.next_page_url)
|
57
|
+
yield(response)
|
58
|
+
end
|
59
|
+
end
|
32
60
|
end
|
33
61
|
end
|
34
62
|
end
|
@@ -32,5 +32,21 @@ module BankExchangeApi::Response
|
|
32
32
|
def body
|
33
33
|
raise NotImplementedError, __method__
|
34
34
|
end
|
35
|
+
|
36
|
+
def pagination
|
37
|
+
raise NotImplementedError, __method__
|
38
|
+
end
|
39
|
+
|
40
|
+
def next_page_url
|
41
|
+
raise NotImplementedError, __method__
|
42
|
+
end
|
43
|
+
|
44
|
+
def paginatable?
|
45
|
+
!next_page_url.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def not_paginatable?
|
49
|
+
!paginatable?
|
50
|
+
end
|
35
51
|
end
|
36
52
|
end
|
@@ -15,12 +15,20 @@ module BankExchangeApi::Response
|
|
15
15
|
body.fetch('params', {})
|
16
16
|
end
|
17
17
|
|
18
|
+
def pagination
|
19
|
+
body.fetch('pagination', {})
|
20
|
+
end
|
21
|
+
|
22
|
+
def next_page_url
|
23
|
+
pagination['next_page_url']
|
24
|
+
end
|
25
|
+
|
18
26
|
def data
|
19
27
|
root ? body[root.to_s] : body
|
20
28
|
end
|
21
29
|
|
22
30
|
def inspect
|
23
|
-
|
31
|
+
body
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank_exchange_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksandr Shylau
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- ".env.example"
|
119
119
|
- ".gitignore"
|
120
120
|
- ".rspec"
|
121
|
+
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|