afterbanks-api-ruby 0.3.4 → 0.4.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: 47ce0303d43a61ed4dbb9995e830c150b9ce17381680d6d60c0ca4fb3c57c18a
4
- data.tar.gz: 0b3809056462a943e2aef44c2046686a244c282714f12f8f2fbbcfaf98610260
3
+ metadata.gz: 22ea53955debb94c87dcb7534c8be33518ec8e1e4800794e53fd871fdc819dac
4
+ data.tar.gz: af6ea1904f773515c156c8af3d920b683ea207d6432c5bfda4b729aa81f9d199
5
5
  SHA512:
6
- metadata.gz: 58b5066534be42b43d178b48f2b601f11cee1f7ebf57d481a68536c904f88db7ecf735200f33bcafea85e280c9b165adbbe5881c7a71030584666dfb2ec073ac
7
- data.tar.gz: 7a17bfa456463b898ceace9a0fae98b2fd4d885a339b4924116128d2b8a8c57884a11d8a230dd6c7765bef6f52d7b72ea453d68be111ac430ebe506c4ab721bb
6
+ metadata.gz: 9b890219799117cee50690a67c9ead8b49f14b84a40b36d569c62847a91683a0d5d0d929ac9536f3ac07d0531d7b31d98709cc0273032360c2733c34f34430d5
7
+ data.tar.gz: 8e975d6acef0726e98d7245ed0f40e40a4c7e56bf12f91ca6ec7092122446eb84eb515428c28408d2231872a26695d7d68c6c2677203146c9db59f67a2952694
data/.circleci/config.yml CHANGED
@@ -4,7 +4,7 @@ executors:
4
4
  gem-executor:
5
5
  working_directory: ~/tmp/gem
6
6
  docker:
7
- - image: circleci/ruby:2.4.1
7
+ - image: circleci/ruby:2.7.5
8
8
  environment:
9
9
  TZ: "Europe/Madrid"
10
10
 
@@ -16,7 +16,7 @@ jobs:
16
16
 
17
17
  - run:
18
18
  name: Update bundler
19
- command: gem install bundler -v 1.17.3
19
+ command: gem install bundler -v 2.2.25
20
20
 
21
21
  - restore_cache:
22
22
  keys:
@@ -34,6 +34,10 @@ jobs:
34
34
  name: Run rspec
35
35
  command: bundle exec rspec spec/
36
36
 
37
+ - run:
38
+ name: Run Rubocop
39
+ command: bundle exec rubocop
40
+
37
41
  workflows:
38
42
  build-test-gem:
39
43
  jobs:
data/.rubocop.yml ADDED
@@ -0,0 +1,45 @@
1
+ inherit_from: .rubocop_exclusions.yml
2
+
3
+ # General configuration
4
+ AllCops:
5
+ DisabledByDefault: true
6
+ Include:
7
+ - 'lib/**/*.rb'
8
+ - 'spec/**/*.rb'
9
+ NewCops: enable
10
+ SuggestExtensions: false
11
+ TargetRubyVersion: 2.7.5
12
+
13
+ # Explicit configuration
14
+ Bundler:
15
+ Enabled: true
16
+
17
+ Lint:
18
+ Enabled: true
19
+
20
+ Layout:
21
+ Enabled: true
22
+
23
+ Layout/BlockAlignment:
24
+ EnforcedStyleAlignWith: start_of_block
25
+
26
+ Layout/HashAlignment:
27
+ AllowMultipleStyles: true
28
+ EnforcedHashRocketStyle: table
29
+ EnforcedColonStyle: table
30
+
31
+ Layout/MultilineMethodCallIndentation:
32
+ Enabled: true
33
+ EnforcedStyle: indented_relative_to_receiver
34
+
35
+ Security:
36
+ Enabled: true
37
+
38
+ Style/CollectionMethods:
39
+ Enabled: true
40
+ PreferredMethods:
41
+ inject: "inject"
42
+ collect: "map"
43
+
44
+ Style/Documentation:
45
+ Enabled: false
@@ -0,0 +1,28 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-09-30 09:45:27 UTC using RuboCop version 1.36.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ Security/MarshalLoad:
11
+ Exclude:
12
+ - 'spec/afterbanks/resources/account_spec.rb'
13
+ - 'spec/afterbanks/resources/bank_spec.rb'
14
+ - 'spec/afterbanks/resources/transaction_spec.rb'
15
+ - 'spec/afterbanks/resources/user_spec.rb'
16
+
17
+ # Offense count: 1
18
+ # This cop supports safe autocorrection (--autocorrect).
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
20
+ # URISchemes: http, https
21
+ Layout/LineLength:
22
+ Max: 149
23
+
24
+ # Offense count: 2
25
+ Lint/MissingSuper:
26
+ Exclude:
27
+ - 'lib/afterbanks/collection.rb'
28
+ - 'lib/afterbanks/error.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- afterbanks-api-ruby (0.3.4)
4
+ afterbanks-api-ruby (0.4.0)
5
5
  rest-client (~> 2.0.2)
