gocardless-pro 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -4
  3. data/lib/gocardless-pro.rb +1 -169
  4. data/lib/gocardless-pro/api_service.rb +2 -2
  5. data/lib/gocardless-pro/client.rb +135 -0
  6. data/lib/gocardless-pro/version.rb +1 -1
  7. data/spec/api_service_spec.rb +3 -2
  8. data/spec/client_spec.rb +4 -14
  9. data/spec/services/creditor_bank_account_service_spec.rb +1 -2
  10. data/spec/services/creditor_service_spec.rb +1 -2
  11. data/spec/services/customer_bank_account_service_spec.rb +1 -2
  12. data/spec/services/customer_service_spec.rb +1 -2
  13. data/spec/services/event_service_spec.rb +1 -2
  14. data/spec/services/helper_service_spec.rb +1 -2
  15. data/spec/services/mandate_service_spec.rb +1 -2
  16. data/spec/services/payment_service_spec.rb +1 -2
  17. data/spec/services/payout_service_spec.rb +1 -2
  18. data/spec/services/redirect_flow_service_spec.rb +1 -2
  19. data/spec/services/refund_service_spec.rb +1 -2
  20. data/spec/services/subscription_service_spec.rb +1 -2
  21. metadata +2 -25
  22. data/lib/gocardless-pro/resources/api_key.rb +0 -62
  23. data/lib/gocardless-pro/resources/publishable_api_key.rb +0 -51
  24. data/lib/gocardless-pro/resources/role.rb +0 -101
  25. data/lib/gocardless-pro/resources/user.rb +0 -60
  26. data/lib/gocardless-pro/services/api_key_service.rb +0 -130
  27. data/lib/gocardless-pro/services/publishable_api_key_service.rb +0 -130
  28. data/lib/gocardless-pro/services/role_service.rb +0 -127
  29. data/lib/gocardless-pro/services/user_service.rb +0 -148
  30. data/spec/resources/api_key_spec.rb +0 -85
  31. data/spec/resources/publishable_api_key_spec.rb +0 -63
  32. data/spec/resources/role_spec.rb +0 -63
  33. data/spec/resources/user_spec.rb +0 -85
  34. data/spec/services/api_key_service_spec.rb +0 -362
  35. data/spec/services/publishable_api_key_service_spec.rb +0 -336
  36. data/spec/services/role_service_spec.rb +0 -336
  37. data/spec/services/user_service_spec.rb +0 -433
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4743079901f623f99893a58f597217374d0b149b
4
- data.tar.gz: 921dcc074feefd8c1a34169a7dea5510d81144b6
3
+ metadata.gz: cc97cc92944bdc8032081deee54e766bb9aa95bc
4
+ data.tar.gz: f5c6b37dd5d70425c9c6b0e127013c013fe9fd7f
5
5
  SHA512:
6
- metadata.gz: eb1c2e0828a1910b4b94009a69d8d051cbaa4bbb8bd99394811afa03587e1e0f6ea9ae6008780c458a9eadd5cc97fc9d2b1720e3ca6025b2b55b64140af85506
7
- data.tar.gz: 538fd99d6696cd8b21b9fe66de2121071b847c92ef60346923bd620cede1afc3fa9685d4cebcce0c9ab7cb50190978755cb71dadc0f4a13438da85967b39f848
6
+ metadata.gz: 867c8018cab90326aaa0e258b631240753e1b4820b8a4a4dd3339519d093dd6ce1360cdf87d5330f6e081f319c66172ef5fa3755990a6988bfb08af679b1887f
7
+ data.tar.gz: 17ca6a9c7464c075216cec90f373bcb4b38a4a94fa9e76e59eee44b9c44e91234426d0a4bf976af14e1bf68961229908d726fbe2d486f683a98eeec17617f8b6
data/README.md CHANGED
@@ -26,14 +26,12 @@ require 'gocardless-pro'
26
26
 
27
27
  ### Initialising the client
28
28
 
29
- The client is initialised with the API Key ID and the API Key `key` property.
30
-
29
+ The client is initialised with an Access Token.
31
30
  You can also pass in `environment` as `:sandbox` to make requests to the sandbox environment rather than the live one.
