BnmAPI 0.1.1 → 0.2.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
  SHA256:
3
- metadata.gz: ce36e8209b58c4a626102148db4881260685bc80474e047d2a5d208ca11f6d38
4
- data.tar.gz: d03fd8557fa540500ddbadb94f52dddb73eb18d997285498091d5158c87d62fc
3
+ metadata.gz: 1db572c75b9ac8f3c08255a25fe154b2d344851c12b57526ada5d0677de94c71
4
+ data.tar.gz: ae6ef3c73bd15f81899785ce867f7311e3daa96bd7d24df4453c9f1513d7a0f2
5
5
  SHA512:
6
- metadata.gz: 2ebd4debd931b28525aeb87a4634e1d595d4f6349ad6258d7d5e7842be6c7401de6b9597e6dd7c1be55ff1fe008b5348636d2b4b01f1d1a441c11eba8ca6c3ce
7
- data.tar.gz: e5394be3062c4485cb85e7e055b2907137b967d17bbb952b10af0c1141e9871f6d11a5faf4ecb495b14a92cff7ced9e7f6efe22f39000e788a76ff19621af11e
6
+ metadata.gz: 82b24c23630970776788e7a5856ba1d96e0b5f4bbc6dcbe33bf0d5a191a65bcbc89a7342442217b88ee79caa939dfab265f964aa25ecae2a372f1b51da24236c
7
+ data.tar.gz: 1886ac4524a0f5ea6d725a4ca263dcfffdba7cce8617aec69b094badec05309751de74bbdcebcc9245fbbea8c7057671cb45e1d7413d7e276fb25259dd89f10a
@@ -1,7 +1,17 @@
1
- ---
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=eb717534daf85909a03c990170e4dbd849d1eef16cc9cc804cfa912b284df872
2
4
  sudo: false
3
5
  language: ruby
4
6
  cache: bundler
5
7
  rvm:
6
8
  - 2.6.1
