bloom_remit_client 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +6 -2
- data/CHANGELOG.md +8 -0
- data/README.md +3 -7
- data/bloom_remit_client.gemspec +1 -0
- data/lib/bloom_remit_client/client.rb +78 -22
- data/lib/bloom_remit_client/coercers/path.rb +11 -0
- data/lib/bloom_remit_client/concerns/has_base_authentification.rb +15 -0
- data/lib/bloom_remit_client/models/credit.rb +12 -0
- data/lib/bloom_remit_client/models/recipient.rb +17 -0
- data/lib/bloom_remit_client/models/remittance.rb +22 -0
- data/lib/bloom_remit_client/requests/base.rb +49 -0
- data/lib/bloom_remit_client/requests/billers/list.rb +21 -0
- data/lib/bloom_remit_client/requests/credit/history.rb +18 -0
- data/lib/bloom_remit_client/requests/credit/list.rb +18 -0
- data/lib/bloom_remit_client/requests/payments/create.rb +29 -0
- data/lib/bloom_remit_client/requests/rate/show.rb +26 -0
- data/lib/bloom_remit_client/requests/recipients/create.rb +30 -0
- data/lib/bloom_remit_client/requests/remittances/create.rb +30 -0
- data/lib/bloom_remit_client/requests/requests_sender.rb +27 -0
- data/lib/bloom_remit_client/requests/senders/create.rb +27 -0
- data/lib/bloom_remit_client/requests/url_builder.rb +51 -0
- data/lib/bloom_remit_client/requests.rb +18 -0
- data/lib/bloom_remit_client/responses/base.rb +31 -0
- data/lib/bloom_remit_client/responses/billers/list.rb +17 -0
- data/lib/bloom_remit_client/responses/payments/create.rb +17 -0
- data/lib/bloom_remit_client/responses/recipients/create.rb +20 -0
- data/lib/bloom_remit_client/responses/remittances/create.rb +20 -0
- data/lib/bloom_remit_client/responses/senders/create.rb +21 -0
- data/lib/bloom_remit_client/version.rb +1 -1
- data/lib/bloom_remit_client.rb +40 -13
- metadata +39 -10
- data/lib/bloom_remit_client/requests/base_request.rb +0 -29
- data/lib/bloom_remit_client/requests/billers_request.rb +0 -17
- data/lib/bloom_remit_client/requests/create_payment_request.rb +0 -30
- data/lib/bloom_remit_client/requests/create_sender_request.rb +0 -23
- data/lib/bloom_remit_client/responses/base_response.rb +0 -29
- data/lib/bloom_remit_client/responses/billers_response.rb +0 -13
- data/lib/bloom_remit_client/responses/create_payment_response.rb +0 -13
- data/lib/bloom_remit_client/responses/create_sender_response.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aa72dd929a84719317015b974e91bd7a94cf50c
|
4
|
+
data.tar.gz: d46e17cc17b58475aace9fa894dbe77f5f2a1d20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 198399971aef5c0fd6ce5edd5ecebb8765930e6634af69241802a88bee378ccb2e17e33cdff39d4daedd1c4ab92022c1d73c413a88070359c7425a506cfb52eb
|
7
|
+
data.tar.gz: 28e0e4d2492a0b6c1d98eb837c08fcbda124a7d5df36f35d427ad0a84839dd5760131066c4432ee1285c85dedc04d37c623f01225f2cb5f6f0618242f7400595
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.3.
|
1
|
+
ruby-2.3.1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.5.0] - 2016-09-15
|
6
|
+
### Changed
|
7
|
+
- Structure of files to more easily add new endpoints
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- `rates` endpoint
|
11
|
+
- Add method to create remittances
|
12
|
+
|
5
13
|
## [0.4.0] - 2016-09-01
|
6
14
|
### Added
|
7
15
|
- Made response `#success` a virtus attribute, so that it can be set in factories
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# BloomRemitClient
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Ruby wrapper for BloomRemit's API.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,7 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
See `spec/functional` for examples.
|
26
24
|
|
27
25
|
## Factories
|
28
26
|
|
@@ -36,10 +34,8 @@ To make testing easier, you may `require 'bloom_remit_client/factories'` in your
|
|
36
34
|
|
37
35
|
## Contributing
|
38
36
|
|
39
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
40
|
-
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/imacchiato/bloom_remit_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
41
38
|
|
42
39
|
## License
|
43
40
|
|
44
41
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
45
|
-
|
data/bloom_remit_client.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency "activemodel"
|
30
30
|
spec.add_dependency "activesupport"
|
31
31
|
spec.add_dependency "httparty"
|
32
|
+
spec.add_dependency "addressable"
|
32
33
|
|
33
34
|
spec.add_development_dependency "bundler", "~> 1.12"
|
34
35
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,40 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module BloomRemitClient
|
2
3
|
class Client
|
3
|
-
|
4
4
|
include Virtus.model
|
5
|
-
|
6
|
-
|
5
|
+
include ActiveModel::Validations
|
6
|
+
|
7
|
+
attribute :api_token, String
|
8
|
+
attribute :api_secret, String
|
7
9
|
attribute :agent_id, String
|
8
|
-
attribute :url, String
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
validates :api_token, :api_secret, presence: true
|
12
|
+
|
13
|
+
# GET
|
14
|
+
# /api/v1/partners/:api_token/credits
|
15
|
+
# Parameters: none
|
16
|
+
def credits(params = {})
|
17
|
+
request_params = params.merge(access_params)
|
18
|
+
Requests::Credit::List.new(request_params).()
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET
|
22
|
+
# /api/v1/partners/:api_token/credits/history
|
23
|
+
# Parameters: none
|
24
|
+
def credits_history(params = {})
|
25
|
+
request_params = params.merge(access_params)
|
26
|
+
Requests::Credit::History.new(request_params).()
|
27
|
+
end
|
12
28
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
29
|
+
# GET
|
30
|
+
# /api/v1/rates
|
31
|
+
# Parameters:
|
32
|
+
# partner_id:
|
33
|
+
# String, required
|
34
|
+
# API token
|
35
|
+
# api_secret:
|
36
|
+
# String, required
|
37
|
+
# currency:
|
38
|
+
# One of: [USDPHP, USDUSD, USDKRW, USDAUD, USDCAD, USDJPY, USDNZD, USDSGD, USDHKD,
|
39
|
+
# USDCNY, USDEUR, USDVND, USDSAR, USDTWD, USDQAR, USDKWD, USDAED, USDGBP,
|
40
|
+
# USDMYR, USDINR, USDIDR, USDBTC],
|
41
|
+
# optional
|
42
|
+
def rates(params = {})
|
43
|
+
request_params = params.merge(access_params)
|
44
|
+
Requests::Rate::Show.new(request_params).()
|
17
45
|
end
|
18
46
|
|
19
|
-
def
|
20
|
-
|
21
|
-
raw_response =
|
22
|
-
|
47
|
+
def billers(params={})
|
48
|
+
request_params = params.merge(access_params)
|
49
|
+
raw_response = Requests::Billers::List.new(request_params).()
|
50
|
+
Responses::Billers::List.new(raw_response: raw_response)
|
23
51
|
end
|
24
52
|
|
25
|
-
def
|
26
|
-
params =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
53
|
+
def create_sender(sender_params={})
|
54
|
+
params = {sender: sender_params}
|
55
|
+
request_params = params.merge(default_params).merge(access_params)
|
56
|
+
raw_response = Requests::Senders::Create.new(request_params).()
|
57
|
+
Responses::Senders::Create.new(raw_response: raw_response)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_payment(payment_params={})
|
61
|
+
params = {payment: payment_params}.
|
62
|
+
merge(sender_id: payment_params[:sender_id])
|
63
|
+
request_params = params.merge(default_params).merge(access_params)
|
64
|
+
raw_response = Requests::Payments::Create.new(request_params).()
|
65
|
+
Responses::Payments::Create.new(raw_response: raw_response)
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_recipient(recipient_params={})
|
69
|
+
params = {recipient: recipient_params}.
|
70
|
+
merge(sender_id: recipient_params[:sender_id])
|
71
|
+
request_params = params.merge(default_params).merge(access_params)
|
72
|
+
raw_response = Requests::Recipients::Create.new(request_params).()
|
73
|
+
Responses::Recipients::Create.new(raw_response: raw_response)
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_remittance(remittance_params={})
|
77
|
+
params = {remittance: remittance_params}.
|
78
|
+
merge(sender_id: remittance_params[:sender_id]).
|
79
|
+
merge(recipient_id: remittance_params[:recipient_id])
|
80
|
+
request_params = params.merge(default_params).merge(access_params)
|
81
|
+
raw_response = Requests::Remittances::Create.new(request_params).()
|
82
|
+
Responses::Remittances::Create.new(raw_response: raw_response)
|
31
83
|
end
|
32
84
|
|
33
85
|
private
|
34
86
|
|
35
|
-
|
36
|
-
|
87
|
+
# Should overwrite any other `:api_token`, `:api_secret`
|
88
|
+
def access_params
|
89
|
+
@access_params ||= attributes.slice(:api_token, :api_secret)
|
37
90
|
end
|
38
91
|
|
92
|
+
def default_params
|
93
|
+
@default_params ||= attributes.slice(:agent_id)
|
94
|
+
end
|
39
95
|
end
|
40
96
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Concerns
|
4
|
+
module HasBaseAuthentification
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
attribute :api_token, String
|
8
|
+
attribute :api_secret, String
|
9
|
+
|
10
|
+
validates :api_token, :api_secret, presence: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
class Recipient
|
3
|
+
|
4
|
+
include Virtus.model
|
5
|
+
attribute :id, String
|
6
|
+
attribute :first_name, String
|
7
|
+
attribute :last_name, String
|
8
|
+
attribute :mobile, String
|
9
|
+
attribute :email, String
|
10
|
+
attribute :address, String
|
11
|
+
attribute :city, String
|
12
|
+
attribute :state, String
|
13
|
+
attribute :country, String
|
14
|
+
attribute :postal_code, String
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
class Remittance
|
3
|
+
|
4
|
+
include Virtus.model
|
5
|
+
attribute :id, String
|
6
|
+
attribute :recipient_id, String
|
7
|
+
attribute :orig_currency, String
|
8
|
+
attribute :dest_currency, String
|
9
|
+
attribute :paid_in_orig_currency, Float
|
10
|
+
attribute :receivable_in_dest_currency, Float
|
11
|
+
attribute :status, String
|
12
|
+
attribute :payout_method, String
|
13
|
+
attribute :partner_id, String
|
14
|
+
attribute :flat_fee_in_orig_currency, Float
|
15
|
+
attribute :forex_margin, Float
|
16
|
+
attribute :account_name, String
|
17
|
+
attribute :account_number, String
|
18
|
+
attribute :callback_url, String
|
19
|
+
attribute :sender_id, String
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
class Base
|
5
|
+
include Virtus.model
|
6
|
+
include ActiveModel::Validations
|
7
|
+
include Concerns::HasBaseAuthentification
|
8
|
+
|
9
|
+
def call
|
10
|
+
RequestsSender.new(params).()
|
11
|
+
end
|
12
|
+
|
13
|
+
def params
|
14
|
+
{
|
15
|
+
type: type,
|
16
|
+
body: body,
|
17
|
+
url: {
|
18
|
+
host: ::BloomRemitClient.host,
|
19
|
+
path: path,
|
20
|
+
query_params: query_params
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def type
|
28
|
+
raise NotImplementedError, 'For subclass only!'
|
29
|
+
end
|
30
|
+
|
31
|
+
def path
|
32
|
+
raise NotImplementedError, 'For subclass only!'
|
33
|
+
end
|
34
|
+
|
35
|
+
def body
|
36
|
+
return unless body_params.present?
|
37
|
+
body_params.to_json
|
38
|
+
end
|
39
|
+
|
40
|
+
def body_params
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
|
44
|
+
def query_params
|
45
|
+
attributes.slice(:api_secret)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
module Credit
|
5
|
+
class History < Requests::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def type
|
9
|
+
Requests::GET
|
10
|
+
end
|
11
|
+
|
12
|
+
def path
|
13
|
+
Requests.normalize_path(::BloomRemitClient::Credit::PATH, attributes.slice(:api_token), 'history')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
module Credit
|
5
|
+
class List < Requests::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def type
|
9
|
+
Requests::GET
|
10
|
+
end
|
11
|
+
|
12
|
+
def path
|
13
|
+
Requests.normalize_path(::BloomRemitClient::Credit::PATH, attributes.slice(:api_token))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Requests
|
3
|
+
module Payments
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
PATH = "/api/v2/payments.json"
|
7
|
+
|
8
|
+
attribute :payment, Hash
|
9
|
+
attribute :sender_id, String
|
10
|
+
attribute :agent_id, String
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def path
|
15
|
+
PATH
|
16
|
+
end
|
17
|
+
|
18
|
+
def type
|
19
|
+
POST
|
20
|
+
end
|
21
|
+
|
22
|
+
def body_params
|
23
|
+
attributes.slice(*%i[api_token agent_id sender_id payment])
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
module Rate
|
5
|
+
class Show < Requests::Base
|
6
|
+
PATH = '/api/v1/rates'
|
7
|
+
|
8
|
+
attribute :currency, String
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def type
|
13
|
+
Requests::GET
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
PATH
|
18
|
+
end
|
19
|
+
|
20
|
+
def query_params
|
21
|
+
attributes.slice(:api_secret, :currency).merge(partner_id: api_token)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Requests
|
3
|
+
module Recipients
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
PATH = "/api/v1/partners/:api_token/senders/:sender_id/recipients.json"
|
7
|
+
|
8
|
+
attribute :recipient, Hash
|
9
|
+
attribute :agent_id, String
|
10
|
+
attribute :sender_id, String
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def path
|
15
|
+
PATH.gsub(":api_token", self.api_token).
|
16
|
+
gsub(":sender_id", self.sender_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def type
|
20
|
+
POST
|
21
|
+
end
|
22
|
+
|
23
|
+
def body_params
|
24
|
+
attributes.slice(*%i[agent_id recipient])
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Requests
|
3
|
+
module Remittances
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
PATH = "/api/v1//partners/:api_token/senders/:sender_id/remittances.json"
|
7
|
+
|
8
|
+
attribute :remittance, Hash
|
9
|
+
attribute :sender_id, String
|
10
|
+
attribute :recipient_id, String
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def path
|
15
|
+
PATH.gsub(":api_token", self.api_token).
|
16
|
+
gsub(":sender_id", self.sender_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def type
|
20
|
+
POST
|
21
|
+
end
|
22
|
+
|
23
|
+
def body_params
|
24
|
+
attributes.slice(*%i[recipient_id remittance])
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
class RequestsSender
|
5
|
+
include Virtus.model
|
6
|
+
include ActiveModel::Validations
|
7
|
+
|
8
|
+
attribute :type, String
|
9
|
+
attribute :body, String
|
10
|
+
attribute :headers, Hash, lazy: true, default: ->(object, attribute) { RequestsSender.default_headers }
|
11
|
+
attribute :url, Requests::UrlBuilder
|
12
|
+
|
13
|
+
validates :type, presence: true, inclusion: Requests::REQUEST_TYPES
|
14
|
+
|
15
|
+
def self.default_headers
|
16
|
+
@default_headers ||= {
|
17
|
+
'Content-Type' => Requests::CONTENT_TYPE_JSON_UTF8,
|
18
|
+
'Accept' => Requests::CONTENT_TYPE_JSON
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
HTTParty.send(type, url.(), body: body, headers: headers)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Requests
|
3
|
+
module Senders
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
PATH = "/api/v1/partners/:token/senders.json"
|
7
|
+
|
8
|
+
attribute :sender, Hash
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def path
|
13
|
+
PATH.gsub(":token", self.api_token)
|
14
|
+
end
|
15
|
+
|
16
|
+
def type
|
17
|
+
POST
|
18
|
+
end
|
19
|
+
|
20
|
+
def body_params
|
21
|
+
{ sender: sender }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
class UrlBuilder
|
5
|
+
require 'addressable/uri'
|
6
|
+
include Virtus.model
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
attribute :scheme, String, default: 'https'
|
10
|
+
attribute :subdomain, String
|
11
|
+
attribute :userinfo, String
|
12
|
+
attribute :path, Coercers::Path
|
13
|
+
attribute :host, String
|
14
|
+
attribute :port, Integer
|
15
|
+
attribute :query, String
|
16
|
+
attribute :query_params, Hash, default: {}
|
17
|
+
attribute :fragment, String
|
18
|
+
|
19
|
+
validates :path, :host, :scheme, presence: true
|
20
|
+
validates :scheme, inclusion: ['https', 'http']
|
21
|
+
|
22
|
+
def call
|
23
|
+
builder.build(to_h).to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def host
|
27
|
+
return super unless subdomain.present?
|
28
|
+
"#{subdomain}.#{super}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def query
|
32
|
+
super || build_query
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def builder
|
38
|
+
case scheme
|
39
|
+
when 'http'
|
40
|
+
URI::HTTP
|
41
|
+
when 'https'
|
42
|
+
URI::HTTPS
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_query
|
47
|
+
Addressable::URI.new(query_values: query_params).query
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BloomRemitClient
|
3
|
+
module Requests
|
4
|
+
PATH_PARAM_REGEX = /\:[^\/|\?|\#|$]*/
|
5
|
+
GET = 'get'
|
6
|
+
POST = 'post'
|
7
|
+
PUT = 'put'
|
8
|
+
DELETE = 'delete'
|
9
|
+
REQUEST_TYPES = [GET, POST, PUT, DELETE].freeze
|
10
|
+
CONTENT_TYPE_JSON_UTF8 = 'application/json;charset=UTF-8'
|
11
|
+
CONTENT_TYPE_JSON = 'application/json'
|
12
|
+
|
13
|
+
def self.normalize_path(path, params, postfix = nil)
|
14
|
+
normalized_path = path.gsub(PATH_PARAM_REGEX) { |e| params[e.delete(':').to_sym] }
|
15
|
+
postfix ? "#{normalized_path}/#{postfix}" : normalized_path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Responses
|
3
|
+
class Base
|
4
|
+
|
5
|
+
include Virtus.model
|
6
|
+
attribute :raw_response, Object
|
7
|
+
attribute(:body, Coercers::IndifferentHash, {
|
8
|
+
lazy: true,
|
9
|
+
default: :default_body,
|
10
|
+
})
|
11
|
+
attribute :success, Boolean, lazy: true, default: :default_success
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def default_success
|
16
|
+
raw_response.success?
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_body
|
20
|
+
json = JSON.parse(raw_response.body)
|
21
|
+
|
22
|
+
if json.is_a?(Array)
|
23
|
+
json.map(&:with_indifferent_access)
|
24
|
+
else
|
25
|
+
json.with_indifferent_access
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Responses
|
3
|
+
module Billers
|
4
|
+
class List < Base
|
5
|
+
|
6
|
+
attribute :billers, Array, lazy: true, default: :default_billers
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def default_billers
|
11
|
+
body.map { |hash| Biller.new(hash) }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Responses
|
3
|
+
module Payments
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
attribute :payment, Object, lazy: true, default: :default_payment
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def default_payment
|
11
|
+
Payment.new(body[:payment])
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Responses
|
3
|
+
module Recipients
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
attribute(:recipient, Object, {
|
7
|
+
lazy: true,
|
8
|
+
default: :default_recipient,
|
9
|
+
})
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def default_recipient
|
14
|
+
Recipient.new(body[:recipient])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Responses
|
3
|
+
module Remittances
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
attribute(:remittance, Object, {
|
7
|
+
lazy: true,
|
8
|
+
default: :default_remittance,
|
9
|
+
})
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def default_remittance
|
14
|
+
Remittance.new(body[:remittance])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BloomRemitClient
|
2
|
+
module Responses
|
3
|
+
module Senders
|
4
|
+
class Create < Base
|
5
|
+
|
6
|
+
attribute :sender, Object, lazy: true, default: :default_sender
|
7
|
+
|
8
|
+
def success?
|
9
|
+
raw_response.success?
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_sender
|
15
|
+
User.new(body[:sender])
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/bloom_remit_client.rb
CHANGED
@@ -1,29 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'virtus'
|
2
3
|
require 'httparty'
|
3
4
|
require 'active_model'
|
4
5
|
require 'active_support/core_ext/hash/indifferent_access'
|
5
6
|
require 'active_support/core_ext/object/try'
|
6
7
|
require 'bloom_remit_client/coercers/indifferent_hash'
|
8
|
+
require 'bloom_remit_client/coercers/path'
|
9
|
+
require 'bloom_remit_client/concerns/has_base_authentification'
|
7
10
|
require "bloom_remit_client/version"
|
8
11
|
require "bloom_remit_client/client"
|
9
12
|
require "bloom_remit_client/models/biller"
|
10
13
|
require "bloom_remit_client/models/user"
|
11
14
|
require "bloom_remit_client/models/payment"
|
12
|
-
require "bloom_remit_client/
|
13
|
-
require "bloom_remit_client/
|
14
|
-
require "bloom_remit_client/
|
15
|
-
require "bloom_remit_client/requests
|
16
|
-
require "bloom_remit_client/
|
17
|
-
require "bloom_remit_client/
|
18
|
-
require "bloom_remit_client/
|
19
|
-
require "bloom_remit_client/
|
15
|
+
require "bloom_remit_client/models/remittance"
|
16
|
+
require "bloom_remit_client/models/credit"
|
17
|
+
require "bloom_remit_client/models/recipient"
|
18
|
+
require "bloom_remit_client/requests"
|
19
|
+
require "bloom_remit_client/requests/url_builder"
|
20
|
+
require "bloom_remit_client/requests/requests_sender"
|
21
|
+
require "bloom_remit_client/requests/base"
|
22
|
+
require "bloom_remit_client/requests/credit/list"
|
23
|
+
require "bloom_remit_client/requests/credit/history"
|
24
|
+
require "bloom_remit_client/requests/rate/show"
|
25
|
+
require "bloom_remit_client/requests/billers/list"
|
26
|
+
require "bloom_remit_client/requests/senders/create"
|
27
|
+
require "bloom_remit_client/requests/payments/create"
|
28
|
+
require "bloom_remit_client/requests/remittances/create"
|
29
|
+
require "bloom_remit_client/requests/recipients/create"
|
30
|
+
require "bloom_remit_client/responses/base"
|
31
|
+
require "bloom_remit_client/responses/billers/list"
|
32
|
+
require "bloom_remit_client/responses/senders/create"
|
33
|
+
require "bloom_remit_client/responses/payments/create"
|
34
|
+
require "bloom_remit_client/responses/remittances/create"
|
35
|
+
require "bloom_remit_client/responses/recipients/create"
|
20
36
|
|
21
37
|
module BloomRemitClient
|
38
|
+
PRODUCTION = 'api.bloom.solutions'
|
39
|
+
STAGING = 'bloomremit-staging.herokuapp.com'
|
22
40
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
41
|
+
class << self
|
42
|
+
attr_accessor :sandbox
|
43
|
+
attr_writer :host
|
44
|
+
|
45
|
+
def new(*args)
|
46
|
+
client = Client.new(*args)
|
47
|
+
raise ArgumentError, client.errors.full_messages if client.invalid?
|
48
|
+
client
|
49
|
+
end
|
28
50
|
|
51
|
+
def host
|
52
|
+
return @host if @host
|
53
|
+
sandbox ? STAGING : PRODUCTION
|
54
|
+
end
|
55
|
+
end
|
29
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bloom_remit_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Tayag
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: addressable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,18 +189,33 @@ files:
|
|
175
189
|
- lib/bloom_remit_client.rb
|
176
190
|
- lib/bloom_remit_client/client.rb
|
177
191
|
- lib/bloom_remit_client/coercers/indifferent_hash.rb
|
192
|
+
- lib/bloom_remit_client/coercers/path.rb
|
193
|
+
- lib/bloom_remit_client/concerns/has_base_authentification.rb
|
178
194
|
- lib/bloom_remit_client/factories.rb
|
179
195
|
- lib/bloom_remit_client/models/biller.rb
|
196
|
+
- lib/bloom_remit_client/models/credit.rb
|
180
197
|
- lib/bloom_remit_client/models/payment.rb
|
198
|
+
- lib/bloom_remit_client/models/recipient.rb
|
199
|
+
- lib/bloom_remit_client/models/remittance.rb
|
181
200
|
- lib/bloom_remit_client/models/user.rb
|
182
|
-
- lib/bloom_remit_client/requests
|
183
|
-
- lib/bloom_remit_client/requests/
|
184
|
-
- lib/bloom_remit_client/requests/
|
185
|
-
- lib/bloom_remit_client/requests/
|
186
|
-
- lib/bloom_remit_client/
|
187
|
-
- lib/bloom_remit_client/
|
188
|
-
- lib/bloom_remit_client/
|
189
|
-
- lib/bloom_remit_client/
|
201
|
+
- lib/bloom_remit_client/requests.rb
|
202
|
+
- lib/bloom_remit_client/requests/base.rb
|
203
|
+
- lib/bloom_remit_client/requests/billers/list.rb
|
204
|
+
- lib/bloom_remit_client/requests/credit/history.rb
|
205
|
+
- lib/bloom_remit_client/requests/credit/list.rb
|
206
|
+
- lib/bloom_remit_client/requests/payments/create.rb
|
207
|
+
- lib/bloom_remit_client/requests/rate/show.rb
|
208
|
+
- lib/bloom_remit_client/requests/recipients/create.rb
|
209
|
+
- lib/bloom_remit_client/requests/remittances/create.rb
|
210
|
+
- lib/bloom_remit_client/requests/requests_sender.rb
|
211
|
+
- lib/bloom_remit_client/requests/senders/create.rb
|
212
|
+
- lib/bloom_remit_client/requests/url_builder.rb
|
213
|
+
- lib/bloom_remit_client/responses/base.rb
|
214
|
+
- lib/bloom_remit_client/responses/billers/list.rb
|
215
|
+
- lib/bloom_remit_client/responses/payments/create.rb
|
216
|
+
- lib/bloom_remit_client/responses/recipients/create.rb
|
217
|
+
- lib/bloom_remit_client/responses/remittances/create.rb
|
218
|
+
- lib/bloom_remit_client/responses/senders/create.rb
|
190
219
|
- lib/bloom_remit_client/version.rb
|
191
220
|
homepage: https://github.com/imacchiato/bloom_remit_client-ruby
|
192
221
|
licenses:
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module BloomRemitClient
|
2
|
-
class BaseRequest
|
3
|
-
|
4
|
-
include Virtus.model
|
5
|
-
attribute :token, String
|
6
|
-
attribute :secret, String
|
7
|
-
attribute :url, String
|
8
|
-
attribute :agent_id, String
|
9
|
-
attribute :path, String, lazy: true, default: :default_path
|
10
|
-
attribute :endpoint, String, lazy: true, default: :default_endpoint
|
11
|
-
|
12
|
-
include ActiveModel::Validations
|
13
|
-
validates :token, :secret, :url, :path, presence: true
|
14
|
-
|
15
|
-
def call
|
16
|
-
HTTParty.get(self.endpoint)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def default_endpoint
|
22
|
-
return nil if self.url.nil?
|
23
|
-
uri = URI.parse(self.url)
|
24
|
-
uri.path = path
|
25
|
-
uri.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module BloomRemitClient
|
2
|
-
class CreatePaymentRequest < BaseRequest
|
3
|
-
|
4
|
-
PATH = "/api/v2/payments.json"
|
5
|
-
|
6
|
-
attribute :payment, Hash
|
7
|
-
attribute :sender_id, String
|
8
|
-
|
9
|
-
def call
|
10
|
-
HTTParty.post(self.endpoint, body: params)
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def default_path
|
16
|
-
PATH
|
17
|
-
end
|
18
|
-
|
19
|
-
def params
|
20
|
-
{
|
21
|
-
api_token: token,
|
22
|
-
api_secret: secret,
|
23
|
-
agent_id: agent_id,
|
24
|
-
sender_id: sender_id,
|
25
|
-
payment: payment,
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module BloomRemitClient
|
2
|
-
class CreateSenderRequest < BaseRequest
|
3
|
-
|
4
|
-
PATH = "/api/v1/partners/:token/senders.json"
|
5
|
-
|
6
|
-
attribute :sender, Hash
|
7
|
-
|
8
|
-
def call
|
9
|
-
HTTParty.post(self.endpoint, body: params)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def default_path
|
15
|
-
PATH.gsub(":token", self.token)
|
16
|
-
end
|
17
|
-
|
18
|
-
def params
|
19
|
-
{ api_secret: secret, sender: sender }
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module BloomRemitClient
|
2
|
-
class BaseResponse
|
3
|
-
|
4
|
-
include Virtus.model
|
5
|
-
attribute :raw_response, Object
|
6
|
-
attribute(:body, Coercers::IndifferentHash, {
|
7
|
-
lazy: true,
|
8
|
-
default: :default_body,
|
9
|
-
})
|
10
|
-
attribute :success, Boolean, lazy: true, default: :default_success
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def default_success
|
15
|
-
raw_response.success?
|
16
|
-
end
|
17
|
-
|
18
|
-
def default_body
|
19
|
-
json = JSON.parse(raw_response.body)
|
20
|
-
|
21
|
-
if json.is_a?(Array)
|
22
|
-
json.map(&:with_indifferent_access)
|
23
|
-
else
|
24
|
-
json.with_indifferent_access
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module BloomRemitClient
|
2
|
-
class CreateSenderResponse < BaseResponse
|
3
|
-
|
4
|
-
attribute :sender, Object, lazy: true, default: :default_sender
|
5
|
-
|
6
|
-
def success?
|
7
|
-
raw_response.success?
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def default_sender
|
13
|
-
User.new(body[:sender])
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|