32
31
 
33
32
  ```rb
34
33
  @client = GoCardless::Client.new(
35
- api_key: ENV["GOCARDLESS_API_ID"],
36
- api_secret: ENV["GOCARDLESS_API_KEY"]
34
+ token: ENV["GOCARDLESS_TOKEN"]
37
35
  )
38
36
  ```
39
37
 
@@ -34,9 +34,6 @@ require_relative 'gocardless-pro/paginator'
34
34
  require_relative 'gocardless-pro/request'
35
35
  require_relative 'gocardless-pro/response'
36
36
 
37
- require_relative 'gocardless-pro/resources/api_key'
38
- require_relative 'gocardless-pro/services/api_key_service'
39
-
40
37
  require_relative 'gocardless-pro/resources/creditor'
41
38
  require_relative 'gocardless-pro/services/creditor_service'
42
39
 
@@ -64,178 +61,13 @@ require_relative 'gocardless-pro/services/payment_service'
64
61
  require_relative 'gocardless-pro/resources/payout'
65
62
  require_relative 'gocardless-pro/services/payout_service'
66
63
 
67
- require_relative 'gocardless-pro/resources/publishable_api_key'
68
- require_relative 'gocardless-pro/services/publishable_api_key_service'
69
-
70
64
  require_relative 'gocardless-pro/resources/redirect_flow'
71
65
  require_relative 'gocardless-pro/services/redirect_flow_service'
72
66
 
73
67
  require_relative 'gocardless-pro/resources/refund'
74
68
  require_relative 'gocardless-pro/services/refund_service'
75
69
 
76
- require_relative 'gocardless-pro/resources/role'
77
- require_relative 'gocardless-pro/services/role_service'
78
-
79
70
  require_relative 'gocardless-pro/resources/subscription'
80
71
  require_relative 'gocardless-pro/services/subscription_service'
81
72
 