7
9
  before_install: gem install bundler -v 1.17.2
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
14
+ script:
15
+ - bundle exec rspec
16
+ after_script:
17
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,17 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- BnmAPI (0.1.1)
4
+ BnmAPI (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  addressable (2.6.0)
10
10
  public_suffix (>= 2.0.2, < 4.0)
11
+ ansi (1.5.0)
11
12
  crack (0.4.3)
12
13
  safe_yaml (~> 1.0.0)
13
14
  diff-lcs (1.3)
15
+ docile (1.3.1)
14
16
  hashdiff (0.3.8)
17
+ hirb (0.7.3)
18
+ json (2.2.0)
15
19
  public_suffix (3.0.3)
16
20
  rake (10.5.0)
17
21
  rspec (3.8.0)
@@ -28,6 +32,15 @@ GEM
28
32
  rspec-support (~> 3.8.0)
29
33
  rspec-support (3.8.0)
30
34
  safe_yaml (1.0.5)
35
+ simplecov (0.16.1)
36
+ docile (~> 1.1)
37
+ json (>= 1.8, < 3)
38
+ simplecov-html (~> 0.10.0)
39
+ simplecov-console (0.4.2)
40
+ ansi
41
+ hirb
42
+ simplecov
43
+ simplecov-html (0.10.2)
31
44
  vcr (4.0.0)
32
45
  webmock (3.5.1)
33
46
  addressable (>= 2.3.6)
@@ -42,6 +55,8 @@ DEPENDENCIES
42
55
  bundler (~> 1.17)
43
56
  rake (~> 10.0)
44
57
  rspec (~> 3.0)
58
+ simplecov
59
+ simplecov-console
45
60
  vcr
46
61
  webmock
47
62
 
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Bnmapi
2
2
 
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/b6e071e2dc07ea011a62/maintainability)](https://codeclimate.com/github/jibone/bnmapi/maintainability)
4
+ [![Test
5
+ Coverage](https://api.codeclimate.com/v1/badges/b6e071e2dc07ea011a62/test_coverage)](https://codeclimate.com/github/jibone/bnmapi/test_coverage)
6
+
3
7
  Ruby wrapper for Bank Negara Malaysia Open API. Details and API disclaimer can
4
8
  be found here [BNM Open API](https://api.bnm.gov.my/portal)
5
9
 
6
- _Note:_ This gem is still in early devvelopment stages and not ready for use.
10
+ _Note:_ This gem is still in early development stages and not ready for use.
7
11
 
8
12
  ## Installation
9
13
 
@@ -68,7 +72,7 @@ details.
68
72
  collection = BnmAPI::BaseRate.latest
69
73
 
70
74
  collection.size
71
- # 35 (number if bank in the response like)
75
+ # 35 (number of banks that the response return)
72
76
 
73
77
  puts collection[0].bank_code
74
78
  # BKKBMYKL
@@ -124,14 +128,87 @@ puts bank.last_updated.class
124
128
 
125
129
  puts bank.last_updated.iso8601
126
130
  # 2019-01-18T19:25:02+00:00
131
+ # it returns and DateTime object
127
132
 
128
133
  puts bank.effective_date.class
129
134
  # Date
130
135
 
131
136
  puts bank.effective_date.iso8601
132
137
  # 2019-04-05
138
+ # it returns and Date object
139
+ ```
140
+
141
+ ### Daily FX Turnover
142
+
143
+ Daily foreign exchange turnover for all currencies including interbank and
144
+ customer deals
145
+
146
+ #### (latest)
147
+ https://api.bnm.gov.my/portal#operation/DFXTLatest
148
+
149
+ Get the latest FX turnover.
150
+
151
+ ```ruby
152
+ fx_turn_over = BnmAPI::DailyFXTurnover.latest
153
+
154
+ puts fx_turn_over.date.iso8601
155
+ # 2019-04-05
156
+ # it returns and Date object
157
+
158
+ puts fx_turn_over.total_sum
159
+ # 11.95
160
+
161
+ puts fx_turn_over.last_updated
162
+ # 2019-01-18T19:25:02+00:00
163
+ # it returns and DateTime object
164
+ ```
165
+
166
+ #### (by date)
167
+ https://api.bnm.gov.my/portal#operation/DFXTDate
168
+
169
+ Get daily FX turnover for the date.
170
+
171
+ ```ruby
172
+ # by an initialize Date object
173
+ date = Date.parse('10-4-2019')
174
+ fx_turn_over = BnmAPI::DailyFXTurnover.by_date(date)
175
+
176
+ # from a string that can be parse to a date
177
+ fx_turn_over = BnmAPI::DailyFXTurnover.by_date('10-4-2019')
178
+
179
+ puts fx_turn_over.date.iso8601
180
+ # 2019-04-05
181
+ # it returns and Date object
182
+
183
+ puts fx_turn_over.total_sum
184
+ # 11.95
185
+
186
+ puts fx_turn_over.last_updated
187
+ # 2019-01-18T19:25:02+00:00
188
+ # it returns and DateTime object
189
+ ```
190
+
191
+ #### (by year and month)
192
+ https://api.bnm.gov.my/portal#operation/DFXTMonth
193
+
194
+ Get the list of daily FX turnover for the month
195
+
196
+ ```ruby
197
+ fx_collection = BnmAPI::DailyFXTurnover.by_month(year: 2019, month: 4)
198
+
199
+ puts fx_collection[0].date.iso8601
200
+ # 2019-04-05
201
+ # it returns and Date object
202
+
203
+ puts fx_collection[0].total_sum
204
+ # 11.95
205
+
206
+ puts fx_collection[0].last_updated
207
+ # 2019-01-18T19:25:02+00:00
208
+ # it returns and DateTime object
133
209
  ```
134
210
 
211
+
135
212
  ## Development
136
213
 
137
214
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -24,9 +24,11 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.17"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency 'bundler', "~> 1.17"
28
+ spec.add_development_dependency 'rake', "~> 10.0"
29
+ spec.add_development_dependency 'rspec', "~> 3.0"
30
30
  spec.add_development_dependency 'webmock'
31
31
  spec.add_development_dependency 'vcr'
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency 'simplecov-console'
32
34
  end
@@ -1,9 +1,12 @@
1
1
  require 'bnmapi/version'
2
2
  require 'bnmapi/http/client'
3
3
  require 'bnmapi/data/bank_base_rate'
4
+ require 'bnmapi/data/fx_turnover'
4
5
  require 'bnmapi/error/invalid_bank_code'
6
+ require 'bnmapi/error/no_fx_turnover'
5
7
  require 'bnmapi/welcome'
6
8
  require 'bnmapi/base_rate'
9
+ require 'bnmapi/daily_fx_turnover'
7
10
 
8
11
  module BnmAPI
9
12
  # Your code goes here...
@@ -0,0 +1,54 @@
1
+ module BnmAPI
2
+ class DailyFXTurnover
3
+ ENDPOINT = '/fx-turn-over'
4
+
5
+ def self.latest
6
+ res = fetch_data(ENDPOINT)
7
+ present_data(res['data'], res['meta']['last_updated'])
8
+ end
9
+
10
+ def self.by_date(date)
11
+ date_string = if date.is_a?(Date)
12
+ "#{date.year}-#{date.month}-#{date.day}"
13
+ else
14
+ d = Date.parse(date)
15
+ "#{d.year}-#{d.month}-#{d.day}"
16
+ end
17
+
18
+ res = fetch_data(ENDPOINT + '/date/' + date_string)
19
+ present_data(res['data'], res['meta']['last_updated'])
20
+ end
21
+
22
+ def self.by_month(year:, month:)
23
+ res = fetch_data("#{ENDPOINT}/year/#{year}/month/#{month}")
24
+
25
+ collection = []
26
+ res['data'].each do |data|
27
+ collection << present_data(data, res['meta']['last_updated'])
28
+ end
29
+
30
+ collection
31
+ end
32
+
33
+ private
34
+
35
+ def self.fetch_data(endpoint)
36
+ http = BnmAPI::HTTP::Client.new(endpoint: endpoint)
37
+ res = http.request
38
+
39
+ if res.code == '404'
40
+ raise BnmAPI::Error::NoFXTurnover.new(endpoint: endpoint)
41
+ end
42
+
43
+ JSON.parse(res.read_body)
44
+ end
45
+
46
+ def self.present_data(data, last_updated)
47
+ BnmAPI::Data::FXTurnover.new(
48
+ data['total_sum'],
49
+ data['date'],
50
+ last_updated
51
+ )
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,16 @@
1
+ module BnmAPI::Data
2
+ FXTurnover = Struct.new(
3
+ :total_sum,
4
+ :date_data,
5
+ :last_updated_data
6
+ ) do
7
+
8
+ def last_updated
9
+ DateTime.parse(last_updated_data)
10
+ end
11
+
12
+ def date
13
+ Date.parse(date_data)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module BnmAPI::Error
2
+ class NoFXTurnover < StandardError
3
+ attr_reader :date
4
+
5
+ def initialize(msg: 'No fx turnover on date. endpoint: ', endpoint:)
6
+ @date = date
7
+ super(msg + endpoint)
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module BnmAPI
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BnmAPI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - J Shamsul Bahri (jibone))
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2019-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov-console
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description:
84
112
  email:
85
113
  - jibone@gmail.com
@@ -103,8 +131,11 @@ files:
103
131
  - bnmapi.gemspec
104
132
  - lib/bnmapi.rb
105
133
  - lib/bnmapi/base_rate.rb
134
+ - lib/bnmapi/daily_fx_turnover.rb
106
135
  - lib/bnmapi/data/bank_base_rate.rb
136
+ - lib/bnmapi/data/fx_turnover.rb
107
137
  - lib/bnmapi/error/invalid_bank_code.rb
138
+ - lib/bnmapi/error/no_fx_turnover.rb
108
139
  - lib/bnmapi/http/client.rb
109
140
  - lib/bnmapi/version.rb
110
141
  - lib/bnmapi/welcome.rb