6
6
 
7
7
  GEM
@@ -9,6 +9,7 @@ GEM
9
9
  specs:
10
10
  addressable (2.8.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
12
13
  crack (0.4.3)
13
14
  safe_yaml (~> 1.0.0)
14
15
  diff-lcs (1.3)
@@ -17,16 +18,23 @@ GEM
17
18
  hashdiff (1.0.0)
18
19
  http-cookie (1.0.4)
19
20
  domain_name (~> 0.5)
21
+ json (2.6.2)
20
22
  mime-types (3.3.1)
21
23
  mime-types-data (~> 3.2015)
22
24
  mime-types-data (3.2021.0704)
23
25
  netrc (0.11.0)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.1)
28
+ ast (~> 2.4.1)
24
29
  public_suffix (4.0.6)
30
+ rainbow (3.1.1)
25
31
  rake (13.0.1)
32
+ regexp_parser (2.6.0)
26
33
  rest-client (2.0.2)
27
34
  http-cookie (>= 1.0.2, < 2.0)
28
35
  mime-types (>= 1.16, < 4.0)
29
36
  netrc (~> 0.8)
37
+ rexml (3.2.5)
30
38
  rspec (3.9.0)
31
39
  rspec-core (~> 3.9.0)
32
40
  rspec-expectations (~> 3.9.0)
@@ -40,11 +48,27 @@ GEM
40
48
  diff-lcs (>= 1.2.0, < 2.0)
41
49
  rspec-support (~> 3.9.0)
42
50
  rspec-support (3.9.0)
51
+ rubocop (1.36.0)
52
+ json (~> 2.3)
53
+ parallel (~> 1.10)
54
+ parser (>= 3.1.2.1)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ regexp_parser (>= 1.8, < 3.0)
57
+ rexml (>= 3.2.5, < 4.0)
58
+ rubocop-ast (>= 1.20.1, < 2.0)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 1.4.0, < 3.0)
61
+ rubocop-ast (1.21.0)
62
+ parser (>= 3.1.1.0)
63
+ rubocop-rspec (2.13.2)
64
+ rubocop (~> 1.33)
65
+ ruby-progressbar (1.11.0)
43
66
  safe_yaml (1.0.5)
44
67
  timecop (0.9.1)
45
68
  unf (0.1.4)
46
69
  unf_ext
47
70
  unf_ext (0.0.7.7)
71
+ unicode-display_width (2.3.0)
48
72
  webmock (3.7.6)
49
73
  addressable (>= 2.3.6)
50
74
  crack (>= 0.3.2)
@@ -58,8 +82,10 @@ DEPENDENCIES
58
82
  bundler
59
83
  rake
60
84
  rspec
85
+ rubocop
86
+ rubocop-rspec
61
87
  timecop
62
88
  webmock
63
89
 
64
90
  BUNDLED WITH
65
- 1.17.3
91
+ 2.2.25
data/README.md CHANGED
@@ -33,6 +33,7 @@ You can set a `logger` as well.
33
33
  Changelog
34
34
  ---------
35
35
 
36
+ * v.0.4.0 Add new, opt-in error for missing product, and several internal improvements
36
37
  * v.0.3.4 Security: upgrade addressable from 2.7.0 to 2.8.0
37
38
  * v.0.3.3 Transaction and Account are compatible with account ID
38
39
  * v.0.3.2 Properly handle account ID needed errors
data/afterbanks.gemspec CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rubocop"
28
+ spec.add_development_dependency 'rubocop-rspec'
27
29
  spec.add_development_dependency "timecop"
28
30
  spec.add_development_dependency "webmock"
29
31
  end
