afterbanks-api-ruby 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +40 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +65 -0
- data/README.md +51 -0
- data/Rakefile +8 -0
- data/afterbanks.gemspec +29 -0
- data/lib/afterbanks.rb +12 -0
- data/lib/afterbanks/base.rb +128 -0
- data/lib/afterbanks/collection.rb +9 -0
- data/lib/afterbanks/configuration.rb +5 -0
- data/lib/afterbanks/error.rb +69 -0
- data/lib/afterbanks/resource.rb +77 -0
- data/lib/afterbanks/resources/account.rb +64 -0
- data/lib/afterbanks/resources/bank.rb +91 -0
- data/lib/afterbanks/resources/transaction.rb +76 -0
- data/lib/afterbanks/resources/user.rb +24 -0
- data/lib/afterbanks/response.rb +10 -0
- data/lib/afterbanks/version.rb +3 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19bc05050d36cdf980cc1d2ab883c6b82f4ed4622fa959cebaa80099b5a40716
|
4
|
+
data.tar.gz: a5ffd80b0e31ee743d903564909ba692839c34a390eab12bcec6948719b56b6b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89335c1312001084d537c486f800d3d46fc252b80a634d970b68120210888cbc2e9ba66ee80f331da86cd813c8362081c25f4c91da8501bf6e0157970a4aea51
|
7
|
+
data.tar.gz: e97843bdfd06e003e5ba6136e8e237084e5b0d43c0ad347c221f42586936772c099bf2a2cf59ec57a8363db0b6b600304e21ad0f36d629f83fba70de44f5719c
|
@@ -0,0 +1,40 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
executors:
|
4
|
+
gem-executor:
|
5
|
+
working_directory: ~/tmp/gem
|
6
|
+
docker:
|
7
|
+
- image: circleci/ruby:2.4.1
|
8
|
+
environment:
|
9
|
+
TZ: "Europe/Madrid"
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build-test-gem:
|
13
|
+
executor: gem-executor
|
14
|
+
steps:
|
15
|
+
- checkout
|
16
|
+
|
17
|
+
- run:
|
18
|
+
name: Update bundler
|
19
|
+
command: gem install bundler -v 1.17.3
|
20
|
+
|
21
|
+
- restore_cache:
|
22
|
+
keys:
|
23
|
+
- afterbanks-api-ruby-bundle-v2-{{ checksum "Gemfile.lock" }}
|
24
|
+
- afterbanks-api-ruby-bundle-v2-
|
25
|
+
|
26
|
+
- run: bundle install
|
27
|
+
|
28
|
+
- save_cache:
|
29
|
+
key: afterbanks-api-ruby-bundle-v2-{{ checksum "Gemfile.lock" }}
|
30
|
+
paths:
|
31
|
+
- vendor/bundle
|
32
|
+
|
33
|
+
- run:
|
34
|
+
name: Run rspec
|
35
|
+
command: bundle exec rspec spec/
|
36
|
+
|
37
|
+
workflows:
|
38
|
+
build-test-gem:
|
39
|
+
jobs:
|
40
|
+
- build-test-gem
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
afterbanks-api-ruby (0.2.1)
|
5
|
+
rest-client (~> 2.0.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
domain_name (0.5.20190701)
|
16
|
+
unf (>= 0.0.5, < 1.0.0)
|
17
|
+
hashdiff (1.0.0)
|
18
|
+
http-cookie (1.0.3)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
mime-types (3.3.1)
|
21
|
+
mime-types-data (~> 3.2015)
|
22
|
+
mime-types-data (3.2019.1009)
|
23
|
+
netrc (0.11.0)
|
24
|
+
public_suffix (4.0.1)
|
25
|
+
rake (13.0.1)
|
26
|
+
rest-client (2.0.2)
|
27
|
+
http-cookie (>= 1.0.2, < 2.0)
|
28
|
+
mime-types (>= 1.16, < 4.0)
|
29
|
+
netrc (~> 0.8)
|
30
|
+
rspec (3.9.0)
|
31
|
+
rspec-core (~> 3.9.0)
|
32
|
+
rspec-expectations (~> 3.9.0)
|
33
|
+
rspec-mocks (~> 3.9.0)
|
34
|
+
rspec-core (3.9.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-expectations (3.9.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-mocks (3.9.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-support (3.9.0)
|
43
|
+
safe_yaml (1.0.5)
|
44
|
+
timecop (0.9.1)
|
45
|
+
unf (0.1.4)
|
46
|
+
unf_ext
|
47
|
+
unf_ext (0.0.7.6)
|
48
|
+
webmock (3.7.6)
|
49
|
+
addressable (>= 2.3.6)
|
50
|
+
crack (>= 0.3.2)
|
51
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
afterbanks-api-ruby!
|
58
|
+
bundler
|
59
|
+
rake
|
60
|
+
rspec
|
61
|
+
timecop
|
62
|
+
webmock
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
1.17.3
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Ruby client for Afterbanks API
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/quipuapp/afterbanks-api-ruby.svg?style=shield)](https://circleci.com/gh/quipuapp/afterbanks-api-ruby)
|
4
|
+
|
5
|
+
This is a Ruby client for the Afterbanks' API
|
6
|
+
|
7
|
+
Installation
|
8
|
+
---------
|
9
|
+
|
10
|
+
Install the gem (`gem install afterbanks-api-ruby`) or include it in your Gemfile and `bundle`.
|
11
|
+
|
12
|
+
Configuration
|
13
|
+
---------
|
14
|
+
|
15
|
+
Just set the service key by doing this:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Afterbanks.servicekey = 'yourservicekey'
|
19
|
+
```
|
20
|
+
|
21
|
+
Or, if you use it in a Rails application, create an initializer with this content:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'afterbanks'
|
25
|
+
|
26
|
+
Afterbanks.configure do |config|
|
27
|
+
config.servicekey = 'yourservicekey'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
You can set a `logger` as well.
|
32
|
+
|
33
|
+
Changelog
|
34
|
+
---------
|
35
|
+
|
36
|
+
* v.0.2.1 Better naming for banks
|
37
|
+
* v.0.2.0 Allow adding an (opt-in) random parameter to Afterbanks::Account.list to avoid caching
|
38
|
+
* v.0.1.1 Fix rake security issue and remove specific Ruby version dependency.
|
39
|
+
* v.0.1.0 First vull version, including resource wrapping (for banks, accounts, transactions and the user) and separate exceptions for each different code.
|
40
|
+
|
41
|
+
TODO
|
42
|
+
----
|
43
|
+
|
44
|
+
* Full usage for each resource
|
45
|
+
* Proper explanation of the `Afterbanks:Error` and its subclasses
|
46
|
+
|
47
|
+
About Afterbanks
|
48
|
+
------------
|
49
|
+
|
50
|
+
* [Public site](https://www.afterbanks.com)
|
51
|
+
* [Documentation](https://app.swaggerhub.com/apis/Afterbanks/afterbanks-api-extendida)
|
data/Rakefile
ADDED
data/afterbanks.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'afterbanks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "afterbanks-api-ruby"
|
8
|
+
spec.version = Afterbanks::VERSION
|
9
|
+
spec.authors = ["Albert Bellonch"]
|
10
|
+
spec.email = ["albert@getquipu.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby client for the Afterbanks' API"
|
13
|
+
spec.homepage = "https://getquipu.com"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "rest-client", "~> 2.0.2"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "timecop"
|
28
|
+
spec.add_development_dependency "webmock"
|
29
|
+
end
|
data/lib/afterbanks.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'afterbanks/version'
|
2
|
+
require 'afterbanks/configuration'
|
3
|
+
require 'afterbanks/base'
|
4
|
+
require 'afterbanks/error'
|
5
|
+
require 'afterbanks/resource'
|
6
|
+
require 'afterbanks/response'
|
7
|
+
require 'afterbanks/collection'
|
8
|
+
|
9
|
+
require 'afterbanks/resources/user'
|
10
|
+
require 'afterbanks/resources/bank'
|
11
|
+
require 'afterbanks/resources/account'
|
12
|
+
require 'afterbanks/resources/transaction'
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Afterbanks
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
|
8
|
+
def configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_call(method:, path:, params: {})
|
17
|
+
url = 'https://api.afterbanks.com' + path
|
18
|
+
|
19
|
+
request_params = { method: method, url: url }
|
20
|
+
|
21
|
+
if method == :post
|
22
|
+
request_params.merge!(payload: params)
|
23
|
+
else
|
24
|
+
request_params.merge!(headers: { params: params })
|
25
|
+
end
|
26
|
+
|
27
|
+
response = begin
|
28
|
+
RestClient::Request.execute(request_params)
|
29
|
+
rescue RestClient::BadRequest, RestClient::ExpectationFailed => bad_request
|
30
|
+
bad_request.response
|
31
|
+
end
|
32
|
+
|
33
|
+
debug_id = response.headers[:debug_id]
|
34
|
+
|
35
|
+
log_request(
|
36
|
+
method: method,
|
37
|
+
url: url,
|
38
|
+
params: params,
|
39
|
+
debug_id: debug_id
|
40
|
+
)
|
41
|
+
|
42
|
+
response_body = JSON.parse(response.body)
|
43
|
+
|
44
|
+
treat_errors_if_any(
|
45
|
+
response_body: response_body,
|
46
|
+
debug_id: debug_id
|
47
|
+
)
|
48
|
+
|
49
|
+
[response_body, debug_id]
|
50
|
+
end
|
51
|
+
|
52
|
+
def log_request(method:, url:, params: {}, debug_id: nil)
|
53
|
+
now = Time.now
|
54
|
+
|
55
|
+
log_message(message: "")
|
56
|
+
log_message(message: "=> #{method.upcase} #{url}")
|
57
|
+
|
58
|
+
log_message(message: "* Time: #{now}")
|
59
|
+
log_message(message: "* Timestamp: #{now.to_i}")
|
60
|
+
log_message(message: "* Debug ID: #{debug_id || 'none'}")
|
61
|
+
|
62
|
+
if params.any?
|
63
|
+
log_message(message: "* Params")
|
64
|
+
params.each do |key, value|
|
65
|
+
safe_value = if %w{servicekey user pass pass2}.include?(key.to_s)
|
66
|
+
"<masked>"
|
67
|
+
else
|
68
|
+
value
|
69
|
+
end
|
70
|
+
|
71
|
+
log_message(message: "#{key}: #{safe_value}")
|
72
|
+
end
|
73
|
+
else
|
74
|
+
log_message(message: "* No params")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def log_message(message: nil)
|
79
|
+
return if message.nil?
|
80
|
+
|
81
|
+
logger = Afterbanks.configuration.logger
|
82
|
+
return if logger.nil?
|
83
|
+
|
84
|
+
logger.info(message)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def treat_errors_if_any(response_body:, debug_id:)
|
90
|
+
return unless response_body.is_a?(Hash)
|
91
|
+
|
92
|
+
code = response_body['code']
|
93
|
+
message = response_body['message']
|
94
|
+
additional_info = response_body['additional_info']
|
95
|
+
|
96
|
+
error_info = { message: message, debug_id: debug_id }
|
97
|
+
|
98
|
+
case code
|
99
|
+
when 1
|
100
|
+
raise GenericError.new(error_info)
|
101
|
+
when 2
|
102
|
+
raise ServiceUnavailableTemporarilyError.new(error_info)
|
103
|
+
when 3
|
104
|
+
raise ConnectionDataError.new(error_info)
|
105
|
+
when 4
|
106
|
+
raise AccountIdDoesNotExistError.new(error_info)
|
107
|
+
when 5
|
108
|
+
raise CutConnectionError.new(error_info)
|
109
|
+
when 6
|
110
|
+
raise HumanActionNeededError.new(error_info)
|
111
|
+
when 50
|
112
|
+
unless additional_info
|
113
|
+
raise MissingParameterError.new(error_info)
|
114
|
+
end
|
115
|
+
|
116
|
+
error_info.merge!(additional_info: additional_info)
|
117
|
+
|
118
|
+
if additional_info['session_id']
|
119
|
+
raise TwoStepAuthenticationError.new(error_info)
|
120
|
+
else
|
121
|
+
raise AccountIdNeededError.new(error_info)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Afterbanks
|
2
|
+
class Error < ::StandardError
|
3
|
+
attr_reader :message, :debug_id, :additional_info
|
4
|
+
|
5
|
+
def initialize(message:, debug_id:, additional_info: nil)
|
6
|
+
@message = message
|
7
|
+
@debug_id = debug_id
|
8
|
+
@additional_info = additional_info
|
9
|
+
end
|
10
|
+
|
11
|
+
def code
|
12
|
+
raise 'Not implemented'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class GenericError < Error
|
17
|
+
def code
|
18
|
+
1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ServiceUnavailableTemporarilyError < Error
|
23
|
+
def code
|
24
|
+
2
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ConnectionDataError < Error
|
29
|
+
def code
|
30
|
+
3
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class AccountIdDoesNotExistError < Error
|
35
|
+
def code
|
36
|
+
4
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class CutConnectionError < Error
|
41
|
+
def code
|
42
|
+
5
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class HumanActionNeededError < Error
|
47
|
+
def code
|
48
|
+
6
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class AccountIdNeededError < Error
|
53
|
+
def code
|
54
|
+
50
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class TwoStepAuthenticationError < Error
|
59
|
+
def code
|
60
|
+
50
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class MissingParameterError < Error
|
65
|
+
def code
|
66
|
+
50
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Afterbanks
|
2
|
+
class Resource
|
3
|
+
def initialize(data)
|
4
|
+
generate_attr_readers
|
5
|
+
set_data(data)
|
6
|
+
end
|
7
|
+
|
8
|
+
def fields_information
|
9
|
+
self.class.fields_information
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def generate_attr_readers
|
15
|
+
fields_information.each do |field, _|
|
16
|
+
define_singleton_method(field) do
|
17
|
+
instance_variable_get("@#{field}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_data(data)
|
23
|
+
fields_information.each do |field, type|
|
24
|
+
next unless data.key?(field.to_s) || data[field.to_sym]
|
25
|
+
|
26
|
+
raw_value = data[field.to_s] || data[field.to_sym]
|
27
|
+
value = value_for(raw_value, type)
|
28
|
+
instance_variable_set("@#{field}", value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def value_for(raw_value, type)
|
33
|
+
case type
|
34
|
+
when :boolean
|
35
|
+
[true, "1", 1].include?(raw_value)
|
36
|
+
when :date
|
37
|
+
if raw_value.is_a?(Date)
|
38
|
+
raw_value
|
39
|
+
else
|
40
|
+
Date.parse(raw_value)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
raw_value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def marshal_dump
|
48
|
+
dump = {}
|
49
|
+
|
50
|
+
fields_information.each do |field, _|
|
51
|
+
dump[field] = send(field)
|
52
|
+
end
|
53
|
+
|
54
|
+
dump
|
55
|
+
end
|
56
|
+
|
57
|
+
def marshal_load(serialized_resource)
|
58
|
+
keys = serialized_resource.keys
|
59
|
+
|
60
|
+
keys.each do |key|
|
61
|
+
serialized_resource[key.to_s] = serialized_resource.delete(key)
|
62
|
+
end
|
63
|
+
|
64
|
+
initialize(serialized_resource)
|
65
|
+
end
|
66
|
+
|
67
|
+
class << self
|
68
|
+
def fields_information
|
69
|
+
@fields_information
|
70
|
+
end
|
71
|
+
|
72
|
+
def has_fields(fields_information)
|
73
|
+
@fields_information = fields_information
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Afterbanks
|
2
|
+
class Account < Resource
|
3
|
+
has_fields service: :string,
|
4
|
+
product: :string,
|
5
|
+
type: :string,
|
6
|
+
balance: :decimal,
|
7
|
+
currency: :string,
|
8
|
+
description: :string,
|
9
|
+
iban: :string,
|
10
|
+
is_owner: :boolean,
|
11
|
+
holders: :hash
|
12
|
+
|
13
|
+
def self.list(service:, username:, password:, password2: nil,
|
14
|
+
document_type: nil, session_id: nil, otp: nil, counter_id: nil,
|
15
|
+
avoid_caching: false)
|
16
|
+
|
17
|
+
params = {
|
18
|
+
servicekey: Afterbanks.configuration.servicekey,
|
19
|
+
service: service,
|
20
|
+
user: username,
|
21
|
+
pass: password,
|
22
|
+
products: 'GLOBAL'
|
23
|
+
}
|
24
|
+
|
25
|
+
params.merge!(pass2: password2) unless password2.nil?
|
26
|
+
params.merge!(documentType: document_type) unless document_type.nil?
|
27
|
+
params.merge!(session_id: session_id) unless session_id.nil?
|
28
|
+
params.merge!(OTP: otp) unless otp.nil?
|
29
|
+
params.merge!(counterId: counter_id) unless counter_id.nil?
|
30
|
+
|
31
|
+
params.merge!(randomizer: Time.now.to_i) if avoid_caching
|
32
|
+
|
33
|
+
response, debug_id = Afterbanks.api_call(
|
34
|
+
method: :post,
|
35
|
+
path: '/V3/',
|
36
|
+
params: params
|
37
|
+
)
|
38
|
+
|
39
|
+
Response.new(
|
40
|
+
result: Collection.new(
|
41
|
+
accounts_information_for(
|
42
|
+
response: response,
|
43
|
+
service: service
|
44
|
+
),
|
45
|
+
self
|
46
|
+
),
|
47
|
+
debug_id: debug_id
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.accounts_information_for(response:, service:)
|
54
|
+
accounts_information = []
|
55
|
+
|
56
|
+
response.each do |account_information|
|
57
|
+
account_information['service'] = service
|
58
|
+
accounts_information << account_information
|
59
|
+
end
|
60
|
+
|
61
|
+
accounts_information
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Afterbanks
|
2
|
+
class Bank < Resource
|
3
|
+
has_fields country_code: :string,
|
4
|
+
service: :string,
|
5
|
+
swift: :string,
|
6
|
+
fullname: :string,
|
7
|
+
business: :boolean,
|
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
|
32
|
+
),
|
33
|
+
self
|
34
|
+
),
|
35
|
+
debug_id: debug_id
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.banks_information_for(response:, ordered:)
|
42
|
+
banks_information = []
|
43
|
+
|
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
|
+
)
|
56
|
+
|
57
|
+
banks_information << bank_information
|
58
|
+
end
|
59
|
+
|
60
|
+
if ordered
|
61
|
+
banks_information.sort! do |bank_information1, bank_information2|
|
62
|
+
bank_information1['fullname'].downcase <=> bank_information2['fullname'].downcase
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
banks_information
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.bank_name_for(bank_information:, services_number_by_bank_id:)
|
70
|
+
if bank_information['service'] == 'cajaingenieros'
|
71
|
+
return "Caixa d'Enginyers"
|
72
|
+
end
|
73
|
+
|
74
|
+
fullname = bank_information['fullname']
|
75
|
+
if bank_information['business'] == "1"
|
76
|
+
return "#{fullname} Empresas"
|
77
|
+
end
|
78
|
+
|
79
|
+
bank_id = bank_id_for(bank_information: bank_information)
|
80
|
+
if services_number_by_bank_id[bank_id] > 1
|
81
|
+
return "#{fullname} Particulares"
|
82
|
+
end
|
83
|
+
|
84
|
+
fullname
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.bank_id_for(bank_information:)
|
88
|
+
bank_information['service'].split("_").first
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Afterbanks
|
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,
|
10
|
+
transactionId: :string,
|
11
|
+
categoryId: :integer
|
12
|
+
|
13
|
+
def self.list(service:, username:, password:, password2: nil,
|
14
|
+
document_type: nil, products:, startdate:,
|
15
|
+
session_id: nil, otp: nil, counter_id: nil)
|
16
|
+
|
17
|
+
params = {
|
18
|
+
servicekey: Afterbanks.configuration.servicekey,
|
19
|
+
service: service,
|
20
|
+
user: username,
|
21
|
+
pass: password,
|
22
|
+
products: products,
|
23
|
+
startdate: startdate.strftime("%d-%m-%Y")
|
24
|
+
}
|
25
|
+
|
26
|
+
params.merge!(pass2: password2) unless password2.nil?
|
27
|
+
params.merge!(documentType: document_type) unless document_type.nil?
|
28
|
+
params.merge!(session_id: session_id) unless session_id.nil?
|
29
|
+
params.merge!(OTP: otp) unless otp.nil?
|
30
|
+
params.merge!(counterId: counter_id) unless counter_id.nil?
|
31
|
+
|
32
|
+
response, debug_id = Afterbanks.api_call(
|
33
|
+
method: :post,
|
34
|
+
path: '/V3/',
|
35
|
+
params: params
|
36
|
+
)
|
37
|
+
|
38
|
+
Response.new(
|
39
|
+
result: Collection.new(
|
40
|
+
transactions_information_for(
|
41
|
+
service: service,
|
42
|
+
response: response,
|
43
|
+
products: products
|
44
|
+
),
|
45
|
+
self
|
46
|
+
),
|
47
|
+
debug_id: debug_id
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.transactions_information_for(response:, service:, products:)
|
54
|
+
transactions_information = []
|
55
|
+
products_array = products.split(",")
|
56
|
+
|
57
|
+
response.each do |account_information|
|
58
|
+
product = account_information['product']
|
59
|
+
|
60
|
+
if products_array.include?(product)
|
61
|
+
transactions = account_information['transactions']
|
62
|
+
next if transactions.nil?
|
63
|
+
|
64
|
+
transactions.each do |transaction|
|
65
|
+
transaction['service'] = service
|
66
|
+
transaction['product'] = product
|
67
|
+
end
|
68
|
+
|
69
|
+
transactions_information += transactions
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
transactions_information
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Afterbanks
|
2
|
+
class User < Resource
|
3
|
+
has_fields limit: :integer,
|
4
|
+
counter: :integer,
|
5
|
+
remaining_calls: :integer,
|
6
|
+
date_renewal: :date,
|
7
|
+
detail: :string
|
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
|
+
)
|
17
|
+
|
18
|
+
Response.new(
|
19
|
+
result: new(response),
|
20
|
+
debug_id: debug_id
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: afterbanks-api-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Albert Bellonch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
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: webmock
|
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
|
+
description:
|
98
|
+
email:
|
99
|
+
- albert@getquipu.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".circleci/config.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- afterbanks.gemspec
|
112
|
+
- lib/afterbanks.rb
|
113
|
+
- lib/afterbanks/base.rb
|
114
|
+
- lib/afterbanks/collection.rb
|
115
|
+
- lib/afterbanks/configuration.rb
|
116
|
+
- lib/afterbanks/error.rb
|
117
|
+
- lib/afterbanks/resource.rb
|
118
|
+
- lib/afterbanks/resources/account.rb
|
119
|
+
- lib/afterbanks/resources/bank.rb
|
120
|
+
- lib/afterbanks/resources/transaction.rb
|
121
|
+
- lib/afterbanks/resources/user.rb
|
122
|
+
- lib/afterbanks/response.rb
|
123
|
+
- lib/afterbanks/version.rb
|
124
|
+
homepage: https://getquipu.com
|
125
|
+
licenses: []
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.7.6.2
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Ruby client for the Afterbanks' API
|
147
|
+
test_files: []
|