82
- require_relative 'gocardless-pro/resources/user'
83
- require_relative 'gocardless-pro/services/user_service'
84
-
85
- module GoCardless
86
- # A class for working with and talking to the GoCardless API
87
- class Client
88
- extend Forwardable
89
-
90
- # Access to the service for api_key to make API calls
91
- def api_keys
92
- @api_keys ||= Services::ApiKeyService.new(@api_service)
93
- end
94
-
95
- # Access to the service for creditor to make API calls
96
- def creditors
97
- @creditors ||= Services::CreditorService.new(@api_service)
98
- end
99
-
100
- # Access to the service for creditor_bank_account to make API calls
101
- def creditor_bank_accounts
102
- @creditor_bank_accounts ||= Services::CreditorBankAccountService.new(@api_service)
103
- end
104
-
105
- # Access to the service for customer to make API calls
106
- def customers
107
- @customers ||= Services::CustomerService.new(@api_service)
108
- end
109
-
110
- # Access to the service for customer_bank_account to make API calls
111
- def customer_bank_accounts
112
- @customer_bank_accounts ||= Services::CustomerBankAccountService.new(@api_service)
113
- end
114
-
115
- # Access to the service for event to make API calls
116
- def events
117
- @events ||= Services::EventService.new(@api_service)
118
- end
119
-
120
- # Access to the service for helper to make API calls
121
- def helpers
122
- @helpers ||= Services::HelperService.new(@api_service)
123
- end
124
-
125
- # Access to the service for mandate to make API calls
126
- def mandates
127
- @mandates ||= Services::MandateService.new(@api_service)
128
- end
129
-
130
- # Access to the service for payment to make API calls
131
- def payments
132
- @payments ||= Services::PaymentService.new(@api_service)
133
- end
134
-
135
- # Access to the service for payout to make API calls
136
- def payouts
137
- @payouts ||= Services::PayoutService.new(@api_service)
138
- end
139
-
140
- # Access to the service for publishable_api_key to make API calls
141
- def publishable_api_keys
142
- @publishable_api_keys ||= Services::PublishableApiKeyService.new(@api_service)
143
- end
144
-
145
- # Access to the service for redirect_flow to make API calls
146
- def redirect_flows
147
- @redirect_flows ||= Services::RedirectFlowService.new(@api_service)
148
- end
149
-
150
- # Access to the service for refund to make API calls
151
- def refunds
152
- @refunds ||= Services::RefundService.new(@api_service)
153
- end
154
-
155
- # Access to the service for role to make API calls
156
- def roles
157
- @roles ||= Services::RoleService.new(@api_service)
158
- end
159
-
160
- # Access to the service for subscription to make API calls
161
- def subscriptions
162
- @subscriptions ||= Services::SubscriptionService.new(@api_service)
163
- end
164
-
165
- # Access to the service for user to make API calls
166
- def users
167
- @users ||= Services::UserService.new(@api_service)
168
- end
169
-
170
- # Get a Client configured to use HTTP Basic authentication with the GC Api
171
- #
172
- # @param options [Hash<Symbol,String>] configuration for creating the client
173
- # @option options [Symbol] :environment the environment to connect to - one of `:live` or `:sandbox`.
174
- # @option options [Symbol] :api_key the ID of the API Key
175
- # @option options [Symbol] :api_secret the key of the API Key
176
- # @option options [Symbol] :url the full URL used to make requests to. If you specify this, it will be used over the `environment` option.
177
- # @return [Client] A client configured to use the API with HTTP Basic
178
- # authentication.
179
- #
180
- def initialize(options)
181
- api_key = options.delete(:api_key) || fail('No API key ID given to GoCardless Client')
182
- api_secret = options.delete(:api_secret) || fail('No API secret given to GoCardless Client')
183
- environment = options.delete(:environment) || :live
184
- url = options.delete(:url) || url_for_environment(environment)
185
- options = custom_options(options)
186
- @api_service = ApiService.new(url, api_key, api_secret, options)
187
- end
188
-
189
- private
190
-
191
- def url_for_environment(environment)
192
- if environment === :live
193
- 'https://api.gocardless.com'
194
- elsif environment === :sandbox
195
- 'https://api-sandbox.gocardless.com'
196
- else
197
- fail "Unknown environment key: #{environment}"
198
- end
199
- end
200
-
201
- # Get customized options.
202
- def custom_options(options)
203
- return default_options if options.nil?
204
-
205
- return default_options.merge(options) unless options[:default_headers]
206
-
207
- opts = default_options.merge(options)
208
- opts[:default_headers] = default_options[:default_headers].merge(options[:default_headers])
209
-
210
- opts
211
- end
212
-
213
- # Get the default options.
214
- def default_options
215
- {
216
- default_headers: {
217
- 'GoCardless-Version' => '2014-11-03',
218
- 'User-Agent' => "#{user_agent}",
219
- 'Content-Type' => 'application/json'
220
- }
221
- }
222
- end
223
-
224
- def user_agent
225
- @user_agent ||=
226
- begin
227
- gem_name = 'gocardless-pro'
228
- gem_info = "#{gem_name}"
229
- gem_info += "/v#{ GoCardless::VERSION}" if defined?(GoCardless::VERSION)
230
- ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
231
- ruby_version = RUBY_VERSION
232
- ruby_version += " p#{RUBY_PATCHLEVEL}" if defined?(RUBY_PATCHLEVEL)
233
- comment = ["#{ruby_engine} #{ruby_version}"]
234
- comment << "gocardless-pro v#{ GoCardless::VERSION}"
235
- comment << "faraday v#{Faraday::VERSION}"
236
- comment << RUBY_PLATFORM if defined?(RUBY_PLATFORM)
237
- "#{gem_info} (#{comment.join('; ')})"
238
- end
239
- end
240
- end
241
- end
73
+ require_relative 'gocardless-pro/client.rb'
@@ -16,7 +16,7 @@ module GoCardless
16
16
  # @param key [String] the API Key ID to use
17
17
  # @param secret [String] the API key secret to use
18
18
  # @param options [Hash] additional options to use when creating the service
19
- def initialize(url, key, secret, options = {})
19
+ def initialize(url, token, options = {})
20
20
  @url = url
21
21
  root_url, @path_prefix = unpack_url(url)
22
22
  http_adapter = options[:http_adapter] || [:net_http]
