promisepay 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed9b3ebad1d27848ce0b1e11a9ec1aa0e7efa76a
4
- data.tar.gz: 90149cfd350f8a64bc69b63da43e803f533d69a2
3
+ metadata.gz: 23ea2e12b7d1d4f35d341d41172be42221ee8291
4
+ data.tar.gz: 132b72a092ec9ad83e6d5ae6c8b01e156a3410df
5
5
  SHA512:
6
- metadata.gz: 6bb6af619be1ce789fcf0f958b5de64fdbd4f0a01e18a3e9df347e14fa2a8a599bc30d01cee7a2bb7f42c42368d5f5accabd2e9f5a3a8284525995885f29d5ee
7
- data.tar.gz: 5b1ef57cc159e7321da2e80dcc441ab9fc83840d29f838ea91932a85fbaef7f795a4945771185604927cd4b9796cdea1d56f5e8a846f549c34d7f671f1335629
6
+ metadata.gz: f3c30eec78f309ef4750b9f8d719b65e04ddcea609e0b45aed746b1c1065e29806f0087e97ded5740b12915f099eb0b12a218d6801652ddb9095ef60d6be1dab
7
+ data.tar.gz: 5ef05d8c96a61ef9452d5d4ad0b62a90912c69a14bd06fb2ea625259f78637a53f98c664905c9a7e2ed2c94990ad41eac48e6f0ddc76b2660adcaf52935b6992
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2015 Romain Vigo Benia
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2015 Romain Vigo Benia
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,163 +1,163 @@
1
- # The PromisePay Ruby Gem
2
- [![Gem Version](https://badge.fury.io/rb/promisepay.svg)](http://badge.fury.io/rb/promisepay)
3
- [![Build Status](https://travis-ci.org/PromisePay/promisepay-ruby.svg?branch=develop)](https://travis-ci.org/PromisePay/promisepay-ruby)
4
- [![Coverage Status](https://coveralls.io/repos/PromisePay/promisepay-ruby/badge.svg?branch=develop)](https://coveralls.io/r/PromisePay/promisepay-ruby?branch=develop)
5
- [![Code Climate](https://codeclimate.com/github/PromisePay/promisepay-ruby/badges/gpa.svg)](https://codeclimate.com/github/PromisePay/promisepay-ruby)
6
-
7
- A Ruby interface to the Promisepay API.
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- ```ruby
14
- gem 'promisepay'
15
- ```
16
-
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install promisepay
24
-
25
- ## Usage
26
-
27
- Before interacting with Promispay API you need to generate an access token.
28
-
29
- See http://docs.promisepay.com/v2.2/docs/request_token for more information.
30
-
31
- ### Client
32
-
33
- Create a client as following:
34
-
35
- ```ruby
36
- require 'promisepay'
37
-
38
- client = Promisepay::Client.new(username: 'YOUR_USERNAME', token: 'YOUR_TOKEN')
39
- ```
40
-
41
- Alternatively Promisepay Gem handles client configuration through environment variables.
42
-
43
- ```ruby
44
- ENV['PROMISEPAY_USERNAME'] = 'YOUR_USERNAME'
45
- ENV['PROMISEPAY_TOKEN'] = 'YOUR_TOKEN'
46
- ```
47
-
48
- ```ruby
49
- require 'promisepay'
50
-
51
- client = Promisepay::Client.new()
52
- ```
53
-
54
- _All configurable parameters are available in the Client Configuration section of this README._
55
-
56
- ### Calls
57
-
58
- The example below is translating [use case #1](http://docs.promisepay.com/v2.2/docs/charge-a-buyer-hold-funds-in-escrow-then-release-t) available on Promispay online documentation.
59
-
60
- ```ruby
61
- # 1- Create buyer
62
- buyer = client.users.create(
63
- id: '123456',
64
- first_name: 'test',
65
- last_name: 'buyer',
66
- email: 'buyer@test.com',
67
- address_line1: '48 collingwood',
68
- state: 'vic',
69
- city: 'Mel',
70
- zip: '3000',
71
- country: 'AUS'
72
- )
73
-
74
- # 2- Create buyer's card account
75
- buyer_card_account = client.card_accounts.create(
76
- user_id: buyer.id,
77
- full_name: 'test Buyer',
78
- number: '4111 1111 1111 1111',
79
- expiry_month: Time.now.month,
80
- expiry_year: Time.now.year + 1,
81
- cvv: '123'
82
- )
83
-
84
- # 3- Create seller
85
- seller = client.users.create(
86
- id: '123457',
87
- first_name: 'test',
88
- last_name: 'seller',
89
- email: 'seller@test.com',
90
- mobile: '+61416452321',
91
- address_line1: 'abc',
92
- state: 'vic',
93
- city: 'Mel',
94
- zip: '3000',
95
- country: 'AUS'
96
- )
97
-
98
- # 4- Create seller's bank account
99
- seller_bank_account = client.bank_accounts.create(
100
- user_id: seller.id,
101
- bank_name: 'Nab',
102
- account_name: 'test seller',
103
- routing_number: '22222222',
104
- account_number: '1234567890',
105
- account_type: 'savings',
106
- holder_type: 'personal',
107
- country: 'AUS'
108
- )
109
-
110
- # 5. Create seller's disbursement account
111
- seller.disbursement_account(seller_bank_account.id)
112
-
113
- # 6. Create fee
114
- fee = client.fees.create(
115
- name: 'test fee for 5 AUD',
116
- fee_type_id: '1',
117
- amount: '75',
118
- to: 'seller'
119
- )
120
-
121
- # 7. Create item and link buyer, seller and fee to it
122
- item = client.items.create(
123
- id: '12345',
124
- name: 'test item for 5AUD',
125
- amount: '500',
126
- payement_type: '1',
127
- buyer_id: buyer.id,
128
- seller_id: seller.id,
129
- fee_id: fee.id,
130
- description: '5AUD transfer'
131
- )
132
-
133
- # 8. Pay for item using the buyer's CC account
134
- item.make_payment(
135
- user_id: buyer.id,
136
- account_id: buyer_card_account.id
137
- )
138
-
139
- # 9. Buyer releases payment
140
- item.release_payment(user_id: buyer.id)
141
-
142
- # 10. Check payment status at any time (optional)
143
- item.status
144
- ```
145
-
146
- _Check out the [online documentation](http://promisepay.github.io/promisepay-ruby/) to get a list of available resources and methods._
147
-
148
- ## Client Configuration
149
-
150
- The following parameters are configurable through the client:
151
-
152
- * `:username` / `ENV['PROMISEPAY_USERNAME']`: username for [basic authentication](http://docs.promisepay.com/v2.2/docs/overview-2)
153
- * `:token` / `ENV['PROMISEPAY_TOKEN']`: token for [basic authentication](http://docs.promisepay.com/v2.2/docs/overview-2)
154
- * `:environment` / `ENV['PROMISEPAY_ENVIRONMENT']`: API [environment](http://docs.promisepay.com/v2.2/docs/environments) to use (default: 'test')
155
- * `:api_domain` / `ENV['PROMISEPAY_API_DOMAIN']`: API domain name to use (default: 'api.promisepay.com')
156
-
157
- ## Contributing
158
-
159
- 1. Fork it ( https://github.com/PromisePay/promisepay-ruby/fork )
160
- 2. Create your feature branch (`git checkout -b my-new-feature`)
161
- 3. Commit your changes (`git commit -am 'Add some feature'`)
162
- 4. Push to the branch (`git push origin my-new-feature`)
163
- 5. Create a new Pull Request
1
+ # The PromisePay Ruby Gem
2
+ [![Gem Version](https://badge.fury.io/rb/promisepay.svg)](http://badge.fury.io/rb/promisepay)
3
+ [![Build Status](https://travis-ci.org/PromisePay/promisepay-ruby.svg?branch=develop)](https://travis-ci.org/PromisePay/promisepay-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/PromisePay/promisepay-ruby/badge.svg?branch=develop)](https://coveralls.io/r/PromisePay/promisepay-ruby?branch=develop)
5
+ [![Code Climate](https://codeclimate.com/github/PromisePay/promisepay-ruby/badges/gpa.svg)](https://codeclimate.com/github/PromisePay/promisepay-ruby)
6
+
7
+ A Ruby interface to the Promisepay API.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'promisepay'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install promisepay
24
+
25
+ ## Usage
26
+
27
+ Before interacting with Promispay API you need to generate an access token.
28
+
29
+ See http://docs.promisepay.com/v2.2/docs/request_token for more information.
30
+
31
+ ### Client
32
+
33
+ Create a client as following:
34
+
35
+ ```ruby
36
+ require 'promisepay'
37
+
38
+ client = Promisepay::Client.new(username: 'YOUR_USERNAME', token: 'YOUR_TOKEN')
39
+ ```
40
+
41
+ Alternatively Promisepay Gem handles client configuration through environment variables.
42
+
43
+ ```ruby
44
+ ENV['PROMISEPAY_USERNAME'] = 'YOUR_USERNAME'
45
+ ENV['PROMISEPAY_TOKEN'] = 'YOUR_TOKEN'
46
+ ```
47
+
48
+ ```ruby
49
+ require 'promisepay'
50
+
51
+ client = Promisepay::Client.new()
52
+ ```
53
+
54
+ _All configurable parameters are available in the Client Configuration section of this README._
55
+
56
+ ### Calls
57
+
58
+ The example below is translating [use case #1](http://docs.promisepay.com/v2.2/docs/charge-a-buyer-hold-funds-in-escrow-then-release-t) available on Promispay online documentation.
59
+
60
+ ```ruby
61
+ # 1- Create buyer
62
+ buyer = client.users.create(
63
+ id: '123456',
64
+ first_name: 'test',
65
+ last_name: 'buyer',
66
+ email: 'buyer@test.com',
67
+ address_line1: '48 collingwood',
68
+ state: 'vic',
69
+ city: 'Mel',
70
+ zip: '3000',
71
+ country: 'AUS'
72
+ )
73
+
74
+ # 2- Create buyer's card account
75
+ buyer_card_account = client.card_accounts.create(
76
+ user_id: buyer.id,
77
+ full_name: 'test Buyer',
78
+ number: '4111 1111 1111 1111',
79
+ expiry_month: Time.now.month,
80
+ expiry_year: Time.now.year + 1,
81
+ cvv: '123'
82
+ )
83
+
84
+ # 3- Create seller
85
+ seller = client.users.create(
86
+ id: '123457',
87
+ first_name: 'test',
88
+ last_name: 'seller',
89
+ email: 'seller@test.com',
90
+ mobile: '+61416452321',
91
+ address_line1: 'abc',
92
+ state: 'vic',
93
+ city: 'Mel',
94
+ zip: '3000',
95
+ country: 'AUS'
96
+ )
97
+
98
+ # 4- Create seller's bank account
99
+ seller_bank_account = client.bank_accounts.create(
100
+ user_id: seller.id,
101
+ bank_name: 'Nab',
102
+ account_name: 'test seller',
103
+ routing_number: '22222222',
104
+ account_number: '1234567890',
105
+ account_type: 'savings',
106
+ holder_type: 'personal',
107
+ country: 'AUS'
108
+ )
109
+
110
+ # 5. Create seller's disbursement account
111
+ seller.disbursement_account(seller_bank_account.id)
112
+
113
+ # 6. Create fee
114
+ fee = client.fees.create(
115
+ name: 'test fee for 5 AUD',
116
+ fee_type_id: '1',
117
+ amount: '75',
118
+ to: 'seller'
119
+ )
120
+
121
+ # 7. Create item and link buyer, seller and fee to it
122
+ item = client.items.create(
123
+ id: '12345',
124
+ name: 'test item for 5AUD',
125
+ amount: '500',
126
+ payement_type: '1',
127
+ buyer_id: buyer.id,
128
+ seller_id: seller.id,
129
+ fee_id: fee.id,
130
+ description: '5AUD transfer'
131
+ )
132
+
133
+ # 8. Pay for item using the buyer's CC account
134
+ item.make_payment(
135
+ user_id: buyer.id,
136
+ account_id: buyer_card_account.id
137
+ )
138
+
139
+ # 9. Buyer releases payment
140
+ item.release_payment(user_id: buyer.id)
141
+
142
+ # 10. Check payment status at any time (optional)
143
+ item.status
144
+ ```
145
+
146
+ _Check out the [online documentation](http://promisepay.github.io/promisepay-ruby/) to get a list of available resources and methods._
147
+
148
+ ## Client Configuration
149
+
150
+ The following parameters are configurable through the client:
151
+
152
+ * `:username` / `ENV['PROMISEPAY_USERNAME']`: username for [basic authentication](http://docs.promisepay.com/v2.2/docs/overview-2)
153
+ * `:token` / `ENV['PROMISEPAY_TOKEN']`: token for [basic authentication](http://docs.promisepay.com/v2.2/docs/overview-2)
154
+ * `:environment` / `ENV['PROMISEPAY_ENVIRONMENT']`: API [environment](http://docs.promisepay.com/v2.2/docs/environments) to use (default: 'test')
155
+ * `:api_domain` / `ENV['PROMISEPAY_API_DOMAIN']`: API domain name to use (default: 'api.promisepay.com')
156
+
157
+ ## Contributing
158
+
159
+ 1. Fork it ( https://github.com/PromisePay/promisepay-ruby/fork )
160
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
161
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
162
+ 4. Push to the branch (`git push origin my-new-feature`)
163
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require 'bundler/gem_tasks'
1
+ require 'bundler/gem_tasks'
data/lib/promisepay.rb CHANGED
@@ -1,13 +1,13 @@
1
- require_relative 'promisepay/client'
2
- require_relative 'promisepay/default'
3
- require_relative 'promisepay/error'
4
- require_relative 'promisepay/version'
5
-
6
- # Ruby toolkit for the Promisepay API
7
- module Promisepay
8
- class << self
9
- include Promisepay::Configurable
10
- end
11
- end
12
-
13
- Promisepay.setup
1
+ require_relative 'promisepay/client'
2
+ require_relative 'promisepay/default'
3
+ require_relative 'promisepay/error'
4
+ require_relative 'promisepay/version'
5
+
6
+ # Ruby toolkit for the Promisepay API
7
+ module Promisepay
8
+ class << self
9
+ include Promisepay::Configurable
10
+ end
11
+ end
12
+
13
+ Promisepay.setup
@@ -1,144 +1,147 @@
1
- require_relative 'configurable'
2
- require_relative 'models/base_model'
3
- require_relative 'models/account'
4
- require_relative 'models/bank_account'
5
- require_relative 'models/card_account'
6
- require_relative 'models/fee'
7
- require_relative 'models/item'
8
- require_relative 'models/paypal_account'
9
- require_relative 'models/transaction'
10
- require_relative 'models/user'
11
- require_relative 'resources/base_resource'
12
- require_relative 'resources/account_resource'
13
- require_relative 'resources/bank_account_resource'
14
- require_relative 'resources/card_account_resource'
15
- require_relative 'resources/fee_resource'
16
- require_relative 'resources/item_resource'
17
- require_relative 'resources/paypal_account_resource'
18
- require_relative 'resources/transaction_resource'
19
- require_relative 'resources/user_resource'
20
- require 'json'
21
- require 'faraday'
22
-
23
- module Promisepay
24
- # Client for the Promisepay API
25
- #
26
- # @see http://docs.promisepay.com/v2.2/docs/overview
27
- class Client
28
- include Promisepay::Configurable
29
-
30
- def initialize(options = {})
31
- # Use options passed in, but fall back to module defaults
32
- Promisepay::Configurable.keys.each do |key|
33
- instance_variable_set(
34
- :"@#{key}", options[key] || Promisepay.instance_variable_get(:"@#{key}")
35
- )
36
- end
37
- end
38
-
39
- # Create a new Faraday connection
40
- #
41
- # @return [Faraday::Connection]
42
- def connection
43
- Faraday.new(url: @api_endpoint) do |builder|
44
- builder.request :basic_auth, @username, @token
45
- builder.adapter :net_http
46
- end
47
- end
48
-
49
- # Make a HTTP GET request
50
- #
51
- # @param url [String] The path, relative to {#api_endpoint}
52
- # @param parameters [Hash] Query params for request
53
- # @return [Faraday::Response]
54
- def get(url, parameters = {})
55
- response = connection.get("#{api_endpoint}#{url}", parameters)
56
- on_complete(response)
57
- response
58
- end
59
-
60
- # Make a HTTP POST request
61
- #
62
- # @param url [String] The path, relative to {#api_endpoint}
63
- # @param parameters [Hash] Query params for request
64
- # @return [Faraday::Response]
65
- def post(url, parameters = {})
66
- response = connection.post do |req|
67
- req.url "#{api_endpoint}#{url}"
68
- req.headers['Content-Type'] = 'application/json'
69
- req.body = parameters.to_json
70
- end
71
- on_complete(response)
72
- response
73
- end
74
-
75
- # Make a HTTP PATCH request
76
- #
77
- # @param url [String] The path, relative to {#api_endpoint}
78
- # @param parameters [Hash] Query params for request
79
- # @return [Faraday::Response]
80
- def patch(url, parameters = {})
81
- response = connection.patch do |req|
82
- req.url "#{api_endpoint}#{url}"
83
- req.headers['Content-Type'] = 'application/json'
84
- req.body = parameters.to_json
85
- end
86
- on_complete(response)
87
- response
88
- end
89
-
90
- # Make a HTTP DELETE request
91
- #
92
- # @param url [String] The path, relative to {#api_endpoint}
93
- # @param parameters [Hash] Query params for request
94
- # @return [Faraday::Response]
95
- def delete(url, parameters = {})
96
- response = connection.delete do |req|
97
- req.url "#{api_endpoint}#{url}"
98
- req.headers['Content-Type'] = 'application/json'
99
- req.body = parameters.to_json
100
- end
101
- on_complete(response)
102
- response
103
- end
104
-
105
- # Available resources for {Client}
106
- #
107
- # @return [Hash]
108
- def self.resources
109
- {
110
- bank_accounts: BankAccountResource,
111
- card_accounts: CardAccountResource,
112
- fees: FeeResource,
113
- items: ItemResource,
114
- paypal_accounts: PaypalAccountResource,
115
- transactions: TransactionResource,
116
- users: UserResource
117
- }
118
- end
119
-
120
- # Catch calls for resources
121
- #
122
- def method_missing(name, *args, &block)
123
- if self.class.resources.keys.include?(name)
124
- resources[name] ||= self.class.resources[name].new(self)
125
- resources[name]
126
- else
127
- super
128
- end
129
- end
130
-
131
- # Resources being currently used
132
- #
133
- # @return [Hash]
134
- def resources
135
- @resources ||= {}
136
- end
137
-
138
- private
139
-
140
- def on_complete(response)
141
- fail Promisepay::Error.from_response(response) unless response.success?
142
- end
143
- end
144
- end
1
+ require_relative 'configurable'
2
+ require_relative 'models/base_model'
3
+ require_relative 'models/account'
4
+ require_relative 'models/bank_account'
5
+ require_relative 'models/card_account'
6
+ require_relative 'models/fee'
7
+ require_relative 'models/item'
8
+ require_relative 'models/paypal_account'
9
+ require_relative 'models/token'
10
+ require_relative 'models/transaction'
11
+ require_relative 'models/user'
12
+ require_relative 'resources/base_resource'
13
+ require_relative 'resources/account_resource'
14
+ require_relative 'resources/bank_account_resource'
15
+ require_relative 'resources/card_account_resource'
16
+ require_relative 'resources/fee_resource'
17
+ require_relative 'resources/item_resource'
18
+ require_relative 'resources/paypal_account_resource'
19
+ require_relative 'resources/token_resource'
20
+ require_relative 'resources/transaction_resource'
21
+ require_relative 'resources/user_resource'
22
+ require 'json'
23
+ require 'faraday'
24
+
25
+ module Promisepay
26
+ # Client for the Promisepay API
27
+ #
28
+ # @see http://docs.promisepay.com/v2.2/docs/overview
29
+ class Client
30
+ include Promisepay::Configurable
31
+
32
+ def initialize(options = {})
33
+ # Use options passed in, but fall back to module defaults
34
+ Promisepay::Configurable.keys.each do |key|
35
+ instance_variable_set(
36
+ :"@#{key}", options[key] || Promisepay.instance_variable_get(:"@#{key}")
37
+ )
38
+ end
39
+ end
40
+
41
+ # Create a new Faraday connection
42
+ #
43
+ # @return [Faraday::Connection]
44
+ def connection
45
+ Faraday.new(url: @api_endpoint) do |builder|
46
+ builder.request :basic_auth, @username, @token
47
+ builder.adapter :net_http
48
+ end
49
+ end
50
+
51
+ # Make a HTTP GET request
52
+ #
53
+ # @param url [String] The path, relative to {#api_endpoint}
54
+ # @param parameters [Hash] Query params for request
55
+ # @return [Faraday::Response]
56
+ def get(url, parameters = {})
57
+ response = connection.get("#{api_endpoint}#{url}", parameters)
58
+ on_complete(response)
59
+ response
60
+ end
61
+
62
+ # Make a HTTP POST request
63
+ #
64
+ # @param url [String] The path, relative to {#api_endpoint}
65
+ # @param parameters [Hash] Query params for request
66
+ # @return [Faraday::Response]
67
+ def post(url, parameters = {})
68
+ response = connection.post do |req|
69
+ req.url "#{api_endpoint}#{url}"
70
+ req.headers['Content-Type'] = 'application/json'
71
+ req.body = parameters.to_json
72
+ end
73
+ on_complete(response)
74
+ response
75
+ end
76
+
77
+ # Make a HTTP PATCH request
78
+ #
79
+ # @param url [String] The path, relative to {#api_endpoint}
80
+ # @param parameters [Hash] Query params for request
81
+ # @return [Faraday::Response]
82
+ def patch(url, parameters = {})
83
+ response = connection.patch do |req|
84
+ req.url "#{api_endpoint}#{url}"
85
+ req.headers['Content-Type'] = 'application/json'
86
+ req.body = parameters.to_json
87
+ end
88
+ on_complete(response)
89
+ response
90
+ end
91
+
92
+ # Make a HTTP DELETE request
93
+ #
94
+ # @param url [String] The path, relative to {#api_endpoint}
95
+ # @param parameters [Hash] Query params for request
96
+ # @return [Faraday::Response]
97
+ def delete(url, parameters = {})
98
+ response = connection.delete do |req|
99
+ req.url "#{api_endpoint}#{url}"
100
+ req.headers['Content-Type'] = 'application/json'
101
+ req.body = parameters.to_json
102
+ end
103
+ on_complete(response)
104
+ response
105
+ end
106
+
107
+ # Available resources for {Client}
108
+ #
109
+ # @return [Hash]
110
+ def self.resources
111
+ {
112
+ bank_accounts: BankAccountResource,
113
+ card_accounts: CardAccountResource,
114
+ fees: FeeResource,
115
+ items: ItemResource,
116
+ paypal_accounts: PaypalAccountResource,
117
+ transactions: TransactionResource,
118
+ users: UserResource,
119
+ tokens: TokenResource
120
+ }
121
+ end
122
+
123
+ # Catch calls for resources
124
+ #
125
+ def method_missing(name, *args, &block)
126
+ if self.class.resources.keys.include?(name)
127
+ resources[name] ||= self.class.resources[name].new(self)
128
+ resources[name]
129
+ else
130
+ super
131
+ end
132
+ end
133
+
134
+ # Resources being currently used
135
+ #
136
+ # @return [Hash]
137
+ def resources
138
+ @resources ||= {}
139
+ end
140
+
141
+ private
142
+
143
+ def on_complete(response)
144
+ fail Promisepay::Error.from_response(response) unless response.success?
145
+ end
146
+ end
147
+ end