@@ -3,8 +3,6 @@ require 'json'
3
3
 
4
4
  module Afterbanks
5
5
  class << self
6
- attr_accessor :configuration
7
-
8
6
  def configuration
9
7
  @configuration ||= Configuration.new
10
8
  end
@@ -17,7 +15,7 @@ module Afterbanks
17
15
  url = 'https://api.afterbanks.com' + path
18
16
 
19
17
  # Timeout is set to 5min: some banks take a lot to respond (e.g. ING Direct)
20
- request_params = { method: method, url: url, timeout: 60*5 }
18
+ request_params = { method: method, url: url, timeout: 60 * 5 }
21
19
 
22
20
  if method == :post
23
21
  request_params.merge!(payload: params)
@@ -34,9 +32,9 @@ module Afterbanks
34
32
  debug_id = response.headers[:debug_id]
35
33
 
36
34
  log_request(
37
- method: method,
38
- url: url,
39
- params: params,
35
+ method: method,
36
+ url: url,
37
+ params: params,
40
38
  debug_id: debug_id
41
39
  )
42
40
 
@@ -44,7 +42,7 @@ module Afterbanks
44
42
 
45
43
  treat_errors_if_any(
46
44
  response_body: response_body,
47
- debug_id: debug_id
45
+ debug_id: debug_id
48
46
  )
49
47
 
50
48
  [response_body, debug_id]
@@ -70,13 +68,13 @@ module Afterbanks
70
68
  end
71
69
 
72
70
  logger.info(
73
- message: 'Afterbanks request',
74
- method: method.upcase.to_s,
75
- url: url,
76
- time: now.to_s,
71
+ message: 'Afterbanks request',
72
+ method: method.upcase.to_s,
73
+ url: url,
74
+ time: now.to_s,
77
75
  timestamp: now.to_i,
78
- debug_id: debug_id || 'none',
79
- params: safe_params
76
+ debug_id: debug_id || 'none',
77
+ params: safe_params
80
78
  )
81
79
  end
82
80
 
@@ -93,28 +91,28 @@ module Afterbanks
93
91
 
94
92
  case code
95
93
  when 1
96
- raise GenericError.new(error_info)
94
+ raise GenericError.new(**error_info)
97
95
  when 2
98
- raise ServiceUnavailableTemporarilyError.new(error_info)
96
+ raise ServiceUnavailableTemporarilyError.new(**error_info)
99
97
  when 3
100
- raise ConnectionDataError.new(error_info)
98
+ raise ConnectionDataError.new(**error_info)
101
99
  when 4
102
- raise AccountIdDoesNotExistError.new(error_info)
100
+ raise AccountIdDoesNotExistError.new(**error_info)
103
101
  when 5
104
- raise CutConnectionError.new(error_info)
102
+ raise CutConnectionError.new(**error_info)
105
103
  when 6
106
- raise HumanActionNeededError.new(error_info)
104
+ raise HumanActionNeededError.new(**error_info)
107
105
  when 50
108
106
  unless additional_info
109
- raise MissingParameterError.new(error_info)
107
+ raise MissingParameterError.new(**error_info)
110
108
  end
111
109
 
112
110
  error_info.merge!(additional_info: additional_info)
113
111
 
114
112
  if additional_info.is_a?(Hash) && additional_info['session_id']
115
- raise TwoStepAuthenticationError.new(error_info)
113
+ raise TwoStepAuthenticationError.new(**error_info)
116
114
  else
117
- raise AccountIdNeededError.new(error_info)
115
+ raise AccountIdNeededError.new(**error_info)
118
116
  end
119
117
  end
120
118
 
@@ -66,4 +66,12 @@ module Afterbanks
66
66
  50
67
67
  end
68
68
  end
69
+
70
+ class MissingProductError < Error
71
+ def code
72
+ # This is not provided by Afterbanks itself, but an invented unique ID
73
+ # without overlap from other error codes
74
+ -1
75
+ end
76
+ end
69
77
  end
@@ -1,67 +1,69 @@
1
1
  module Afterbanks
2
2
  class Account < Resource
3
- has_fields service: :string,
4
- product: :string,
5
- type: :string,
6
- balance: :decimal,
7
- currency: :string,
3
+ has_fields service: :string,
4
+ product: :string,
5
+ type: :string,
6
+ balance: :decimal,
7
+ currency: :string,
8
8
  description: :string,
