fidor_api 1.0.0 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -49
- data/Rakefile +6 -3
- data/lib/fidor_api/client/authentication.rb +63 -0
- data/lib/fidor_api/client/configuration.rb +32 -0
- data/lib/fidor_api/client/connection.rb +56 -0
- data/lib/fidor_api/client/dsl/confirmable_actions.rb +19 -0
- data/lib/fidor_api/client/dsl/core_data.rb +19 -0
- data/lib/fidor_api/client/dsl/messages.rb +31 -0
- data/lib/fidor_api/client/dsl/transactions.rb +15 -0
- data/lib/fidor_api/client/dsl/transfers/classic.rb +29 -0
- data/lib/fidor_api/client/dsl/transfers/generic.rb +34 -0
- data/lib/fidor_api/client/dsl/transfers.rb +22 -0
- data/lib/fidor_api/client/dsl.rb +59 -0
- data/lib/fidor_api/client.rb +17 -21
- data/lib/fidor_api/collection/kaminari_support.rb +17 -0
- data/lib/fidor_api/collection.rb +18 -34
- data/lib/fidor_api/environment/base.rb +21 -0
- data/lib/fidor_api/environment/fidor_de/production.rb +23 -0
- data/lib/fidor_api/environment/fidor_de/sandbox.rb +23 -0
- data/lib/fidor_api/environment/fidor_de.rb +8 -0
- data/lib/fidor_api/environment/future.rb +21 -0
- data/lib/fidor_api/environment.rb +7 -0
- data/lib/fidor_api/errors.rb +3 -26
- data/lib/fidor_api/model/account.rb +25 -0
- data/lib/fidor_api/model/base.rb +44 -0
- data/lib/fidor_api/model/confirmable_action.rb +9 -0
- data/lib/fidor_api/model/customer.rb +36 -0
- data/lib/fidor_api/model/helpers/action_view_support.rb +21 -0
- data/lib/fidor_api/model/helpers/attribute_decimal_methods.rb +32 -0
- data/lib/fidor_api/model/helpers.rb +8 -0
- data/lib/fidor_api/model/message.rb +23 -0
- data/lib/fidor_api/model/transaction.rb +21 -0
- data/lib/fidor_api/model/transfer/classic/base.rb +15 -0
- data/lib/fidor_api/model/transfer/classic/internal.rb +20 -0
- data/lib/fidor_api/model/transfer/classic/sepa.rb +11 -0
- data/lib/fidor_api/model/transfer/classic.rb +11 -0
- data/lib/fidor_api/model/transfer/generic.rb +71 -0
- data/lib/fidor_api/model/transfer.rb +8 -0
- data/lib/fidor_api/model/user.rb +10 -0
- data/lib/fidor_api/model.rb +13 -0
- data/lib/fidor_api/token.rb +13 -18
- data/lib/fidor_api/version.rb +1 -1
- data/lib/fidor_api.rb +14 -58
- metadata +152 -89
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -20
- data/CHANGELOG.md +0 -129
- data/Gemfile +0 -15
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/fidor_api.gemspec +0 -24
- data/lib/fidor_api/account.rb +0 -45
- data/lib/fidor_api/amount_attributes.rb +0 -30
- data/lib/fidor_api/approval_required.rb +0 -9
- data/lib/fidor_api/auth.rb +0 -45
- data/lib/fidor_api/beneficiary/ach.rb +0 -39
- data/lib/fidor_api/beneficiary/base.rb +0 -118
- data/lib/fidor_api/beneficiary/generic.rb +0 -24
- data/lib/fidor_api/beneficiary/p2p_account_number.rb +0 -14
- data/lib/fidor_api/beneficiary/p2p_phone.rb +0 -14
- data/lib/fidor_api/beneficiary/p2p_username.rb +0 -14
- data/lib/fidor_api/beneficiary/swift.rb +0 -35
- data/lib/fidor_api/beneficiary/unknown.rb +0 -16
- data/lib/fidor_api/beneficiary/utility.rb +0 -35
- data/lib/fidor_api/beneficiary.rb +0 -27
- data/lib/fidor_api/card.rb +0 -77
- data/lib/fidor_api/card_limit_attribute.rb +0 -52
- data/lib/fidor_api/card_limits.rb +0 -14
- data/lib/fidor_api/confirmable_action.rb +0 -45
- data/lib/fidor_api/connectivity/connection.rb +0 -113
- data/lib/fidor_api/connectivity/endpoint.rb +0 -82
- data/lib/fidor_api/connectivity/resource.rb +0 -76
- data/lib/fidor_api/connectivity.rb +0 -17
- data/lib/fidor_api/constants.rb +0 -3
- data/lib/fidor_api/customer.rb +0 -140
- data/lib/fidor_api/customers/confirmations.rb +0 -19
- data/lib/fidor_api/message.rb +0 -52
- data/lib/fidor_api/msisdn.rb +0 -45
- data/lib/fidor_api/password.rb +0 -29
- data/lib/fidor_api/preauth.rb +0 -33
- data/lib/fidor_api/preauth_details.rb +0 -97
- data/lib/fidor_api/session_token.rb +0 -20
- data/lib/fidor_api/transaction.rb +0 -37
- data/lib/fidor_api/transaction_details.rb +0 -119
- data/lib/fidor_api/transfer/ach.rb +0 -46
- data/lib/fidor_api/transfer/bank_internal.rb +0 -37
- data/lib/fidor_api/transfer/base.rb +0 -36
- data/lib/fidor_api/transfer/fps.rb +0 -56
- data/lib/fidor_api/transfer/generic.rb +0 -134
- data/lib/fidor_api/transfer/internal.rb +0 -53
- data/lib/fidor_api/transfer/p2p_account_number.rb +0 -45
- data/lib/fidor_api/transfer/p2p_phone.rb +0 -45
- data/lib/fidor_api/transfer/p2p_username.rb +0 -45
- data/lib/fidor_api/transfer/sepa.rb +0 -56
- data/lib/fidor_api/transfer/swift.rb +0 -49
- data/lib/fidor_api/transfer/utility.rb +0 -50
- data/lib/fidor_api/transfer.rb +0 -17
- data/lib/fidor_api/user.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de8a8afe76c2e2584facd1439e52c087e6d9457119ffd8365ea3bcb2ef418640
|
4
|
+
data.tar.gz: 38d944042a2442defe90265299ec4d14327fa183fa7a2e22e9b5596ca92ecc24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4de4c0de79dfad96ede97a5a15f579459efe9c0a9ef88613a8679728abb69d8fb6b6b1ebe1b0a0f67eb9674369c8d062e9d4d0dee4a64b791aca2a5fb0c272f9
|
7
|
+
data.tar.gz: 927502fe292869143510d492eecfdc013a6955d0d2a4414c8aedff620dba6fd5cfdeb378eb86c8b37c895806f58a146afb2ec9c463e2aec02024451e68bd550b
|
data/README.md
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# FidorApi
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/fidor_api.svg)](https://badge.fury.io/rb/fidor_api)
|
4
|
-
[![Build Status](https://travis-ci.org/fidor/fidor_api.svg?branch=
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/fidor/fidor_api/badges/coverage.svg)](https://codeclimate.com/github/fidor/fidor_api/coverage)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/fidor/fidor_api/badges/gpa.svg)](https://codeclimate.com/github/fidor/fidor_api)
|
4
|
+
[![Build Status](https://travis-ci.org/fidor/fidor_api.svg?branch=v2)](https://travis-ci.org/fidor/fidor_api)
|
7
5
|
|
8
|
-
|
6
|
+
Ruby client library to work with Fidor APIs.
|
9
7
|
|
10
|
-
💡 This branch contains the
|
8
|
+
💡 This branch contains the `2.x.x` version. For previous versions see `v1` branch.
|
11
9
|
|
12
10
|
## Installation
|
13
11
|
|
14
12
|
Add this line to your application's Gemfile:
|
15
13
|
|
16
14
|
```ruby
|
17
|
-
gem 'fidor_api'
|
15
|
+
gem 'fidor_api', '>= 2'
|
18
16
|
```
|
19
17
|
|
20
18
|
And then execute:
|
@@ -30,15 +28,10 @@ Or install it yourself as:
|
|
30
28
|
### 0. Configure
|
31
29
|
|
32
30
|
```ruby
|
33
|
-
FidorApi.
|
34
|
-
config.
|
35
|
-
config.
|
36
|
-
config.
|
37
|
-
config.client_id = ENV["FIDOR_API_CLIENT_ID"]
|
38
|
-
config.client_secret = ENV["FIDOR_API_CLIENT_SECRET"]
|
39
|
-
config.htauth_user = ENV["FIDOR_API_HTAUTH_USER"]
|
40
|
-
config.htauth_password = ENV["FIDOR_API_HTAUTH_PASSWORD"]
|
41
|
-
config.affiliate_uid = ENV["FIDOR_API_AFFILIATE_UID"]
|
31
|
+
client = FidorApi::Client.new do |config|
|
32
|
+
config.environment = FidorApi::Environment::FidorDE::Sandbox
|
33
|
+
config.client_id = 'your-client-id'
|
34
|
+
config.client_secret = 'your-client-secret'
|
42
35
|
end
|
43
36
|
```
|
44
37
|
|
@@ -47,60 +40,48 @@ end
|
|
47
40
|
Redirect the user to the authorize URL:
|
48
41
|
|
49
42
|
```ruby
|
50
|
-
redirect_to
|
43
|
+
redirect_to client.authorize_start(
|
44
|
+
redirect_uri: 'https://localhost:3000/callback'
|
45
|
+
)
|
51
46
|
```
|
52
47
|
|
53
48
|
Use code passed to the callback URL and fetch the access token:
|
54
49
|
|
55
50
|
```ruby
|
56
|
-
session[:api_token] =
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
def api_token
|
63
|
-
FidorApi::Token.new session[:api_token] if session[:api_token]
|
64
|
-
end
|
65
|
-
|
66
|
-
if api_token && !api_token.valid?
|
67
|
-
session[:api_token] = FidorApi::Auth.refresh_token(api_token).to_hash
|
68
|
-
end
|
51
|
+
session[:api_token] = client.authorize_complete(
|
52
|
+
redirect_uri: 'https://localhost:3000/callback',
|
53
|
+
code: params[:code]
|
54
|
+
)
|
69
55
|
```
|
70
56
|
|
71
57
|
### 2. Fetching data
|
72
58
|
|
73
59
|
```ruby
|
74
|
-
|
60
|
+
client.token = FidorApi::Token.new(session[:api_token])
|
75
61
|
|
76
|
-
user =
|
77
|
-
# => FidorApi::User
|
62
|
+
user = client.user
|
63
|
+
# => FidorApi::Model::User
|
78
64
|
|
79
|
-
|
65
|
+
user = client.transactions
|
80
66
|
# => FidorApi::Collection
|
81
67
|
|
82
68
|
transaction = transactions.first
|
83
|
-
# => FidorApi::Transaction
|
69
|
+
# => FidorApi::Model::Transaction
|
84
70
|
```
|
85
71
|
|
86
72
|
### 3. Creating transfers
|
87
73
|
|
88
74
|
```ruby
|
89
|
-
|
75
|
+
client.token = FidorApi::Token.new(session[:api_token])
|
90
76
|
|
91
|
-
transfer =
|
77
|
+
transfer = client.create_internal_transfer(
|
92
78
|
account_id: 875,
|
93
|
-
receiver:
|
94
|
-
external_uid:
|
95
|
-
subject:
|
79
|
+
receiver: 'kycfull@fidor.de',
|
80
|
+
external_uid: '4279762F5',
|
81
|
+
subject: 'Money for you',
|
96
82
|
amount: 1000
|
97
83
|
)
|
98
|
-
# => FidorApi::Transfer::Internal
|
99
|
-
|
100
|
-
transfer.save
|
101
|
-
# => true
|
102
|
-
# or
|
103
|
-
# => false and `transfer.errors` containing details
|
84
|
+
# => FidorApi::Model::Transfer::Classic::Internal
|
104
85
|
```
|
105
86
|
|
106
87
|
## Development
|
@@ -113,10 +94,6 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
113
94
|
|
114
95
|
Bug reports and pull requests are welcome on GitHub at https://github.com/fidor/fidor_api.
|
115
96
|
|
116
|
-
## Changelog
|
117
|
-
|
118
|
-
Have a look at the [CHANGELOG](CHANGELOG.md) for details.
|
119
|
-
|
120
97
|
## License
|
121
98
|
|
122
99
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
task :default
|
6
|
+
task :default do
|
7
|
+
system('bundle exec rspec')
|
8
|
+
system('bundle exec rubocop')
|
9
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module Authentication
|
4
|
+
attr_accessor :token
|
5
|
+
|
6
|
+
# oAuth2 - Resource Owner Password Grant Flow
|
7
|
+
def login(username:, password:, grant_type: 'password')
|
8
|
+
check_flow_support! :resource_owner_password_credentials
|
9
|
+
|
10
|
+
self.token = oauth_token(
|
11
|
+
grant_type: grant_type,
|
12
|
+
username: username,
|
13
|
+
password: password
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# oAuth2 - Client Credentials Flow
|
18
|
+
def client_login
|
19
|
+
check_flow_support! :client_credentials
|
20
|
+
|
21
|
+
self.token = oauth_token(grant_type: 'client_credentials')
|
22
|
+
end
|
23
|
+
|
24
|
+
# oAuth2 - Authorization Code Grant Flow - Start
|
25
|
+
def authorize_start(redirect_uri:, state: SecureRandom.hex(8))
|
26
|
+
check_flow_support! :authorization_code
|
27
|
+
|
28
|
+
"#{config.environment.auth_host}/oauth/authorize" \
|
29
|
+
+ "?client_id=#{config.client_id}" \
|
30
|
+
+ "&redirect_uri=#{CGI.escape(redirect_uri)}" \
|
31
|
+
+ "&state=#{state}" \
|
32
|
+
+ '&response_type=code'
|
33
|
+
end
|
34
|
+
|
35
|
+
# oAuth2 - Authorization Code Grant Flow - Complete
|
36
|
+
def authorize_complete(redirect_uri:, code:)
|
37
|
+
self.token = oauth_token(
|
38
|
+
grant_type: 'authorization_code',
|
39
|
+
client_id: config.client_id,
|
40
|
+
redirect_uri: redirect_uri,
|
41
|
+
code: code
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def check_flow_support!(symbol)
|
48
|
+
raise Errors::NotSupported \
|
49
|
+
unless config.environment.auth_methods.include? symbol
|
50
|
+
end
|
51
|
+
|
52
|
+
def oauth_token(**body)
|
53
|
+
response = connection(host: config.environment.auth_host).post(
|
54
|
+
'/oauth/token',
|
55
|
+
body: body,
|
56
|
+
auth: [config.client_id, config.client_secret]
|
57
|
+
)
|
58
|
+
|
59
|
+
Token.new(response.body)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module FidorApi
|
4
|
+
class Client
|
5
|
+
class Configuration
|
6
|
+
ATTRIBUTES = %i[
|
7
|
+
environment
|
8
|
+
client_id
|
9
|
+
client_secret
|
10
|
+
logger
|
11
|
+
log_bodies
|
12
|
+
verify_ssl
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
attr_accessor(*ATTRIBUTES)
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
self.environment = Environment::FidorDE::Sandbox.new
|
19
|
+
self.logger = Logger.new(STDOUT)
|
20
|
+
self.log_bodies = true
|
21
|
+
self.verify_ssl = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate!
|
25
|
+
ATTRIBUTES.each do |key|
|
26
|
+
raise "Missing config value for `#{key}`!" \
|
27
|
+
if instance_variable_get("@#{key}").nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
class Connection
|
4
|
+
DEFAULT_HEADERS = {
|
5
|
+
'Accept' => 'application/vnd.fidor.de; version=1,text/json',
|
6
|
+
'Content-Type' => 'application/json'
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
def initialize(client:, host:)
|
10
|
+
@client = client
|
11
|
+
@host = host
|
12
|
+
end
|
13
|
+
|
14
|
+
%i[get post put patch delete].each do |method|
|
15
|
+
define_method method do |path, query: nil, body: nil, headers: {}, auth: nil|
|
16
|
+
request(
|
17
|
+
path: path,
|
18
|
+
method: method,
|
19
|
+
query: query,
|
20
|
+
body: body,
|
21
|
+
headers: DEFAULT_HEADERS.merge(headers),
|
22
|
+
auth: auth
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_accessor :client, :host
|
30
|
+
|
31
|
+
def request(path:, method: :get, query: {}, body: {}, headers: {}, auth: nil) # rubocop:disable Metrics/ParameterLists
|
32
|
+
payload = method == :get ? query : body&.to_json
|
33
|
+
|
34
|
+
response = faraday(auth: auth).public_send(method, path, payload) do |request|
|
35
|
+
request.headers = headers
|
36
|
+
end
|
37
|
+
|
38
|
+
response
|
39
|
+
rescue Faraday::ClientError => e
|
40
|
+
client.config.logger.error e.inspect
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
|
44
|
+
def faraday(auth:) # rubocop:disable Metrics/AbcSize
|
45
|
+
Faraday.new(url: host, ssl: { verify: client.config.verify_ssl }) do |config|
|
46
|
+
config.use Faraday::Request::BasicAuthentication, *auth if auth.is_a? Array
|
47
|
+
config.request :oauth2, client.token.access_token, token_type: :bearer if client.token
|
48
|
+
config.response :logger, client.config.logger, bodies: client.config.log_bodies if client.config.logger
|
49
|
+
config.response :raise_error
|
50
|
+
config.response :json, content_type: /json/
|
51
|
+
config.adapter Faraday.default_adapter
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module ConfirmableActions
|
5
|
+
def confirmable_action(id, options = {})
|
6
|
+
fetch(:single, Model::ConfirmableAction, "/confirmable/actions/#{id}", options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def refresh_confirmable_action(id, options = {})
|
10
|
+
update(Model::ConfirmableAction, "/confirmable/actions/#{id}/refresh", id, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_confirmable_action(id, attributes = {})
|
14
|
+
update(Model::ConfirmableAction, "/confirmable/actions/#{id}", id, attributes)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module CoreData
|
5
|
+
def user(options = {})
|
6
|
+
fetch(:single, Model::User, '/users/current', options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def customers(options = {})
|
10
|
+
fetch(:collection, Model::Customer, '/customers', options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def accounts(options = {})
|
14
|
+
fetch(:collection, Model::Account, '/accounts', options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module Messages
|
5
|
+
def messages(options = {})
|
6
|
+
fetch(:collection, Model::Message, '/messages', options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def message(id, options = {})
|
10
|
+
fetch(:single, Model::Message, "/messages/#{id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def message_attachment(id)
|
14
|
+
response = connection.get("/messages/#{id}/attachment")
|
15
|
+
|
16
|
+
Model::Message::Attachment.new(
|
17
|
+
type: response.headers['content-type'],
|
18
|
+
filename: response.headers['content-disposition'][/filename="([^"]+)"/, 1],
|
19
|
+
content: response.body
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def message_content(id)
|
24
|
+
response = connection.get("/messages/#{id}/content")
|
25
|
+
|
26
|
+
Model::Message::Content.new(raw: response.body)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module Transactions
|
5
|
+
def transactions(options = {})
|
6
|
+
fetch(:collection, Model::Transaction, '/transactions', options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def transaction(id, options = {})
|
10
|
+
fetch(:single, Model::Transaction, "/transactions/#{id}", options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module Transfers
|
5
|
+
module Classic
|
6
|
+
def internal_transfers(options = {})
|
7
|
+
check_transfer_support! :classic
|
8
|
+
fetch(:collection, FidorApi::Model::Transfer::Classic::Internal, '/internal_transfers', options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def internal_transfer(id, options = {})
|
12
|
+
check_transfer_support! :classic
|
13
|
+
fetch(:single, FidorApi::Model::Transfer::Classic::Internal, "/internal_transfers/#{id}", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def new_internal_transfer(attributes = {})
|
17
|
+
check_transfer_support! :classic
|
18
|
+
Model::Transfer::Classic::Internal.new(attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_internal_transfer(attributes = {})
|
22
|
+
check_transfer_support! :classic
|
23
|
+
create(FidorApi::Model::Transfer::Classic::Internal, '/internal_transfers', attributes)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module Transfers
|
5
|
+
module Generic
|
6
|
+
def transfers(options = {})
|
7
|
+
check_transfer_support! :generic
|
8
|
+
fetch(:collection, FidorApi::Model::Transfer::Generic, '/transfers', options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def transfer(id, options = {})
|
12
|
+
check_transfer_support! :generic
|
13
|
+
fetch(:single, FidorApi::Model::Transfer::Generic, "/transfers/#{id}", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def new_transfer(attributes = {})
|
17
|
+
check_transfer_support! :generic
|
18
|
+
Model::Transfer::Generic.new(attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_transfer(attributes = {})
|
22
|
+
check_transfer_support! :generic
|
23
|
+
create(FidorApi::Model::Transfer::Generic, '/transfers', attributes)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_transfer(id, attributes = {})
|
27
|
+
check_transfer_support! :generic
|
28
|
+
update(FidorApi::Model::Transfer::Generic, "/transfers/#{id}", id, attributes)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
module Transfers
|
5
|
+
autoload :Classic, 'fidor_api/client/dsl/transfers/classic'
|
6
|
+
autoload :Generic, 'fidor_api/client/dsl/transfers/generic'
|
7
|
+
|
8
|
+
def self.included(klass)
|
9
|
+
klass.include Transfers::Classic
|
10
|
+
klass.include Transfers::Generic
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def check_transfer_support!(type)
|
16
|
+
raise Errors::NotSupported \
|
17
|
+
unless config.environment.transfers_api == type
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module FidorApi
|
2
|
+
class Client
|
3
|
+
module DSL
|
4
|
+
autoload :ConfirmableActions, 'fidor_api/client/dsl/confirmable_actions'
|
5
|
+
autoload :CoreData, 'fidor_api/client/dsl/core_data'
|
6
|
+
autoload :Messages, 'fidor_api/client/dsl/messages'
|
7
|
+
autoload :Transfers, 'fidor_api/client/dsl/transfers'
|
8
|
+
autoload :Transactions, 'fidor_api/client/dsl/transactions'
|
9
|
+
|
10
|
+
def self.included(klass)
|
11
|
+
klass.include ConfirmableActions
|
12
|
+
klass.include CoreData
|
13
|
+
klass.include Messages
|
14
|
+
klass.include Transfers
|
15
|
+
klass.include Transactions
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def fetch(type, klass, endpoint, options)
|
21
|
+
case type
|
22
|
+
when :single
|
23
|
+
klass.new(connection.get(endpoint, query: options).body)
|
24
|
+
when :collection
|
25
|
+
Collection.new(klass: klass, raw: connection.get(endpoint, query: options).body)
|
26
|
+
else
|
27
|
+
raise ArgumentError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(klass, endpoint, attributes)
|
32
|
+
request(klass, endpoint, :post, attributes)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update(klass, endpoint, id, attributes)
|
36
|
+
request(klass, endpoint, :put, attributes.merge(id: id))
|
37
|
+
end
|
38
|
+
|
39
|
+
def request(klass, endpoint, method, attributes) # rubocop:disable Metrics/AbcSize
|
40
|
+
model = klass.new(attributes)
|
41
|
+
model.tap do |m|
|
42
|
+
response = connection.public_send(method, endpoint, body: m.as_json)
|
43
|
+
m.set_attributes(response.body) if response.body.is_a?(Hash)
|
44
|
+
m.confirmable_action_id = extract_confirmable_id(response.headers)
|
45
|
+
end
|
46
|
+
rescue Faraday::ClientError => e
|
47
|
+
raise if e.response[:status] != 422
|
48
|
+
model.tap { |m| m.parse_errors(e.response[:body]) }
|
49
|
+
end
|
50
|
+
|
51
|
+
POSSIBLE_CONFIRMABLE_HEADERS = %w[x-fidor-confirmation-path location].freeze
|
52
|
+
|
53
|
+
def extract_confirmable_id(headers)
|
54
|
+
return if (tuple = headers.detect { |key, _| POSSIBLE_CONFIRMABLE_HEADERS.include? key }).nil?
|
55
|
+
tuple.last.split('/').last
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/fidor_api/client.rb
CHANGED
@@ -1,27 +1,23 @@
|
|
1
1
|
module FidorApi
|
2
|
-
|
3
2
|
class Client
|
4
|
-
|
3
|
+
autoload :Authentication, 'fidor_api/client/authentication'
|
4
|
+
autoload :Configuration, 'fidor_api/client/configuration'
|
5
|
+
autoload :Connection, 'fidor_api/client/connection'
|
6
|
+
autoload :DSL, 'fidor_api/client/dsl'
|
5
7
|
|
6
|
-
|
8
|
+
include Authentication
|
9
|
+
include DSL
|
7
10
|
|
8
|
-
|
9
|
-
include Beneficiary::ClientSupport
|
10
|
-
include Beneficiary::ACH::ClientSupport
|
11
|
-
include ConfirmableAction::ClientSupport
|
12
|
-
include Customer::ClientSupport
|
13
|
-
include Message::ClientSupport
|
14
|
-
include Preauth::ClientSupport
|
15
|
-
include SessionToken::ClientSupport
|
16
|
-
include Transaction::ClientSupport
|
17
|
-
include Transfer::ACH::ClientSupport
|
18
|
-
include Transfer::Internal::ClientSupport
|
19
|
-
include Transfer::SEPA::ClientSupport
|
20
|
-
include Transfer::FPS::ClientSupport
|
21
|
-
include Transfer::P2pAccountNumber::ClientSupport
|
22
|
-
include Transfer::P2pPhone::ClientSupport
|
23
|
-
include Transfer::P2pUsername::ClientSupport
|
24
|
-
include User::ClientSupport
|
25
|
-
end
|
11
|
+
attr_accessor :config
|
26
12
|
|
13
|
+
def initialize
|
14
|
+
self.config = Configuration.new
|
15
|
+
yield(config) if block_given?
|
16
|
+
config.validate!
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection(host: config.environment.api_host)
|
20
|
+
Connection.new(client: self, host: host)
|
21
|
+
end
|
22
|
+
end
|
27
23
|
end
|
data/lib/fidor_api/collection.rb
CHANGED
@@ -1,46 +1,30 @@
|
|
1
1
|
module FidorApi
|
2
|
-
|
3
2
|
class Collection
|
4
|
-
|
5
|
-
include Enumerable
|
6
|
-
|
7
|
-
attr_accessor :records
|
8
|
-
attr_accessor :total_pages, :current_page, :limit_value, :total_entries
|
9
|
-
|
10
|
-
def self.build(klass, response)
|
11
|
-
new.tap do |object|
|
12
|
-
data = response["data"]
|
13
|
-
collection = response["collection"]
|
14
|
-
|
15
|
-
object.records = data.map do |record|
|
16
|
-
class_to_instantiate = if block_given?
|
17
|
-
yield(record)
|
18
|
-
else
|
19
|
-
klass
|
20
|
-
end
|
3
|
+
autoload :KaminariSupport, 'fidor_api/collection/kaminari_support'
|
21
4
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
include Enumerable
|
6
|
+
include KaminariSupport
|
7
|
+
|
8
|
+
attr_reader \
|
9
|
+
:current_page,
|
10
|
+
:per_page,
|
11
|
+
:total_entries,
|
12
|
+
:total_pages
|
13
|
+
|
14
|
+
def initialize(klass:, raw:)
|
15
|
+
@current_page = raw.fetch('collection').fetch('current_page')
|
16
|
+
@per_page = raw.fetch('collection').fetch('per_page')
|
17
|
+
@total_entries = raw.fetch('collection').fetch('total_entries')
|
18
|
+
@total_pages = raw.fetch('collection').fetch('total_pages')
|
19
|
+
@records = raw.fetch('data').map { |attributes| klass.new(attributes) }
|
30
20
|
end
|
31
21
|
|
32
22
|
def each(&block)
|
33
23
|
records.each(&block)
|
34
24
|
end
|
35
25
|
|
36
|
-
|
37
|
-
def last_page?
|
38
|
-
current_page == total_pages
|
39
|
-
end
|
26
|
+
private
|
40
27
|
|
41
|
-
|
42
|
-
current_page + 1
|
43
|
-
end
|
28
|
+
attr_reader :records
|
44
29
|
end
|
45
|
-
|
46
30
|
end
|