@@ -25,7 +25,7 @@ module GoCardless
25
25
  end
26
26
 
27
27
  @headers = options[:default_headers] || {}
28
- @headers['Authorization'] = 'Basic ' + Base64.strict_encode64("#{key}:#{secret}")
28
+ @headers['Authorization'] = "Bearer #{token}"
29
29
  end
30
30
 
31
31
  # Make a request to the API
@@ -0,0 +1,135 @@
1
+ module GoCardless
2
+ # A class for working with and talking to the GoCardless API
3
+ class Client
4
+ extend Forwardable
5
+
6
+ # Access to the service for creditor to make API calls
7
+ def creditors
8
+ @creditors ||= Services::CreditorService.new(@api_service)
9
+ end
10
+
11
+ # Access to the service for creditor_bank_account to make API calls
12
+ def creditor_bank_accounts
13
+ @creditor_bank_accounts ||= Services::CreditorBankAccountService.new(@api_service)
14
+ end
15
+
16
+ # Access to the service for customer to make API calls
17
+ def customers
18
+ @customers ||= Services::CustomerService.new(@api_service)
19
+ end
20
+
21
+ # Access to the service for customer_bank_account to make API calls
22
+ def customer_bank_accounts
23
+ @customer_bank_accounts ||= Services::CustomerBankAccountService.new(@api_service)
24
+ end
25
+
26
+ # Access to the service for event to make API calls
27
+ def events
28
+ @events ||= Services::EventService.new(@api_service)
29
+ end
30
+
31
+ # Access to the service for helper to make API calls
32
+ def helpers
33
+ @helpers ||= Services::HelperService.new(@api_service)
34
+ end
35
+
36
+ # Access to the service for mandate to make API calls
37
+ def mandates
38
+ @mandates ||= Services::MandateService.new(@api_service)
39
+ end
40
+
41
+ # Access to the service for payment to make API calls
42
+ def payments
43
+ @payments ||= Services::PaymentService.new(@api_service)
44
+ end
45
+
46
+ # Access to the service for payout to make API calls
47
+ def payouts
48
+ @payouts ||= Services::PayoutService.new(@api_service)
49
+ end
50
+
51
+ # Access to the service for redirect_flow to make API calls
52
+ def redirect_flows
53
+ @redirect_flows ||= Services::RedirectFlowService.new(@api_service)
54
+ end
55
+
56
+ # Access to the service for refund to make API calls
57
+ def refunds
58
+ @refunds ||= Services::RefundService.new(@api_service)
59
+ end
60
+
61
+ # Access to the service for subscription to make API calls
62
+ def subscriptions
63
+ @subscriptions ||= Services::SubscriptionService.new(@api_service)
64
+ end
65
+
66
+ # Get a Client configured to use HTTP Basic authentication with the GC Api
67
+ #
68
+ # @param options [Hash<Symbol,String>] configuration for creating the client
69
+ # @option options [Symbol] :environment the environment to connect to - one of `:live` or `:sandbox`.
70
+ # @option options [Symbol] :token the API token
71
+ # @option options [Symbol] :url the full URL used to make requests to. If you specify this, it will be used over the `environment` option.
72
+ # @return [Client] A client configured to use the API with HTTP Basic
73
+ # authentication.
74
+ #
75
+ def initialize(options)
76
+ access_token = options.delete(:token) || fail('No Access Token given to GoCardless Client')
77
+ environment = options.delete(:environment) || :live
78
+ url = options.delete(:url) || url_for_environment(environment)
79
+ options = custom_options(options)
80
+ @api_service = ApiService.new(url, access_token, options)
81
+ end
82
+
83
+ private
84
+
85
+ def url_for_environment(environment)
86
+ if environment === :live
87
+ 'https://api.gocardless.com'
88
+ elsif environment === :sandbox
89
+ 'https://api-sandbox.gocardless.com'
90
+ else
91
+ fail "Unknown environment key: #{environment}"
92
+ end
93
+ end
94
+
95
+ # Get customized options.
96
+ def custom_options(options)
97
+ return default_options if options.nil?
98
+
99
+ return default_options.merge(options) unless options[:default_headers]
100
+
101
+ opts = default_options.merge(options)
102
+ opts[:default_headers] = default_options[:default_headers].merge(options[:default_headers])
103
+
104
+ opts
105
+ end
106
+
107
+ # Get the default options.
108
+ def default_options
109
+ {
110
+ default_headers: {
111
+ 'GoCardless-Version' => '2015-04-07',
112
+ 'User-Agent' => "#{user_agent}",
113
+ 'Content-Type' => 'application/json'
114
+ }
115
+ }
116
+ end
117
+
118
+ def user_agent
119
+ @user_agent ||=
120
+ begin
121
+ gem_name = 'gocardless-pro'
122
+ gem_info = "#{gem_name}"
123
+ gem_info += "/v#{ GoCardless::VERSION}" if defined?(GoCardless::VERSION)
124
+ ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
125
+ ruby_version = RUBY_VERSION
126
+ ruby_version += " p#{RUBY_PATCHLEVEL}" if defined?(RUBY_PATCHLEVEL)
127
+ comment = ["#{ruby_engine} #{ruby_version}"]
128
+ comment << "gocardless-pro v#{ GoCardless::VERSION}"
129
+ comment << "faraday v#{Faraday::VERSION}"
130
+ comment << RUBY_PLATFORM if defined?(RUBY_PLATFORM)
131
+ "#{gem_info} (#{comment.join('; ')})"
132
+ end
133
+ end
134
+ end
135
+ end
@@ -4,5 +4,5 @@ end
4
4
 