9
- iban: :string,
10
- is_owner: :boolean,
11
- holders: :hash
9
+ iban: :string,
10
+ is_owner: :boolean,
11
+ holders: :hash
12
12
 
13
- def self.list(service:, username:, password:, password2: nil,
14
- document_type: nil, account_id: nil,
15
- session_id: nil, otp: nil, counter_id: nil,
16
- avoid_caching: false)
13
+ class << self
14
+ def list(service:, username:, password:, password2: nil,
15
+ document_type: nil, account_id: nil,
16
+ session_id: nil, otp: nil, counter_id: nil,
17
+ avoid_caching: false)
17
18
 
18
- params = {
19
- servicekey: Afterbanks.configuration.servicekey,
20
- service: service,
21
- user: username,
22
- pass: password,
23
- products: 'GLOBAL'
24
- }
19
+ params = {
20
+ servicekey: Afterbanks.configuration.servicekey,
21
+ service: service,
22
+ user: username,
23
+ pass: password,
24
+ products: 'GLOBAL'
25
+ }
25
26
 
26
- params.merge!(pass2: password2) unless password2.nil?
27
- params.merge!(documentType: document_type) unless document_type.nil?
28
- params.merge!(account_id: account_id) unless account_id.nil?
27
+ params.merge!(pass2: password2) unless password2.nil?
28
+ params.merge!(documentType: document_type) unless document_type.nil?
29
+ params.merge!(account_id: account_id) unless account_id.nil?
29
30
 
30
- params.merge!(session_id: session_id) unless session_id.nil?
31
- params.merge!(OTP: otp) unless otp.nil?
32
- params.merge!(counterId: counter_id) unless counter_id.nil?
31
+ params.merge!(session_id: session_id) unless session_id.nil?
32
+ params.merge!(OTP: otp) unless otp.nil?
33
+ params.merge!(counterId: counter_id) unless counter_id.nil?
33
34
 
34
- params.merge!(randomizer: Time.now.to_i) if avoid_caching
35
+ params.merge!(randomizer: Time.now.to_i) if avoid_caching
35
36
 
36
- response, debug_id = Afterbanks.api_call(
37
- method: :post,
38
- path: '/V3/',
39
- params: params
40
- )
37
+ response, debug_id = Afterbanks.api_call(
38
+ method: :post,
39
+ path: '/V3/',
40
+ params: params
41
+ )
41
42
 
