afterbanks-api-ruby 0.1.0
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/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +65 -0
- data/README.md +48 -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 +61 -0
- data/lib/afterbanks/resources/bank.rb +60 -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 +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fa27b556d79a7825b09d17c10a21f9c554d1b05
|
4
|
+
data.tar.gz: a32e2b93047687dc1f97fabb398ebff542863ba4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85b9193d0c31773f937f5915cd23a6a4a4979173a010f643e21e06664db4ea7b6d918ddf06aca5daa65908b5391e2d269830ed099865bb54efad2f7e195199d0
|
7
|
+
data.tar.gz: 8b7bbbf76fbbde4cab9439d4c7266a4d547cb9ab5b2094457549b9dc370a70c1568bb80551ce1996f00abaf953db41cd0e0cda955b5a062f3e400210b8bfc946
|
@@ -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/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
afterbanks-api-ruby (0.1.0)
|
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,48 @@
|
|
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
|
+
Changelog
|
8
|
+
---------
|
9
|
+
|
10
|
+
* v.0.1.0 First vull version, including resource wrapping (for banks, accounts, transactions and the user) and separate exceptions for each different code.
|
11
|
+
|
12
|
+
Installation
|
13
|
+
---------
|
14
|
+
|
15
|
+
Install the gem (`gem install afterbanks-api-ruby`) or include it in your Gemfile and `bundle`.
|
16
|
+
|
17
|
+
Configuration
|
18
|
+
---------
|
19
|
+
|
20
|
+
Just set the service key by doing this:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Afterbanks.servicekey = 'yourservicekey'
|
24
|
+
```
|
25
|
+
|
26
|
+
Or, if you use it in a Rails application, create an initializer with this content:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'afterbanks'
|
30
|
+
|
31
|
+
Afterbanks.configure do |config|
|
32
|
+
config.servicekey = 'yourservicekey'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
You can set a `logger` as well.
|
37
|
+
|
38
|
+
TODO
|
39
|
+
----
|
40
|
+
|
41
|
+
* Full usage for each resource
|
42
|
+
* Proper explanation of the `Afterbanks:Error` and its subclasses
|
43
|
+
|
44
|
+
About Afterbanks
|
45
|
+
------------
|
46
|
+
|
47
|
+
* [Public site](https://www.afterbanks.com)
|
48
|
+
* [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,61 @@
|
|
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
|
+
|
16
|
+
params = {
|
17
|
+
servicekey: Afterbanks.configuration.servicekey,
|
18
|
+
service: service,
|
19
|
+
user: username,
|
20
|
+
pass: password,
|
21
|
+
products: 'GLOBAL'
|
22
|
+
}
|
23
|
+
|
24
|
+
params.merge!(pass2: password2) unless password2.nil?
|
25
|
+
params.merge!(documentType: document_type) unless document_type.nil?
|
26
|
+
params.merge!(session_id: session_id) unless session_id.nil?
|
27
|
+
params.merge!(OTP: otp) unless otp.nil?
|
28
|
+
params.merge!(counterId: counter_id) unless counter_id.nil?
|
29
|
+
|
30
|
+
response, debug_id = Afterbanks.api_call(
|
31
|
+
method: :post,
|
32
|
+
path: '/V3/',
|
33
|
+
params: params
|
34
|
+
)
|
35
|
+
|
36
|
+
Response.new(
|
37
|
+
result: Collection.new(
|
38
|
+
accounts_information_for(
|
39
|
+
response: response,
|
40
|
+
service: service
|
41
|
+
),
|
42
|
+
self
|
43
|
+
),
|
44
|
+
debug_id: debug_id
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def self.accounts_information_for(response:, service:)
|
51
|
+
accounts_information = []
|
52
|
+
|
53
|
+
response.each do |account_information|
|
54
|
+
account_information['service'] = service
|
55
|
+
accounts_information << account_information
|
56
|
+
end
|
57
|
+
|
58
|
+
accounts_information
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
if ordered
|
28
|
+
response.sort! do |bank1, bank2|
|
29
|
+
bank1['fullname'].downcase <=> bank2['fullname'].downcase
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Response.new(
|
34
|
+
result: Collection.new(
|
35
|
+
banks_information_for(
|
36
|
+
response: response
|
37
|
+
),
|
38
|
+
self
|
39
|
+
),
|
40
|
+
debug_id: debug_id
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.banks_information_for(response:)
|
47
|
+
banks_information = []
|
48
|
+
|
49
|
+
response.each do |bank_information|
|
50
|
+
if bank_information['business'] == "1"
|
51
|
+
bank_information['fullname'] += " Empresas"
|
52
|
+
end
|
53
|
+
|
54
|
+
banks_information << bank_information
|
55
|
+
end
|
56
|
+
|
57
|
+
banks_information
|
58
|
+
end
|
59
|
+
end
|
60
|
+
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,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: afterbanks-api-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Albert Bellonch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-28 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
|
+
- ".ruby-version"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- afterbanks.gemspec
|
113
|
+
- lib/afterbanks.rb
|
114
|
+
- lib/afterbanks/base.rb
|
115
|
+
- lib/afterbanks/collection.rb
|
116
|
+
- lib/afterbanks/configuration.rb
|
117
|
+
- lib/afterbanks/error.rb
|
118
|
+
- lib/afterbanks/resource.rb
|
119
|
+
- lib/afterbanks/resources/account.rb
|
120
|
+
- lib/afterbanks/resources/bank.rb
|
121
|
+
- lib/afterbanks/resources/transaction.rb
|
122
|
+
- lib/afterbanks/resources/user.rb
|
123
|
+
- lib/afterbanks/response.rb
|
124
|
+
- lib/afterbanks/version.rb
|
125
|
+
homepage: https://getquipu.com
|
126
|
+
licenses: []
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.6.11
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Ruby client for the Afterbanks' API
|
148
|
+
test_files: []
|