5
5
  module GoCardless
6
6
  # Current version of the GC gem
7
- VERSION = '0.1.1'
7
+ VERSION = '0.2.0'
8
8
  end
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GoCardless::ApiService do
4
- subject(:service) { described_class.new("https://api.example.com", "ak123", "abc123") }
4
+ subject(:service) { described_class.new("https://api.example.com", "secret_token") }
5
5
 
6
6
  it "uses basic auth" do
7
- stub = stub_request(:get, 'https://ak123:abc123@api.example.com/customers')
7
+ stub = stub_request(:get, 'https://api.example.com/customers').
8
+ with(headers: { "Authorization" => "Bearer secret_token" })
8
9
  service.make_request(:get, "/customers")
9
10
  expect(stub).to have_been_requested
10
11
  end
@@ -6,24 +6,14 @@ describe GoCardless::Client do
6
6
  let(:options) do
7
7
  {
8
8
  environment: environment,
9
- api_key: api_key,
10
- api_secret: api_secret
9
+ token: token
11
10
  }
12
11
  end
13
12
 
14
- context "when initialised without an API key" do
13
+ context "when initialised without an Access Token" do
15
14
  let(:environment) { :live }
16
- let(:api_secret) { "MYSECRETTOKEN" }
17
- let(:api_key) { nil }
15
+ let(:token) { nil }
18
16
 
19
- it { is_expected.to raise_error("No API key ID given to GoCardless Client") }
20
- end
21
-
22
- context "when initialised without an API secret" do
23
- let(:api_secret) { nil }
24
- let(:environment) { :live }
25
- let(:api_key) { "AK123" }
26
-
27
- it { is_expected.to raise_error("No API secret given to GoCardless Client") }
17
+ it { is_expected.to raise_error("No Access Token given to GoCardless Client") }
28
18
  end
29
19
  end
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe GoCardless::Services::CreditorBankAccountService do
4
4
  let(:client) do
5
5
  GoCardless::Client.new(
6
- api_key: "AK123",
7
- api_secret: "ABC"
6
+ token: "SECRET_TOKEN"
8
7
  )
9
8
  end
10
9
 
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe GoCardless::Services::CreditorService do
4
4
  let(:client) do
5
5
  GoCardless::Client.new(
6
- api_key: "AK123",
7
- api_secret: "ABC"
6
+ token: "SECRET_TOKEN"
8
7
  )
9
8
  end
10
9
 
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe GoCardless::Services::CustomerBankAccountService do
4
4
  let(:client) do
5
5
  GoCardless::Client.new(
6
- api_key: "AK123",
7
- api_secret: "ABC"
6
+ token: "SECRET_TOKEN"
8
7
  )
9
8
  end
10
9