bca_statement 0.1.0 → 0.1.2

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
  SHA1:
3
- metadata.gz: 7321548490c217e03c0cabc262c0a37d3c9a5aa1
4
- data.tar.gz: 6ee866a8ccae3148baf708ee1263290467a29dce
3
+ metadata.gz: 7b48749538c590a27f510695293e095a234892b7
4
+ data.tar.gz: f2643a81da65a74842d8c032b6612c4c8f48d516
5
5
  SHA512:
6
- metadata.gz: 4122f71fa5a099ca96e145bea46bd21cdb0ae212e005487933abe25950bde3888c7baf4b56b228fe27739ea28ea3fab6df6f819a0e151d0c10f6a3028a75a156
7
- data.tar.gz: 3d56d6dd16ef13444ba700f2c09ef896329117b4f45b4e5aa857df8a20106ac3bc26c2c2f8c9b2bfc014810d53077a18191597206193da11f763d4c17b8162e1
6
+ metadata.gz: 267c0362aa3ce57e1d7c31a897e480dc5df38cc7610f6531f2581b4869271935b106f05547a0902ecd8aa78ecf1282a1da3a979f03e9fcf6ed54e963250e24b5
7
+ data.tar.gz: a5d3425bab964ff0488a8faeeb00af4ea7e9c4ddb660754687740ae6fc2ea4a37a1a5a9ee46dcd19bb12bc7bc1a6a1592746a86abeb01c4680b7e1f67c1fd319
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .byebug_history
13
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,14 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bca_statement (0.1.0)
5
- model_attribute
6
- rest-client
4
+ bca_statement (0.1.1)
5
+ model_attribute (~> 3.2.0)
6
+ rest-client (~> 2.0.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- byebug (10.0.2)
12
11
  coderay (1.1.2)
13
12
  diff-lcs (1.3)
14
13
  domain_name (0.5.20180417)
@@ -52,7 +51,6 @@ PLATFORMS
52
51
  DEPENDENCIES
53
52
  bca_statement!
54
53
  bundler (~> 1.16)
55
- byebug
56
54
  pry (~> 0.9)
57
55
  rake (~> 10.0)
58
56
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/bca_statement.svg)](https://badge.fury.io/rb/bca_statement)
2
+
1
3
  # BcaStatement
2
4
 
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bca_statement`. To experiment with that code, run `bin/console` for an interactive prompt.
@@ -20,9 +22,33 @@ Or install it yourself as:
20
22
 
21
23
  $ gem install bca_statement
22
24
 
25
+ ## Configuration
26
+
27
+ The library can be initialized with a Rails initializer containing similar:
28
+ ```ruby
29
+ BcaStatement.configure do |config|
30
+ config.base_url = 'your bca api endpoint'
31
+ config.client_id = 'your client id'
32
+ config.client_secret = 'your client secret'
33
+ config.api_key = 'your api key'
34
+ config.api_secret = 'your api secret'
35
+ config.domain = 'your domain'
36
+ end
37
+ ```
38
+
23
39
  ## Usage
24
40
 
25
- TODO: Write usage instructions here
41
+ ### get statement
42
+ To get list of statement from 17 Aug 2018 - 20 Aug 2018
43
+ ```ruby
44
+ bca_statement = BcaStatement::Client.new
45
+ bca_statement.get_statement('2018-08-17', '2018-08-20')
46
+ ```
47
+
48
+ To Get Balance Details
49
+ ```ruby
50
+ bca_statement.balance
51
+ ```
26
52
 
27
53
  ## Development
28
54
 
@@ -32,7 +58,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
58
 
33
59
  ## Contributing
34
60
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bca_statement. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andymarthin/bca_statement. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
62
 
37
63
  ## License
38
64
 
@@ -40,4 +66,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
66
 
41
67
  ## Code of Conduct
42
68
 
43
- Everyone interacting in the BcaStatement project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bca_statement/blob/master/CODE_OF_CONDUCT.md).
69
+ Everyone interacting in the BcaStatement project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/andymarthin/bca_statement/blob/master/CODE_OF_CONDUCT.md).
@@ -29,9 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rake", "~> 10.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
  spec.add_development_dependency 'pry', '~> 0.9'
32
- spec.add_development_dependency 'byebug'
33
32
 
34
- spec.add_dependency 'model_attribute'
35
- spec.add_dependency 'rest-client'
33
+ spec.add_dependency 'model_attribute', "~> 3.2.0"
34
+ spec.add_dependency 'rest-client', "~> 2.0.2"
36
35
 
37
36
  end
@@ -11,32 +11,38 @@ module BcaStatement
11
11
  attr_reader :access_token
12
12
 
13
13
  def initialize
14
- @timestamp = Time.now.iso8601(3)
15
14
  @base_url = BcaStatement.configuration.base_url
15
+ @corporate_id = BcaStatement.configuration.corporate_id
16
+ @account_number = BcaStatement.configuration.account_number
17
+ @api_key = BcaStatement.configuration.api_key
18
+ @domain = BcaStatement.configuration.domain
19
+
16
20
  authentication
17
21
  end
18
22
 
19
- def get_statement(start_date = '2016-08-29', end_date = '2016-09-01')
23
+ # Get your BCA Bisnis account statement for a period up to 31 days.
24
+ def get_statement(start_date = '2016-08-29', end_date = '2016-09-01')
25
+ return nil unless @access_token
26
+
27
+ @timestamp = Time.now.iso8601(3)
20
28
  @start_date = start_date.to_s
21
29
  @end_date = end_date.to_s
22
30
  @path = "/banking/v3/corporates/"
23
- @corporate_id = BcaStatement.configuration.corporate_id
24
- @account_number = BcaStatement.configuration.account_number
25
31
  @relative_url = "#{@path}#{@corporate_id}/accounts/#{@account_number}/statements?EndDate=#{@end_date}&StartDate=#{@start_date}"
26
- response = RestClient.get("#{@base_url}#{@relative_url}",
32
+ begin
33
+ response = RestClient.get("#{@base_url}#{@relative_url}",
27
34
  "Content-Type": 'application/json',
28
35
  "Authorization": "Bearer #{@access_token}",
29
- "Origin": BcaStatement.configuration.domain,
30
- "X-BCA-Key": BcaStatement.configuration.api_key,
36
+ "Origin": @domain,
37
+ "X-BCA-Key": @api_key,
31
38
  "X-BCA-Timestamp": @timestamp,
32
39
  "X-BCA-Signature": signature)
33
- if response.code.eql?(200)
34
40
  elements = JSON.parse response.body
35
41
  statements = []
36
42
 
37
43
  elements['Data'].each do |element|
38
44
  year = Date.parse(@start_date).strftime('%m').to_i.eql?(12) ? Date.parse(@start_date).strftime('%Y') : Date.parse(@end_date).strftime('%Y')
39
- date = "#{element['TransactionDate']}/#{year}"
45
+ date = element['TransactionDate'].eql?("PEND") ? element['TransactionDate'] : "#{element['TransactionDate']}/#{year}"
40
46
  attribute = {
41
47
  date: date,
42
48
  brance_code: element['BranchCode'],
@@ -48,10 +54,46 @@ module BcaStatement
48
54
  statements << BcaStatement::Entities::Statement.new(attribute)
49
55
  end
50
56
  statements
51
- else
52
- return
53
- end
57
+ rescue RestClient::ExceptionWithResponse => err
58
+ return nil
59
+ end
60
+ end
54
61
 
62
+ # Get your BCA Bisnis account balance information
63
+ def balance
64
+ return nil unless @access_token
65
+
66
+ begin
67
+ @timestamp = Time.now.iso8601(3)
68
+ @relative_url = "/banking/v3/corporates/#{@corporate_id}/accounts/#{@account_number}"
69
+ response = RestClient.get("#{@base_url}#{@relative_url}",
70
+ "Content-Type": 'application/json',
71
+ "Authorization": "Bearer #{@access_token}",
72
+ "Origin": @domain,
73
+ "X-BCA-Key": @api_key,
74
+ "X-BCA-Timestamp": @timestamp,
75
+ "X-BCA-Signature": signature)
76
+
77
+ data = JSON.parse response.body
78
+ if account_detail_success = data['AccountDetailDataSuccess']
79
+ detail = account_detail_success.first
80
+ attribute = {
81
+ account_number: detail['AccountNumber'],
82
+ currency: detail['Currency'],
83
+ balance: detail['Balance'].to_f,
84
+ available_balance: detail['AvailableBalance'].to_f,
85
+ float_amount: detail['FloatAmount'].to_f,
86
+ hold_amount: detail['HoldAmount'].to_f
87
+ plafon: detail['Plafon'].to_f
88
+ }
89
+ BcaStatement::Entities::Balance.new(attribute)
90
+
91
+ else
92
+ return nil
93
+ end
94
+ rescue RestClient::ExceptionWithResponse => err
95
+ return nil
96
+ end
55
97
  end
56
98
 
57
99
  private
@@ -64,16 +106,18 @@ module BcaStatement
64
106
 
65
107
  def authentication
66
108
  # authentication to get access token
67
- url = "#{@base_url}/api/oauth/token"
68
- credential = "#{BcaStatement.configuration.client_id}:#{BcaStatement.configuration.client_secret}"
69
- authorization = { Authorization: "Basic #{Base64.strict_encode64(credential)}" }
70
- payload = { grant_type: 'client_credentials' }
109
+ begin
110
+ url = "#{@base_url}/api/oauth/token"
111
+ credential = "#{BcaStatement.configuration.client_id}:#{BcaStatement.configuration.client_secret}"
112
+ authorization = { Authorization: "Basic #{Base64.strict_encode64(credential)}" }
113
+ payload = { grant_type: 'client_credentials' }
71
114
 
72
- response = RestClient.post(url, payload, authorization)
73
- if response.code.eql?(200)
115
+ response = RestClient.post(url, payload, authorization)
74
116
  body = JSON.parse response.body
75
117
  @access_token = body['access_token']
76
- end
118
+ rescue RestClient::ExceptionWithResponse => err
119
+ err.response
120
+ end
77
121
  end
78
122
  end
79
123
  end
@@ -0,0 +1,19 @@
1
+ module BcaStatement
2
+ module Entities
3
+ class Balance < Base
4
+ extend ModelAttribute
5
+ attribute :account_number, :string
6
+ attribute :currency, :string
7
+ attribute :balance, :float
8
+ attribute :available_balance, :float
9
+ attribute :float_amount, :float
10
+ attribute :hold_amount, :float
11
+ attribute :plafon, :float
12
+
13
+ def initialize(attributes = {})
14
+ set_attributes(attributes)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -4,6 +4,7 @@ module BcaStatement
4
4
  module Entities
5
5
  class Base
6
6
  require "bca_statement/entities/statement.rb"
7
+ require "bca_statement/entities/balance.rb"
7
8
  end
8
9
  end
9
10
  end
@@ -1,3 +1,3 @@
1
1
  module BcaStatement
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bca_statement
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Marthin
@@ -66,48 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
- - !ruby/object:Gem::Dependency
70
- name: byebug
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: model_attribute
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ">="
73
+ - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: 3.2.0
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ">="
80
+ - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: 3.2.0
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rest-client
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ">="
87
+ - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '0'
89
+ version: 2.0.2
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ">="
94
+ - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: 2.0.2
111
97
  description: simple and easy to use wrapper for BCA API
112
98
  email:
113
99
  - mr.andymarthin@gmail.com
@@ -130,6 +116,7 @@ files:
130
116
  - lib/bca_statement.rb
131
117
  - lib/bca_statement/client.rb
132
118
  - lib/bca_statement/configuration.rb
119
+ - lib/bca_statement/entities/balance.rb
133
120
  - lib/bca_statement/entities/base.rb
134
121
  - lib/bca_statement/entities/statement.rb
135
122
  - lib/bca_statement/error.rb