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
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Resources::ApiKey do
4
- describe "initialising" do
5
- let(:data) do
6
- {
7
-
8
-
9
- "created_at" => "created_at-input",
10
-
11
-
12
-
13
- "enabled" => "enabled-input",
14
-
15
-
16
-
17
- "id" => "id-input",
18
-
19
-
20
-
21
- "key" => "key-input",
22
-
23
-
24
-
25
- "links" => {
26
-
27
- "role" => "role-input",
28
-
29
- },
30
-
31
-
32
-
33
- "name" => "name-input",
34
-
35
-
36
-
37
- "webhook_url" => "webhook_url-input",
38
-
39
-
40
- }
41
- end
42
-
43
- it "can be initialized from an uneveloped response" do
44
- resource = described_class.new(data)
45
-
46
-
47
- expect(resource.created_at).to eq("created_at-input")
48
-
49
-
50
-
51
- expect(resource.enabled).to eq("enabled-input")
52
-
53
-
54
-
55
- expect(resource.id).to eq("id-input")
56
-
57
-
58
-
59
- expect(resource.key).to eq("key-input")
60
-
61
-
62
-
63
-
64
- expect(resource.links.role).to eq("role-input")
65
-
66
-
67
-
68
-
69
- expect(resource.name).to eq("name-input")
70
-
71
-
72
-
73
- expect(resource.webhook_url).to eq("webhook_url-input")
74
-
75
-
76
- end
77
-
78
- describe "#to_h" do
79
- it "returns a hash representing the resource" do
80
- expect(described_class.new(data).to_h).to eq(data)
81
- end
82
- end
83
- end
84
- end
85
-
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Resources::PublishableApiKey do
4
- describe "initialising" do
5
- let(:data) do
6
- {
7
-
8
-
9
- "created_at" => "created_at-input",
10
-
11
-
12
-
13
- "enabled" => "enabled-input",
14
-
15
-
16
-
17
- "id" => "id-input",
18
-
19
-
20
-
21
- "key" => "key-input",
22
-
23
-
24
-
25
- "name" => "name-input",
26
-
27
-
28
- }
29
- end
30
-
31
- it "can be initialized from an uneveloped response" do
32
- resource = described_class.new(data)
33
-
34
-
35
- expect(resource.created_at).to eq("created_at-input")
36
-
37
-
38
-
39
- expect(resource.enabled).to eq("enabled-input")
40
-
41
-
42
-
43
- expect(resource.id).to eq("id-input")
44
-
45
-
46
-
47
- expect(resource.key).to eq("key-input")
48
-
49
-
50
-
51
- expect(resource.name).to eq("name-input")
52
-
53
-
54
- end
55
-
56
- describe "#to_h" do
57
- it "returns a hash representing the resource" do
58
- expect(described_class.new(data).to_h).to eq(data)
59
- end
60
- end
61
- end
62
- end
63
-
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Resources::Role do
4
- describe "initialising" do
5
- let(:data) do
6
- {
7
-
8
-
9
- "created_at" => "created_at-input",
10
-
11
-
12
-
13
- "enabled" => "enabled-input",
14
-
15
-
16
-
17
- "id" => "id-input",
18
-
19
-
20
-
21
- "name" => "name-input",
22
-
23
-
24
-
25
- "permissions" => "permissions-input",
26
-
27
-
28
- }
29
- end
30
-
31
- it "can be initialized from an uneveloped response" do
32
- resource = described_class.new(data)
33
-
34
-
35
- expect(resource.created_at).to eq("created_at-input")
36
-
37
-
38
-
39
- expect(resource.enabled).to eq("enabled-input")
40
-
41
-
42
-
43
- expect(resource.id).to eq("id-input")
44
-
45
-
46
-
47
- expect(resource.name).to eq("name-input")
48
-
49
-
50
-
51
- expect(resource.permissions).to eq("permissions-input")
52
-
53
-
54
- end
55
-
56
- describe "#to_h" do
57
- it "returns a hash representing the resource" do
58
- expect(described_class.new(data).to_h).to eq(data)
59
- end
60
- end
61
- end
62
- end
63
-
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Resources::User do
4
- describe "initialising" do
5
- let(:data) do
6
- {
7
-
8
-
9
- "created_at" => "created_at-input",
10
-
11
-
12
-
13
- "email" => "email-input",
14
-
15
-
16
-
17
- "enabled" => "enabled-input",
18
-
19
-
20
-
21
- "family_name" => "family_name-input",
22
-
23
-
24
-
25
- "given_name" => "given_name-input",
26
-
27
-
28
-
29
- "id" => "id-input",
30
-
31
-
32
-
33
- "links" => {
34
-
35
- "role" => "role-input",
36
-
37
- },
38
-
39
-
40
- }
41
- end
42
-
43
- it "can be initialized from an uneveloped response" do
44
- resource = described_class.new(data)
45
-
46
-
47
- expect(resource.created_at).to eq("created_at-input")
48
-
49
-
50
-
51
- expect(resource.email).to eq("email-input")
52
-
53
-
54
-
55
- expect(resource.enabled).to eq("enabled-input")
56
-
57
-
58
-
59
- expect(resource.family_name).to eq("family_name-input")
60
-
61
-
62
-
63
- expect(resource.given_name).to eq("given_name-input")
64
-
65
-
66
-
67
- expect(resource.id).to eq("id-input")
68
-
69
-
70
-
71
-
72
- expect(resource.links.role).to eq("role-input")
73
-
74
-
75
-
76
- end
77
-
78
- describe "#to_h" do
79
- it "returns a hash representing the resource" do
80
- expect(described_class.new(data).to_h).to eq(data)
81
- end
82
- end
83
- end
84
- end
85
-
@@ -1,362 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Services::ApiKeyService do
4
- let(:client) do
5
- GoCardless::Client.new(
6
- api_key: "AK123",
7
- api_secret: "ABC"
8
- )
9
- end
10
-
11
-
12
-
13
-
14
-
15
-
16
- describe "#create" do
17
- subject(:post_create_response) { client.api_keys.create(new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "created_at" => "created_at-input",
23
- "enabled" => "enabled-input",
24
- "id" => "id-input",
25
- "key" => "key-input",
26
- "links" => "links-input",
27
- "name" => "name-input",
28
- "webhook_url" => "webhook_url-input",
29
- }
30
- end
31
-
32
- before do
33
- stub_request(:post, /.*api.gocardless.com\/api_keys/).
34
- with(
35
- body: {
36
- api_keys: {
37
-
38
- "created_at" => "created_at-input",
39
- "enabled" => "enabled-input",
40
- "id" => "id-input",
41
- "key" => "key-input",
42
- "links" => "links-input",
43
- "name" => "name-input",
44
- "webhook_url" => "webhook_url-input",
45
- }
46
- }
47
- ).
48
- to_return(
49
- body: {
50
- api_keys: {
51
-
52
- "created_at" => "created_at-input",
53
- "enabled" => "enabled-input",
54
- "id" => "id-input",
55
- "key" => "key-input",
56
- "links" => "links-input",
57
- "name" => "name-input",
58
- "webhook_url" => "webhook_url-input",
59
- }
60
- }.to_json,
61
- :headers => {'Content-Type' => 'application/json'}
62
- )
63
- end
64
-
65
- it "creates and returns the resource" do
66
- expect(post_create_response).to be_a(GoCardless::Resources::ApiKey)
67
- end
68
- end
69
-
70
- context "with a request that returns a validation error" do
71
- let(:new_resource) { {} }
72
-
73
- before do
74
- stub_request(:post, /.*api.gocardless.com\/api_keys/).to_return(
75
- body: {
76
- error: {
77
- type: 'validation_failed',
78
- code: 422,
79
- errors: [
80
- { message: 'test error message', field: 'test_field' }
81
- ]
82
- }
83
- }.to_json,
84
- headers: {'Content-Type' => 'application/json'},
85
- status: 422
86
- )
87
- end
88
-
89
- it "throws the correct error" do
90
- expect { post_create_response }.to raise_error(GoCardless::ValidationError)
91
- end
92
- end
93
- end
94
-
95
-
96
-
97
-
98
-
99
- describe "#list" do
100
- describe "with no filters" do
101
- subject(:get_list_response) { client.api_keys.list }
102
-
103
- before do
104
- stub_request(:get, /.*api.gocardless.com\/api_keys/).to_return(
105
- body: {
106
- api_keys: [{
107
-
108
- "created_at" => "created_at-input",
109
- "enabled" => "enabled-input",
110
- "id" => "id-input",
111
- "key" => "key-input",
112
- "links" => "links-input",
113
- "name" => "name-input",
114
- "webhook_url" => "webhook_url-input",
115
- }],
116
- meta: {
117
- cursors: {
118
- before: nil,
119
- after: "ABC123"
120
- }
121
- }
122
- }.to_json,
123
- :headers => {'Content-Type' => 'application/json'}
124
- )
125
- end
126
-
127
- it "wraps each item in the resource class" do
128
- expect(get_list_response.map { |x| x.class }.uniq.first).to eq(GoCardless::Resources::ApiKey)
129
-
130
-
131
-
132
- expect(get_list_response.first.created_at).to eq("created_at-input")
133
-
134
-
135
-
136
- expect(get_list_response.first.enabled).to eq("enabled-input")
137
-
138
-
139
-
140
- expect(get_list_response.first.id).to eq("id-input")
141
-
142
-
143
-
144
- expect(get_list_response.first.key).to eq("key-input")
145
-
146
-
147
-
148
-
149
-
150
- expect(get_list_response.first.name).to eq("name-input")
151
-
152
-
153
-
154
- expect(get_list_response.first.webhook_url).to eq("webhook_url-input")
155
-
156
-
157
- end
158
-
159
- it "exposes the cursors for before and after" do
160
- expect(get_list_response.before).to eq(nil)
161
- expect(get_list_response.after).to eq("ABC123")
162
- end
163
- end
164
- end
165
-
166
- describe "#all" do
167
- let!(:first_response_stub) do
168
- stub_request(:get, /.*api.gocardless.com\/api_keys$/).to_return(
169
- body: {
170
- api_keys: [{
171
-
172
- "created_at" => "created_at-input",
173
- "enabled" => "enabled-input",
174
- "id" => "id-input",
175
- "key" => "key-input",
176
- "links" => "links-input",
177
- "name" => "name-input",
178
- "webhook_url" => "webhook_url-input",
179
- }],
180
- meta: {
181
- cursors: { after: 'AB345' },
182
- limit: 1
183
- }
184
- }.to_json,
185
- :headers => {'Content-Type' => 'application/json'}
186
- )
187
- end
188
-
189
- let!(:second_response_stub) do
190
- stub_request(:get, /.*api.gocardless.com\/api_keys\?after=AB345/).to_return(
191
- body: {
192
- api_keys: [{
193
-
194
- "created_at" => "created_at-input",
195
- "enabled" => "enabled-input",
196
- "id" => "id-input",
197
- "key" => "key-input",
198
- "links" => "links-input",
199
- "name" => "name-input",
200
- "webhook_url" => "webhook_url-input",
201
- }],
202
- meta: {
203
- limit: 2,
204
- cursors: {}
205
- }
206
- }.to_json,
207
- :headers => {'Content-Type' => 'application/json'}
208
- )
209
- end
210
-
211
- it "automatically makes the extra requests" do
212
- expect(client.api_keys.all.to_a.length).to eq(2)
213
- expect(first_response_stub).to have_been_requested
214
- expect(second_response_stub).to have_been_requested
215
- end
216
- end
217
-
218
-
219
-
220
-
221
-
222
-
223
- describe "#get" do
224
- let(:id) { "ID123" }
225
-
226
- subject(:get_response) { client.api_keys.get(id) }
227
-
228
- context "when there is a api_key to return" do
229
- before do
230
- stub_request(:get, /.*api.gocardless.com\/api_keys\/ID123/).to_return(
231
- body: {
232
- api_keys: {
233
-
234
- "created_at" => "created_at-input",
235
- "enabled" => "enabled-input",
236
- "id" => "id-input",
237
- "key" => "key-input",
238
- "links" => "links-input",
239
- "name" => "name-input",
240
- "webhook_url" => "webhook_url-input",
241
- }
242
- }.to_json,
243
- :headers => {'Content-Type' => 'application/json'}
244
- )
245
- end
246
-
247
- it "wraps the response in a resource" do
248
- expect(get_response).to be_a(GoCardless::Resources::ApiKey)
249
- end
250
- end
251
- end
252
-
253
-
254
-
255
-
256
-
257
-
258
- describe "#update" do
259
- subject(:put_update_response) { client.api_keys.update(id, update_params) }
260
- let(:id) { "ABC123" }
261
-
262
- context "with a valid request" do
263
- let(:update_params) { { "hello" => "world" } }
264
-
265
- let!(:stub) do
266
- stub_request(:put, /.*api.gocardless.com\/api_keys\/ABC123/).to_return(
267
- body: {
268
- api_keys: {
269
-
270
- "created_at" => "created_at-input",
271
- "enabled" => "enabled-input",
272
- "id" => "id-input",
273
- "key" => "key-input",
274
- "links" => "links-input",
275
- "name" => "name-input",
276
- "webhook_url" => "webhook_url-input",
277
- }
278
- }.to_json,
279
- :headers => {'Content-Type' => 'application/json'}
280
- )
281
- end
282
-
283
- it "updates and returns the resource" do
284
- expect(put_update_response).to be_a(GoCardless::Resources::ApiKey)
285
- expect(stub).to have_been_requested
286
- end
287
- end
288
- end
289
-
290
-
291
-
292
-
293
-
294
- describe "#disable" do
295
-
296
-
297
- subject(:post_response) { client.api_keys.disable(resource_id) }
298
-
299
- let(:resource_id) { "ABC123" }
300
-
301
- let!(:stub) do
302
- # /api_keys/%v/actions/disable
303
- stub_url = "/api_keys/:identity/actions/disable".gsub(':identity', resource_id)
304
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
305
- body: {
306
- api_keys: {
307
-
308
- "created_at" => "created_at-input",
309
- "enabled" => "enabled-input",
310
- "id" => "id-input",
311
- "key" => "key-input",
312
- "links" => "links-input",
313
- "name" => "name-input",
314
- "webhook_url" => "webhook_url-input",
315
- }
316
- }.to_json,
317
- headers: {'Content-Type' => 'application/json'},
318
- )
319
- end
320
-
321
- it "wraps the response and calls the right endpoint" do
322
- expect(post_response).to be_a(GoCardless::Resources::ApiKey)
323
-
324
- expect(stub).to have_been_requested
325
- end
326
-
327
- context "when the request needs a body and custom header" do
328
-
329
- let(:body) { { foo: 'bar' } }
330
- let(:headers) { { 'Foo' => 'Bar' } }
331
- subject(:post_response) { client.api_keys.disable(resource_id, body, headers) }
332
-
333
- let(:resource_id) { "ABC123" }
334
-
335
- let!(:stub) do
336
- # /api_keys/%v/actions/disable
337
- stub_url = "/api_keys/:identity/actions/disable".gsub(':identity', resource_id)
338
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
339
- with(
340
- body: { foo: 'bar' },
341
- headers: { 'Foo' => 'Bar' }
342
- ).to_return(
343
- body: {
344
- api_keys: {
345
-
346
- "created_at" => "created_at-input",
347
- "enabled" => "enabled-input",
348
- "id" => "id-input",
349
- "key" => "key-input",
350
- "links" => "links-input",
351
- "name" => "name-input",
352
- "webhook_url" => "webhook_url-input",
353
- }
354
- }.to_json,
355
- headers: {'Content-Type' => 'application/json'},
356
- )
357
- end
358
- end
359
- end
360
-
361
-
362
- end