42
- Response.new(
43
- result: Collection.new(
44
- accounts_information_for(
45
- response: response,
46
- service: service
43
+ Response.new(
44
+ result: Collection.new(
45
+ accounts_information_for(
46
+ response: response,
47
+ service: service
48
+ ),
49
+ self
47
50
  ),
48
- self
49
- ),
50
- debug_id: debug_id
51
- )
52
- end
51
+ debug_id: debug_id
52
+ )
53
+ end
53
54
 
54
55
  private
55
56
 
56
- def self.accounts_information_for(response:, service:)
57
- accounts_information = []
57
+ def accounts_information_for(response:, service:)
58
+ accounts_information = []
58
59
 
59
- response.each do |account_information|
60
- account_information['service'] = service
61
- accounts_information << account_information
62
- end
60
+ response.each do |account_information|
61
+ account_information['service'] = service
62
+ accounts_information << account_information
63
+ end
63
64
 
64
- accounts_information
65
- end
65
+ accounts_information
66
+ end
67
+ end
66
68
  end
67
69
  end
@@ -1,111 +1,113 @@
1
1
  module Afterbanks
2
2
  class Bank < Resource
3
3
  has_fields country_code: :string,
4
- service: :string,
5
- swift: :string,
6
- fullname: :string,
7
- business: :boolean,
4
+ service: :string,
5
+ swift: :string,
6
+ fullname: :string,
7
+ business: :boolean,
8
8
  documenttype: :string,
9
- user: :string,
10
- pass: :string,
11
- pass2: :string,
12
- userdesc: :string,
13
- passdesc: :string,
14
- pass2desc: :string,
15
- usertype: :string,
16
- passtype: :string,
17
- pass2type: :string,
18
- image: :string,
19
- color: :string
20
-
21
- def self.list(ordered: false)
22
- response, debug_id = Afterbanks.api_call(
23
- method: :get,
24
- path: '/forms/'
25
- )
26
-
27
- Response.new(
28
- result: Collection.new(
29
- banks_information_for(
30
- response: response,
31
- ordered: ordered
9
+ user: :string,
10
+ pass: :string,
11
+ pass2: :string,
12
+ userdesc: :string,
13
+ passdesc: :string,
14
+ pass2desc: :string,
15
+ usertype: :string,
16
+ passtype: :string,
17
+ pass2type: :string,
18
+ image: :string,
19
+ color: :string
20
+
21
+ class << self
22
+ def list(ordered: false)
23
+ response, debug_id = Afterbanks.api_call(
24
+ method: :get,
25
+ path: '/forms/'
26
+ )
27
+
28
+ Response.new(
29
+ result: Collection.new(
30
+ banks_information_for(
31
+ response: response,
32
+ ordered: ordered
33
+ ),
34
+ self
32
35
  ),
33
- self
34
- ),
35
- debug_id: debug_id
36
- )
37
- end
36
+ debug_id: debug_id
37
+ )
38
+ end
38
39
 
39
40
  private
40
41
 
41
- def self.banks_information_for(response:, ordered:)
42
- banks_information = []
42
+ def banks_information_for(response:, ordered:)
43
+ banks_information = []
43
44
 
44
- services_number_by_bank_id = {}
45
- response.each { |bank_information|
46
- bank_id = bank_id_for(bank_information: bank_information)
47
- services_number_by_bank_id[bank_id] ||= 0
48
- services_number_by_bank_id[bank_id] += 1
49
- }
50
-
51
- response.each do |bank_information|
52
- bank_information['fullname'] = bank_name_for(
53
- bank_information: bank_information,
54
- services_number_by_bank_id: services_number_by_bank_id
55
- )
45
+ services_number_by_bank_id = {}
46
+ response.each { |bank_information|
47
+ bank_id = bank_id_for(bank_information: bank_information)
48
+ services_number_by_bank_id[bank_id] ||= 0
49
+ services_number_by_bank_id[bank_id] += 1
50
+ }
56
51
 
57
- banks_information << bank_information
58
- end
52
+ response.each do |bank_information|
53
+ bank_information['fullname'] = bank_name_for(
54
+ bank_information: bank_information,
55
+ services_number_by_bank_id: services_number_by_bank_id
56
+ )
57
+
58
+ banks_information << bank_information
59
+ end
59
60
 
60
- if ordered
61
- banks_information.sort! do |bank_information1, bank_information2|
62
- bank_information1['fullname'].downcase <=> bank_information2['fullname'].downcase
61
+ if ordered
62
+ banks_information.sort! do |bank_information1, bank_information2|
63
+ bank_information1['fullname'].downcase <=> bank_information2['fullname'].downcase
64
+ end
63
65
  end
66
+
67
+ banks_information
64
68
  end
65
69
 
66
- banks_information
67
- end
70
+ def bank_name_for(bank_information:, services_number_by_bank_id:)
71
+ # Name changes:
72
+ # 1. Add Particulares if there are different personal/company endpoints
73
+ # 2. Add Empresas following the same reason
74
+ # 3. Rename Caja Ingenieros into Caixa d'Enginyers (most known name)
75
+ # 4. Rename Caixa Guisona into Caixa Guissona (fix typo)
76
+ # 5. Rename Caixa burriana into Caixa Burriana (fix typo)
77
+ # 6. Rename Bancho Pichincha into Banco Pichincha (fix typo)
78
+
79
+ if bank_information['service'] == 'cajaingenieros'
80
+ return "Caixa d'Enginyers"
81
+ end
68
82
 
69
- def self.bank_name_for(bank_information:, services_number_by_bank_id:)
70
- # Name changes:
71
- # 1. Add Particulares if there are different personal/company endpoints
72
- # 2. Add Empresas following the same reason
73
- # 3. Rename Caja Ingenieros into Caixa d'Enginyers (most known name)
74
- # 4. Rename Caixa Guisona into Caixa Guissona (fix typo)
75
- # 5. Rename Caixa burriana into Caixa Burriana (fix typo)
76
- # 6. Rename Bancho Pichincha into Banco Pichincha (fix typo)
83
+ if bank_information['service'] == 'caixaguissona'
84
+ return "Caixa Guissona"
85
+ end
77
86
 
78
- if bank_information['service'] == 'cajaingenieros'
79
- return "Caixa d'Enginyers"
80
- end
87
+ if bank_information['service'] == 'caixaruralburriana'
88
+ return "Caixa Burriana"
89
+ end
81
90
 
82
- if bank_information['service'] == 'caixaguissona'
83
- return "Caixa Guissona"
84
- end
91
+ if bank_information['service'] == 'pichincha'
92
+ return "Banco Pichincha"
93
+ end
85
94
 
86
- if bank_information['service'] == 'caixaruralburriana'
87
- return "Caixa Burriana"
88
- end
95
+ fullname = bank_information['fullname']
96
+ if bank_information['business'] == "1"
97
+ return "#{fullname} Empresas"
98
+ end
89
99
 
90
- if bank_information['service'] == 'pichincha'
91
- return "Banco Pichincha"
92
- end
100
+ bank_id = bank_id_for(bank_information: bank_information)
101
+ if services_number_by_bank_id[bank_id] > 1
102
+ return "#{fullname} Particulares"
103
+ end
93
104
 
94
- fullname = bank_information['fullname']
95
- if bank_information['business'] == "1"
96
- return "#{fullname} Empresas"
105
+ fullname
97
106
  end
98
107
 
99
- bank_id = bank_id_for(bank_information: bank_information)
100
- if services_number_by_bank_id[bank_id] > 1
101
- return "#{fullname} Particulares"
108
+ def bank_id_for(bank_information:)
109
+ bank_information['service'].split("_").first
102
110
  end
103
-
104
- fullname
105
- end
106
-
107
- def self.bank_id_for(bank_information:)
108
- bank_information['service'].split("_").first
109
- end
111
+ end
110
112
  end
111
113
  end
@@ -1,79 +1,102 @@
1
1
  module Afterbanks
2
2
  class Transaction < Resource
3
- has_fields service: :string,
4
- product: :string,
5
- date: :date,
6
- date2: :date,
7
- amount: :decimal,
8
- description: :string,
9
- balance: :decimal,
3
+ has_fields service: :string,
4
+ product: :string,
5
+ date: :date,
6
+ date2: :date,
7
+ amount: :decimal,
8
+ description: :string,
9
+ balance: :decimal,
10
10
  transactionId: :string,
11
- categoryId: :integer
12
-
13
- def self.list(service:, username:, password:, password2: nil,
14
- document_type: nil, account_id: nil,
15
- products:, startdate:,
16
- session_id: nil, otp: nil, counter_id: nil)
17
-
18
- params = {
19
- servicekey: Afterbanks.configuration.servicekey,
20
- service: service,
21
- user: username,
22
- pass: password,
23
- products: products,
24
- startdate: startdate.strftime("%d-%m-%Y")
25
- }
26
-
27
- params.merge!(pass2: password2) unless password2.nil?
28
- params.merge!(documentType: document_type) unless document_type.nil?
29
- params.merge!(account_id: account_id) unless account_id.nil?
30
-
31
- params.merge!(session_id: session_id) unless session_id.nil?
32
- params.merge!(OTP: otp) unless otp.nil?
33
- params.merge!(counterId: counter_id) unless counter_id.nil?
34
-
35
- response, debug_id = Afterbanks.api_call(
36
- method: :post,
37
- path: '/V3/',
38
- params: params
39
- )
40
-
41
- Response.new(
42
- result: Collection.new(
43
- transactions_information_for(
44
- service: service,
11
+ categoryId: :integer
12
+
13
+ class << self
14
+ def list(service:, username:, password:, password2: nil,
15
+ document_type: nil, account_id: nil,
16
+ products:, check_products_presence: false, startdate:,
17
+ session_id: nil, otp: nil, counter_id: nil)
18
+
19
+ params = {
20
+ servicekey: Afterbanks.configuration.servicekey,
21
+ service: service,
22
+ user: username,
23
+ pass: password,
24
+ products: products,
25
+ startdate: startdate.strftime("%d-%m-%Y")
26
+ }
27
+
28
+ params.merge!(pass2: password2) unless password2.nil?
29
+ params.merge!(documentType: document_type) unless document_type.nil?
30
+ params.merge!(account_id: account_id) unless account_id.nil?
31
+
32
+ params.merge!(session_id: session_id) unless session_id.nil?
33
+ params.merge!(OTP: otp) unless otp.nil?
34
+ params.merge!(counterId: counter_id) unless counter_id.nil?
35
+
36
+ response, debug_id = Afterbanks.api_call(
37
+ method: :post,
38
+ path: '/V3/',
39
+ params: params
40
+ )
41
+
42
+ if check_products_presence
43
+ ensure_no_product_is_missing(
45
44
  response: response,
45
+ debug_id: debug_id,
46
46
  products: products
47
+ )
48
+ end
49
+
50
+ Response.new(
51
+ result: Collection.new(
52
+ transactions_information_for(
53
+ service: service,
54
+ response: response,
55
+ products: products
56
+ ),
57
+ self
47
58
  ),
48
- self
49
- ),
50
- debug_id: debug_id
51
- )
52
- end
59
+ debug_id: debug_id
60
+ )
61
+ end
53
62
 
54
63
  private
55
64
 
56
- def self.transactions_information_for(response:, service:, products:)
57
- transactions_information = []
58
- products_array = products.split(",")
65
+ def ensure_no_product_is_missing(response:, debug_id:, products:)
66
+ products_array = products.split(",")
67
+ found_products_array = response.map { |account_information| account_information['product'] }
59
68
 
60
- response.each do |account_information|
61
- product = account_information['product']
69
+ missing_products_array = products_array - found_products_array
70
+ return unless missing_products_array.any?
62
71
 
63
- if products_array.include?(product)
64
- transactions = account_information['transactions']
65
- next if transactions.nil?
72
+ raise MissingProductError.new(
73
+ message: 'Producto no encontrado',
74
+ debug_id: debug_id
75
+ )
76
+ end
66
77
 
67
- transactions.each do |transaction|
68
- transaction['service'] = service
69
- transaction['product'] = product
70
- end
78
+ def transactions_information_for(response:, service:, products:)
79
+ transactions_information = []
80
+ products_array = products.split(",")
81
+
82
+ response.each do |account_information|
83
+ product = account_information['product']
84
+
85
+ if products_array.include?(product)
86
+ transactions = account_information['transactions']
87
+ next if transactions.nil?
88
+
89
+ transactions.each do |transaction|
90
+ transaction['service'] = service
91
+ transaction['product'] = product
92
+ end
71
93
 
72
- transactions_information += transactions
94
+ transactions_information += transactions
95
+ end
73
96
  end
74
- end
75
97
 
76
- transactions_information
77
- end
98
+ transactions_information
99
+ end
100
+ end
78
101
  end
79
102
  end
@@ -1,24 +1,26 @@
1
1
  module Afterbanks
2
2
  class User < Resource
3
- has_fields limit: :integer,
4
- counter: :integer,
3
+ has_fields limit: :integer,
4
+ counter: :integer,
5
5
  remaining_calls: :integer,
6
- date_renewal: :date,
7
- detail: :string
6
+ date_renewal: :date,
7
+ detail: :string
8
8
 
9
- def self.get
10
- response, debug_id = Afterbanks.api_call(
11
- method: :post,
12
- path: '/me/',
13
- params: {
14
- servicekey: Afterbanks.configuration.servicekey
15
- }
16
- )
9
+ class << self
10
+ def get
11
+ response, debug_id = Afterbanks.api_call(
12
+ method: :post,
13
+ path: '/me/',
14
+ params: {
15
+ servicekey: Afterbanks.configuration.servicekey
16
+ }
17
+ )
17
18
 
18
- Response.new(
19
- result: new(response),
20
- debug_id: debug_id
21
- )
19
+ Response.new(
20
+ result: new(response),
21
+ debug_id: debug_id
22
+ )
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -1,3 +1,3 @@
1
1
  module Afterbanks
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: afterbanks-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Bellonch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-13 00:00:00.000000000 Z
11
+ date: 2022-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
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
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
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'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: timecop
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +132,8 @@ files:
104
132
  - ".circleci/config.yml"
105
133
  - ".gitignore"
106
134
  - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".rubocop_exclusions.yml"
107
137
  - Gemfile
108
138
  - Gemfile.lock
109
139
  - README.md
@@ -139,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
169
  - !ruby/object:Gem::Version
140
170
  version: '0'
141
171
  requirements: []
142
- rubygems_version: 3.0.3
172
+ rubygems_version: 3.1.4
143
173
  signing_key:
144
174
  specification_version: 4
145
175
  summary: Ruby client for the Afterbanks' API