gocardless-pro 0.1.1 → 0.2.0

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.
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,433 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Services::UserService 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.users.create(new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "created_at" => "created_at-input",
23
- "email" => "email-input",
24
- "enabled" => "enabled-input",
25
- "family_name" => "family_name-input",
26
- "given_name" => "given_name-input",
27
- "id" => "id-input",
28
- "links" => "links-input",
29
- }
30
- end
31
-
32
- before do
33
- stub_request(:post, /.*api.gocardless.com\/users/).
34
- with(
35
- body: {
36
- users: {
37
-
38
- "created_at" => "created_at-input",
39
- "email" => "email-input",
40
- "enabled" => "enabled-input",
41
- "family_name" => "family_name-input",
42
- "given_name" => "given_name-input",
43
- "id" => "id-input",
44
- "links" => "links-input",
45
- }
46
- }
47
- ).
48
- to_return(
49
- body: {
50
- users: {
51
-
52
- "created_at" => "created_at-input",
53
- "email" => "email-input",
54
- "enabled" => "enabled-input",
55
- "family_name" => "family_name-input",
56
- "given_name" => "given_name-input",
57
- "id" => "id-input",
58
- "links" => "links-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::User)
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\/users/).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.users.list }
102
-
103
- before do
104
- stub_request(:get, /.*api.gocardless.com\/users/).to_return(
105
- body: {
106
- users: [{
107
-
108
- "created_at" => "created_at-input",
109
- "email" => "email-input",
110
- "enabled" => "enabled-input",
111
- "family_name" => "family_name-input",
112
- "given_name" => "given_name-input",
113
- "id" => "id-input",
114
- "links" => "links-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::User)
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.email).to eq("email-input")
137
-
138
-
139
-
140
- expect(get_list_response.first.enabled).to eq("enabled-input")
141
-
142
-
143
-
144
- expect(get_list_response.first.family_name).to eq("family_name-input")
145
-
146
-
147
-
148
- expect(get_list_response.first.given_name).to eq("given_name-input")
149
-
150
-
151
-
152
- expect(get_list_response.first.id).to eq("id-input")
153
-
154
-
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\/users$/).to_return(
169
- body: {
170
- users: [{
171
-
172
- "created_at" => "created_at-input",
173
- "email" => "email-input",
174
- "enabled" => "enabled-input",
175
- "family_name" => "family_name-input",
176
- "given_name" => "given_name-input",
177
- "id" => "id-input",
178
- "links" => "links-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\/users\?after=AB345/).to_return(
191
- body: {
192
- users: [{
193
-
194
- "created_at" => "created_at-input",
195
- "email" => "email-input",
196
- "enabled" => "enabled-input",
197
- "family_name" => "family_name-input",
198
- "given_name" => "given_name-input",
199
- "id" => "id-input",
200
- "links" => "links-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.users.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.users.get(id) }
227
-
228
- context "when there is a user to return" do
229
- before do
230
- stub_request(:get, /.*api.gocardless.com\/users\/ID123/).to_return(
231
- body: {
232
- users: {
233
-
234
- "created_at" => "created_at-input",
235
- "email" => "email-input",
236
- "enabled" => "enabled-input",
237
- "family_name" => "family_name-input",
238
- "given_name" => "given_name-input",
239
- "id" => "id-input",
240
- "links" => "links-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::User)
249
- end
250
- end
251
- end
252
-
253
-
254
-
255
-
256
-
257
-
258
- describe "#update" do
259
- subject(:put_update_response) { client.users.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\/users\/ABC123/).to_return(
267
- body: {
268
- users: {
269
-
270
- "created_at" => "created_at-input",
271
- "email" => "email-input",
272
- "enabled" => "enabled-input",
273
- "family_name" => "family_name-input",
274
- "given_name" => "given_name-input",
275
- "id" => "id-input",
276
- "links" => "links-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::User)
285
- expect(stub).to have_been_requested
286
- end
287
- end
288
- end
289
-
290
-
291
-
292
-
293
-
294
- describe "#enable" do
295
-
296
-
297
- subject(:post_response) { client.users.enable(resource_id) }
298
-
299
- let(:resource_id) { "ABC123" }
300
-
301
- let!(:stub) do
302
- # /users/%v/actions/enable
303
- stub_url = "/users/:identity/actions/enable".gsub(':identity', resource_id)
304
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
305
- body: {
306
- users: {
307
-
308
- "created_at" => "created_at-input",
309
- "email" => "email-input",
310
- "enabled" => "enabled-input",
311
- "family_name" => "family_name-input",
312
- "given_name" => "given_name-input",
313
- "id" => "id-input",
314
- "links" => "links-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::User)
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.users.enable(resource_id, body, headers) }
332
-
333
- let(:resource_id) { "ABC123" }
334
-
335
- let!(:stub) do
336
- # /users/%v/actions/enable
337
- stub_url = "/users/:identity/actions/enable".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
- users: {
345
-
346
- "created_at" => "created_at-input",
347
- "email" => "email-input",
348
- "enabled" => "enabled-input",
349
- "family_name" => "family_name-input",
350
- "given_name" => "given_name-input",
351
- "id" => "id-input",
352
- "links" => "links-input",
353
- }
354
- }.to_json,
355
- headers: {'Content-Type' => 'application/json'},
356
- )
357
- end
358
- end
359
- end
360
-
361
-
362
-
363
-
364
-
365
- describe "#disable" do
366
-
367
-
368
- subject(:post_response) { client.users.disable(resource_id) }
369
-
370
- let(:resource_id) { "ABC123" }
371
-
372
- let!(:stub) do
373
- # /users/%v/actions/disable
374
- stub_url = "/users/:identity/actions/disable".gsub(':identity', resource_id)
375
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
376
- body: {
377
- users: {
378
-
379
- "created_at" => "created_at-input",
380
- "email" => "email-input",
381
- "enabled" => "enabled-input",
382
- "family_name" => "family_name-input",
383
- "given_name" => "given_name-input",
384
- "id" => "id-input",
385
- "links" => "links-input",
386
- }
387
- }.to_json,
388
- headers: {'Content-Type' => 'application/json'},
389
- )
390
- end
391
-
392
- it "wraps the response and calls the right endpoint" do
393
- expect(post_response).to be_a(GoCardless::Resources::User)
394
-
395
- expect(stub).to have_been_requested
396
- end
397
-
398
- context "when the request needs a body and custom header" do
399
-
400
- let(:body) { { foo: 'bar' } }
401
- let(:headers) { { 'Foo' => 'Bar' } }
402
- subject(:post_response) { client.users.disable(resource_id, body, headers) }
403
-
404
- let(:resource_id) { "ABC123" }
405
-
406
- let!(:stub) do
407
- # /users/%v/actions/disable
408
- stub_url = "/users/:identity/actions/disable".gsub(':identity', resource_id)
409
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
410
- with(
411
- body: { foo: 'bar' },
412
- headers: { 'Foo' => 'Bar' }
413
- ).to_return(
414
- body: {
415
- users: {
416
-
417
- "created_at" => "created_at-input",
418
- "email" => "email-input",
419
- "enabled" => "enabled-input",
420
- "family_name" => "family_name-input",
421
- "given_name" => "given_name-input",
422
- "id" => "id-input",
423
- "links" => "links-input",
424
- }
425
- }.to_json,
426
- headers: {'Content-Type' => 'application/json'},
427
- )
428
- end
429
- end
430
- end
431
-
432
-
433
- end