gocardless-pro 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +132 -0
  6. data/circle.yml +18 -0
  7. data/demo.rb +10 -0
  8. data/gocardless-pro.gemspec +27 -0
  9. data/lib/gocardless-pro.rb +243 -0
  10. data/lib/gocardless-pro/api_service.rb +57 -0
  11. data/lib/gocardless-pro/error.rb +42 -0
  12. data/lib/gocardless-pro/error/gocardless_error.rb +5 -0
  13. data/lib/gocardless-pro/error/invalid_api_usage_error.rb +5 -0
  14. data/lib/gocardless-pro/error/invalid_state_error.rb +5 -0
  15. data/lib/gocardless-pro/error/validation_error.rb +5 -0
  16. data/lib/gocardless-pro/list_response.rb +34 -0
  17. data/lib/gocardless-pro/paginator.rb +37 -0
  18. data/lib/gocardless-pro/request.rb +69 -0
  19. data/lib/gocardless-pro/resources/api_key.rb +62 -0
  20. data/lib/gocardless-pro/resources/creditor.rb +83 -0
  21. data/lib/gocardless-pro/resources/creditor_bank_account.rb +78 -0
  22. data/lib/gocardless-pro/resources/customer.rb +72 -0
  23. data/lib/gocardless-pro/resources/customer_bank_account.rb +80 -0
  24. data/lib/gocardless-pro/resources/event.rb +75 -0
  25. data/lib/gocardless-pro/resources/helper.rb +29 -0
  26. data/lib/gocardless-pro/resources/mandate.rb +70 -0
  27. data/lib/gocardless-pro/resources/payment.rb +86 -0
  28. data/lib/gocardless-pro/resources/payout.rb +66 -0
  29. data/lib/gocardless-pro/resources/publishable_api_key.rb +51 -0
  30. data/lib/gocardless-pro/resources/redirect_flow.rb +104 -0
  31. data/lib/gocardless-pro/resources/refund.rb +70 -0
  32. data/lib/gocardless-pro/resources/role.rb +101 -0
  33. data/lib/gocardless-pro/resources/subscription.rb +152 -0
  34. data/lib/gocardless-pro/resources/user.rb +60 -0
  35. data/lib/gocardless-pro/response.rb +77 -0
  36. data/lib/gocardless-pro/services/api_key_service.rb +130 -0
  37. data/lib/gocardless-pro/services/base_service.rb +29 -0
  38. data/lib/gocardless-pro/services/creditor_bank_account_service.rb +122 -0
  39. data/lib/gocardless-pro/services/creditor_service.rb +112 -0
  40. data/lib/gocardless-pro/services/customer_bank_account_service.rb +153 -0
  41. data/lib/gocardless-pro/services/customer_service.rb +112 -0
  42. data/lib/gocardless-pro/services/event_service.rb +80 -0
  43. data/lib/gocardless-pro/services/helper_service.rb +97 -0
  44. data/lib/gocardless-pro/services/mandate_service.rb +170 -0
  45. data/lib/gocardless-pro/services/payment_service.rb +164 -0
  46. data/lib/gocardless-pro/services/payout_service.rb +80 -0
  47. data/lib/gocardless-pro/services/publishable_api_key_service.rb +130 -0
  48. data/lib/gocardless-pro/services/redirect_flow_service.rb +96 -0
  49. data/lib/gocardless-pro/services/refund_service.rb +126 -0
  50. data/lib/gocardless-pro/services/role_service.rb +127 -0
  51. data/lib/gocardless-pro/services/subscription_service.rb +133 -0
  52. data/lib/gocardless-pro/services/user_service.rb +148 -0
  53. data/lib/gocardless-pro/version.rb +8 -0
  54. data/spec/api_service_spec.rb +69 -0
  55. data/spec/client_spec.rb +29 -0
  56. data/spec/error_spec.rb +44 -0
  57. data/spec/resources/api_key_spec.rb +85 -0
  58. data/spec/resources/creditor_bank_account_spec.rb +109 -0
  59. data/spec/resources/creditor_spec.rb +125 -0
  60. data/spec/resources/customer_bank_account_spec.rb +109 -0
  61. data/spec/resources/customer_spec.rb +127 -0
  62. data/spec/resources/event_spec.rb +113 -0
  63. data/spec/resources/helper_spec.rb +23 -0
  64. data/spec/resources/mandate_spec.rb +97 -0
  65. data/spec/resources/payment_spec.rb +129 -0
  66. data/spec/resources/payout_spec.rb +89 -0
  67. data/spec/resources/publishable_api_key_spec.rb +63 -0
  68. data/spec/resources/redirect_flow_spec.rb +97 -0
  69. data/spec/resources/refund_spec.rb +77 -0
  70. data/spec/resources/role_spec.rb +63 -0
  71. data/spec/resources/subscription_spec.rb +157 -0
  72. data/spec/resources/user_spec.rb +85 -0
  73. data/spec/response_spec.rb +79 -0
  74. data/spec/services/api_key_service_spec.rb +362 -0
  75. data/spec/services/creditor_bank_account_service_spec.rb +365 -0
  76. data/spec/services/creditor_service_spec.rb +339 -0
  77. data/spec/services/customer_bank_account_service_spec.rb +404 -0
  78. data/spec/services/customer_service_spec.rb +365 -0
  79. data/spec/services/event_service_spec.rb +172 -0
  80. data/spec/services/helper_service_spec.rb +123 -0
  81. data/spec/services/mandate_service_spec.rb +449 -0
  82. data/spec/services/payment_service_spec.rb +497 -0
  83. data/spec/services/payout_service_spec.rb +172 -0
  84. data/spec/services/publishable_api_key_service_spec.rb +336 -0
  85. data/spec/services/redirect_flow_service_spec.rb +208 -0
  86. data/spec/services/refund_service_spec.rb +279 -0
  87. data/spec/services/role_service_spec.rb +336 -0
  88. data/spec/services/subscription_service_spec.rb +488 -0
  89. data/spec/services/user_service_spec.rb +433 -0
  90. data/spec/spec_helper.rb +91 -0
  91. metadata +255 -0
@@ -0,0 +1,404 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Services::CustomerBankAccountService 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.customer_bank_accounts.create(new_resource) }
18
+ context "with a valid request" do
19
+ let(:new_resource) do
20
+ {
21
+
22
+ "account_holder_name" => "account_holder_name-input",
23
+ "account_number_ending" => "account_number_ending-input",
24
+ "bank_name" => "bank_name-input",
25
+ "country_code" => "country_code-input",
26
+ "created_at" => "created_at-input",
27
+ "currency" => "currency-input",
28
+ "enabled" => "enabled-input",
29
+ "id" => "id-input",
30
+ "links" => "links-input",
31
+ "metadata" => "metadata-input",
32
+ }
33
+ end
34
+
35
+ before do
36
+ stub_request(:post, /.*api.gocardless.com\/customer_bank_accounts/).
37
+ with(
38
+ body: {
39
+ customer_bank_accounts: {
40
+
41
+ "account_holder_name" => "account_holder_name-input",
42
+ "account_number_ending" => "account_number_ending-input",
43
+ "bank_name" => "bank_name-input",
44
+ "country_code" => "country_code-input",
45
+ "created_at" => "created_at-input",
46
+ "currency" => "currency-input",
47
+ "enabled" => "enabled-input",
48
+ "id" => "id-input",
49
+ "links" => "links-input",
50
+ "metadata" => "metadata-input",
51
+ }
52
+ }
53
+ ).
54
+ to_return(
55
+ body: {
56
+ customer_bank_accounts: {
57
+
58
+ "account_holder_name" => "account_holder_name-input",
59
+ "account_number_ending" => "account_number_ending-input",
60
+ "bank_name" => "bank_name-input",
61
+ "country_code" => "country_code-input",
62
+ "created_at" => "created_at-input",
63
+ "currency" => "currency-input",
64
+ "enabled" => "enabled-input",
65
+ "id" => "id-input",
66
+ "links" => "links-input",
67
+ "metadata" => "metadata-input",
68
+ }
69
+ }.to_json,
70
+ :headers => {'Content-Type' => 'application/json'}
71
+ )
72
+ end
73
+
74
+ it "creates and returns the resource" do
75
+ expect(post_create_response).to be_a(GoCardless::Resources::CustomerBankAccount)
76
+ end
77
+ end
78
+
79
+ context "with a request that returns a validation error" do
80
+ let(:new_resource) { {} }
81
+
82
+ before do
83
+ stub_request(:post, /.*api.gocardless.com\/customer_bank_accounts/).to_return(
84
+ body: {
85
+ error: {
86
+ type: 'validation_failed',
87
+ code: 422,
88
+ errors: [
89
+ { message: 'test error message', field: 'test_field' }
90
+ ]
91
+ }
92
+ }.to_json,
93
+ headers: {'Content-Type' => 'application/json'},
94
+ status: 422
95
+ )
96
+ end
97
+
98
+ it "throws the correct error" do
99
+ expect { post_create_response }.to raise_error(GoCardless::ValidationError)
100
+ end
101
+ end
102
+ end
103
+
104
+
105
+
106
+
107
+
108
+ describe "#list" do
109
+ describe "with no filters" do
110
+ subject(:get_list_response) { client.customer_bank_accounts.list }
111
+
112
+ before do
113
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts/).to_return(
114
+ body: {
115
+ customer_bank_accounts: [{
116
+
117
+ "account_holder_name" => "account_holder_name-input",
118
+ "account_number_ending" => "account_number_ending-input",
119
+ "bank_name" => "bank_name-input",
120
+ "country_code" => "country_code-input",
121
+ "created_at" => "created_at-input",
122
+ "currency" => "currency-input",
123
+ "enabled" => "enabled-input",
124
+ "id" => "id-input",
125
+ "links" => "links-input",
126
+ "metadata" => "metadata-input",
127
+ }],
128
+ meta: {
129
+ cursors: {
130
+ before: nil,
131
+ after: "ABC123"
132
+ }
133
+ }
134
+ }.to_json,
135
+ :headers => {'Content-Type' => 'application/json'}
136
+ )
137
+ end
138
+
139
+ it "wraps each item in the resource class" do
140
+ expect(get_list_response.map { |x| x.class }.uniq.first).to eq(GoCardless::Resources::CustomerBankAccount)
141
+
142
+
143
+
144
+ expect(get_list_response.first.account_holder_name).to eq("account_holder_name-input")
145
+
146
+
147
+
148
+ expect(get_list_response.first.account_number_ending).to eq("account_number_ending-input")
149
+
150
+
151
+
152
+ expect(get_list_response.first.bank_name).to eq("bank_name-input")
153
+
154
+
155
+
156
+ expect(get_list_response.first.country_code).to eq("country_code-input")
157
+
158
+
159
+
160
+ expect(get_list_response.first.created_at).to eq("created_at-input")
161
+
162
+
163
+
164
+ expect(get_list_response.first.currency).to eq("currency-input")
165
+
166
+
167
+
168
+ expect(get_list_response.first.enabled).to eq("enabled-input")
169
+
170
+
171
+
172
+ expect(get_list_response.first.id).to eq("id-input")
173
+
174
+
175
+
176
+
177
+
178
+ expect(get_list_response.first.metadata).to eq("metadata-input")
179
+
180
+
181
+ end
182
+
183
+ it "exposes the cursors for before and after" do
184
+ expect(get_list_response.before).to eq(nil)
185
+ expect(get_list_response.after).to eq("ABC123")
186
+ end
187
+ end
188
+ end
189
+
190
+ describe "#all" do
191
+ let!(:first_response_stub) do
192
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts$/).to_return(
193
+ body: {
194
+ customer_bank_accounts: [{
195
+
196
+ "account_holder_name" => "account_holder_name-input",
197
+ "account_number_ending" => "account_number_ending-input",
198
+ "bank_name" => "bank_name-input",
199
+ "country_code" => "country_code-input",
200
+ "created_at" => "created_at-input",
201
+ "currency" => "currency-input",
202
+ "enabled" => "enabled-input",
203
+ "id" => "id-input",
204
+ "links" => "links-input",
205
+ "metadata" => "metadata-input",
206
+ }],
207
+ meta: {
208
+ cursors: { after: 'AB345' },
209
+ limit: 1
210
+ }
211
+ }.to_json,
212
+ :headers => {'Content-Type' => 'application/json'}
213
+ )
214
+ end
215
+
216
+ let!(:second_response_stub) do
217
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts\?after=AB345/).to_return(
218
+ body: {
219
+ customer_bank_accounts: [{
220
+
221
+ "account_holder_name" => "account_holder_name-input",
222
+ "account_number_ending" => "account_number_ending-input",
223
+ "bank_name" => "bank_name-input",
224
+ "country_code" => "country_code-input",
225
+ "created_at" => "created_at-input",
226
+ "currency" => "currency-input",
227
+ "enabled" => "enabled-input",
228
+ "id" => "id-input",
229
+ "links" => "links-input",
230
+ "metadata" => "metadata-input",
231
+ }],
232
+ meta: {
233
+ limit: 2,
234
+ cursors: {}
235
+ }
236
+ }.to_json,
237
+ :headers => {'Content-Type' => 'application/json'}
238
+ )
239
+ end
240
+
241
+ it "automatically makes the extra requests" do
242
+ expect(client.customer_bank_accounts.all.to_a.length).to eq(2)
243
+ expect(first_response_stub).to have_been_requested
244
+ expect(second_response_stub).to have_been_requested
245
+ end
246
+ end
247
+
248
+
249
+
250
+
251
+
252
+
253
+ describe "#get" do
254
+ let(:id) { "ID123" }
255
+
256
+ subject(:get_response) { client.customer_bank_accounts.get(id) }
257
+
258
+ context "when there is a customer_bank_account to return" do
259
+ before do
260
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts\/ID123/).to_return(
261
+ body: {
262
+ customer_bank_accounts: {
263
+
264
+ "account_holder_name" => "account_holder_name-input",
265
+ "account_number_ending" => "account_number_ending-input",
266
+ "bank_name" => "bank_name-input",
267
+ "country_code" => "country_code-input",
268
+ "created_at" => "created_at-input",
269
+ "currency" => "currency-input",
270
+ "enabled" => "enabled-input",
271
+ "id" => "id-input",
272
+ "links" => "links-input",
273
+ "metadata" => "metadata-input",
274
+ }
275
+ }.to_json,
276
+ :headers => {'Content-Type' => 'application/json'}
277
+ )
278
+ end
279
+
280
+ it "wraps the response in a resource" do
281
+ expect(get_response).to be_a(GoCardless::Resources::CustomerBankAccount)
282
+ end
283
+ end
284
+ end
285
+
286
+
287
+
288
+
289
+
290
+
291
+ describe "#update" do
292
+ subject(:put_update_response) { client.customer_bank_accounts.update(id, update_params) }
293
+ let(:id) { "ABC123" }
294
+
295
+ context "with a valid request" do
296
+ let(:update_params) { { "hello" => "world" } }
297
+
298
+ let!(:stub) do
299
+ stub_request(:put, /.*api.gocardless.com\/customer_bank_accounts\/ABC123/).to_return(
300
+ body: {
301
+ customer_bank_accounts: {
302
+
303
+ "account_holder_name" => "account_holder_name-input",
304
+ "account_number_ending" => "account_number_ending-input",
305
+ "bank_name" => "bank_name-input",
306
+ "country_code" => "country_code-input",
307
+ "created_at" => "created_at-input",
308
+ "currency" => "currency-input",
309
+ "enabled" => "enabled-input",
310
+ "id" => "id-input",
311
+ "links" => "links-input",
312
+ "metadata" => "metadata-input",
313
+ }
314
+ }.to_json,
315
+ :headers => {'Content-Type' => 'application/json'}
316
+ )
317
+ end
318
+
319
+ it "updates and returns the resource" do
320
+ expect(put_update_response).to be_a(GoCardless::Resources::CustomerBankAccount)
321
+ expect(stub).to have_been_requested
322
+ end
323
+ end
324
+ end
325
+
326
+
327
+
328
+
329
+
330
+ describe "#disable" do
331
+
332
+
333
+ subject(:post_response) { client.customer_bank_accounts.disable(resource_id) }
334
+
335
+ let(:resource_id) { "ABC123" }
336
+
337
+ let!(:stub) do
338
+ # /customer_bank_accounts/%v/actions/disable
339
+ stub_url = "/customer_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
340
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
341
+ body: {
342
+ customer_bank_accounts: {
343
+
344
+ "account_holder_name" => "account_holder_name-input",
345
+ "account_number_ending" => "account_number_ending-input",
346
+ "bank_name" => "bank_name-input",
347
+ "country_code" => "country_code-input",
348
+ "created_at" => "created_at-input",
349
+ "currency" => "currency-input",
350
+ "enabled" => "enabled-input",
351
+ "id" => "id-input",
352
+ "links" => "links-input",
353
+ "metadata" => "metadata-input",
354
+ }
355
+ }.to_json,
356
+ headers: {'Content-Type' => 'application/json'},
357
+ )
358
+ end
359
+
360
+ it "wraps the response and calls the right endpoint" do
361
+ expect(post_response).to be_a(GoCardless::Resources::CustomerBankAccount)
362
+
363
+ expect(stub).to have_been_requested
364
+ end
365
+
366
+ context "when the request needs a body and custom header" do
367
+
368
+ let(:body) { { foo: 'bar' } }
369
+ let(:headers) { { 'Foo' => 'Bar' } }
370
+ subject(:post_response) { client.customer_bank_accounts.disable(resource_id, body, headers) }
371
+
372
+ let(:resource_id) { "ABC123" }
373
+
374
+ let!(:stub) do
375
+ # /customer_bank_accounts/%v/actions/disable
376
+ stub_url = "/customer_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
377
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
378
+ with(
379
+ body: { foo: 'bar' },
380
+ headers: { 'Foo' => 'Bar' }
381
+ ).to_return(
382
+ body: {
383
+ customer_bank_accounts: {
384
+
385
+ "account_holder_name" => "account_holder_name-input",
386
+ "account_number_ending" => "account_number_ending-input",
387
+ "bank_name" => "bank_name-input",
388
+ "country_code" => "country_code-input",
389
+ "created_at" => "created_at-input",
390
+ "currency" => "currency-input",
391
+ "enabled" => "enabled-input",
392
+ "id" => "id-input",
393
+ "links" => "links-input",
394
+ "metadata" => "metadata-input",
395
+ }
396
+ }.to_json,
397
+ headers: {'Content-Type' => 'application/json'},
398
+ )
399
+ end
400
+ end
401
+ end
402
+
403
+
404
+ end
@@ -0,0 +1,365 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Services::CustomerService 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.customers.create(new_resource) }
18
+ context "with a valid request" do
19
+ let(:new_resource) do
20
+ {
21
+
22
+ "address_line1" => "address_line1-input",
23
+ "address_line2" => "address_line2-input",
24
+ "address_line3" => "address_line3-input",
25
+ "city" => "city-input",
26
+ "country_code" => "country_code-input",
27
+ "created_at" => "created_at-input",
28
+ "email" => "email-input",
29
+ "family_name" => "family_name-input",
30
+ "given_name" => "given_name-input",
31
+ "id" => "id-input",
32
+ "metadata" => "metadata-input",
33
+ "postal_code" => "postal_code-input",
34
+ "region" => "region-input",
35
+ }
36
+ end
37
+
38
+ before do
39
+ stub_request(:post, /.*api.gocardless.com\/customers/).
40
+ with(
41
+ body: {
42
+ customers: {
43
+
44
+ "address_line1" => "address_line1-input",
45
+ "address_line2" => "address_line2-input",
46
+ "address_line3" => "address_line3-input",
47
+ "city" => "city-input",
48
+ "country_code" => "country_code-input",
49
+ "created_at" => "created_at-input",
50
+ "email" => "email-input",
51
+ "family_name" => "family_name-input",
52
+ "given_name" => "given_name-input",
53
+ "id" => "id-input",
54
+ "metadata" => "metadata-input",
55
+ "postal_code" => "postal_code-input",
56
+ "region" => "region-input",
57
+ }
58
+ }
59
+ ).
60
+ to_return(
61
+ body: {
62
+ customers: {
63
+
64
+ "address_line1" => "address_line1-input",
65
+ "address_line2" => "address_line2-input",
66
+ "address_line3" => "address_line3-input",
67
+ "city" => "city-input",
68
+ "country_code" => "country_code-input",
69
+ "created_at" => "created_at-input",
70
+ "email" => "email-input",
71
+ "family_name" => "family_name-input",
72
+ "given_name" => "given_name-input",
73
+ "id" => "id-input",
74
+ "metadata" => "metadata-input",
75
+ "postal_code" => "postal_code-input",
76
+ "region" => "region-input",
77
+ }
78
+ }.to_json,
79
+ :headers => {'Content-Type' => 'application/json'}
80
+ )
81
+ end
82
+
83
+ it "creates and returns the resource" do
84
+ expect(post_create_response).to be_a(GoCardless::Resources::Customer)
85
+ end
86
+ end
87
+
88
+ context "with a request that returns a validation error" do
89
+ let(:new_resource) { {} }
90
+
91
+ before do
92
+ stub_request(:post, /.*api.gocardless.com\/customers/).to_return(
93
+ body: {
94
+ error: {
95
+ type: 'validation_failed',
96
+ code: 422,
97
+ errors: [
98
+ { message: 'test error message', field: 'test_field' }
99
+ ]
100
+ }
101
+ }.to_json,
102
+ headers: {'Content-Type' => 'application/json'},
103
+ status: 422
104
+ )
105
+ end
106
+
107
+ it "throws the correct error" do
108
+ expect { post_create_response }.to raise_error(GoCardless::ValidationError)
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+
115
+
116
+
117
+ describe "#list" do
118
+ describe "with no filters" do
119
+ subject(:get_list_response) { client.customers.list }
120
+
121
+ before do
122
+ stub_request(:get, /.*api.gocardless.com\/customers/).to_return(
123
+ body: {
124
+ customers: [{
125
+
126
+ "address_line1" => "address_line1-input",
127
+ "address_line2" => "address_line2-input",
128
+ "address_line3" => "address_line3-input",
129
+ "city" => "city-input",
130
+ "country_code" => "country_code-input",
131
+ "created_at" => "created_at-input",
132
+ "email" => "email-input",
133
+ "family_name" => "family_name-input",
134
+ "given_name" => "given_name-input",
135
+ "id" => "id-input",
136
+ "metadata" => "metadata-input",
137
+ "postal_code" => "postal_code-input",
138
+ "region" => "region-input",
139
+ }],
140
+ meta: {
141
+ cursors: {
142
+ before: nil,
143
+ after: "ABC123"
144
+ }
145
+ }
146
+ }.to_json,
147
+ :headers => {'Content-Type' => 'application/json'}
148
+ )
149
+ end
150
+
151
+ it "wraps each item in the resource class" do
152
+ expect(get_list_response.map { |x| x.class }.uniq.first).to eq(GoCardless::Resources::Customer)
153
+
154
+
155
+
156
+ expect(get_list_response.first.address_line1).to eq("address_line1-input")
157
+
158
+
159
+
160
+ expect(get_list_response.first.address_line2).to eq("address_line2-input")
161
+
162
+
163
+
164
+ expect(get_list_response.first.address_line3).to eq("address_line3-input")
165
+
166
+
167
+
168
+ expect(get_list_response.first.city).to eq("city-input")
169
+
170
+
171
+
172
+ expect(get_list_response.first.country_code).to eq("country_code-input")
173
+
174
+
175
+
176
+ expect(get_list_response.first.created_at).to eq("created_at-input")
177
+
178
+
179
+
180
+ expect(get_list_response.first.email).to eq("email-input")
181
+
182
+
183
+
184
+ expect(get_list_response.first.family_name).to eq("family_name-input")
185
+
186
+
187
+
188
+ expect(get_list_response.first.given_name).to eq("given_name-input")
189
+
190
+
191
+
192
+ expect(get_list_response.first.id).to eq("id-input")
193
+
194
+
195
+
196
+ expect(get_list_response.first.metadata).to eq("metadata-input")
197
+
198
+
199
+
200
+ expect(get_list_response.first.postal_code).to eq("postal_code-input")
201
+
202
+
203
+
204
+ expect(get_list_response.first.region).to eq("region-input")
205
+
206
+
207
+ end
208
+
209
+ it "exposes the cursors for before and after" do
210
+ expect(get_list_response.before).to eq(nil)
211
+ expect(get_list_response.after).to eq("ABC123")
212
+ end
213
+ end
214
+ end
215
+
216
+ describe "#all" do
217
+ let!(:first_response_stub) do
218
+ stub_request(:get, /.*api.gocardless.com\/customers$/).to_return(
219
+ body: {
220
+ customers: [{
221
+
222
+ "address_line1" => "address_line1-input",
223
+ "address_line2" => "address_line2-input",
224
+ "address_line3" => "address_line3-input",
225
+ "city" => "city-input",
226
+ "country_code" => "country_code-input",
227
+ "created_at" => "created_at-input",
228
+ "email" => "email-input",
229
+ "family_name" => "family_name-input",
230
+ "given_name" => "given_name-input",
231
+ "id" => "id-input",
232
+ "metadata" => "metadata-input",
233
+ "postal_code" => "postal_code-input",
234
+ "region" => "region-input",
235
+ }],
236
+ meta: {
237
+ cursors: { after: 'AB345' },
238
+ limit: 1
239
+ }
240
+ }.to_json,
241
+ :headers => {'Content-Type' => 'application/json'}
242
+ )
243
+ end
244
+
245
+ let!(:second_response_stub) do
246
+ stub_request(:get, /.*api.gocardless.com\/customers\?after=AB345/).to_return(
247
+ body: {
248
+ customers: [{
249
+
250
+ "address_line1" => "address_line1-input",
251
+ "address_line2" => "address_line2-input",
252
+ "address_line3" => "address_line3-input",
253
+ "city" => "city-input",
254
+ "country_code" => "country_code-input",
255
+ "created_at" => "created_at-input",
256
+ "email" => "email-input",
257
+ "family_name" => "family_name-input",
258
+ "given_name" => "given_name-input",
259
+ "id" => "id-input",
260
+ "metadata" => "metadata-input",
261
+ "postal_code" => "postal_code-input",
262
+ "region" => "region-input",
263
+ }],
264
+ meta: {
265
+ limit: 2,
266
+ cursors: {}
267
+ }
268
+ }.to_json,
269
+ :headers => {'Content-Type' => 'application/json'}
270
+ )
271
+ end
272
+
273
+ it "automatically makes the extra requests" do
274
+ expect(client.customers.all.to_a.length).to eq(2)
275
+ expect(first_response_stub).to have_been_requested
276
+ expect(second_response_stub).to have_been_requested
277
+ end
278
+ end
279
+
280
+
281
+
282
+
283
+
284
+
285
+ describe "#get" do
286
+ let(:id) { "ID123" }
287
+
288
+ subject(:get_response) { client.customers.get(id) }
289
+
290
+ context "when there is a customer to return" do
291
+ before do
292
+ stub_request(:get, /.*api.gocardless.com\/customers\/ID123/).to_return(
293
+ body: {
294
+ customers: {
295
+
296
+ "address_line1" => "address_line1-input",
297
+ "address_line2" => "address_line2-input",
298
+ "address_line3" => "address_line3-input",
299
+ "city" => "city-input",
300
+ "country_code" => "country_code-input",
301
+ "created_at" => "created_at-input",
302
+ "email" => "email-input",
303
+ "family_name" => "family_name-input",
304
+ "given_name" => "given_name-input",
305
+ "id" => "id-input",
306
+ "metadata" => "metadata-input",
307
+ "postal_code" => "postal_code-input",
308
+ "region" => "region-input",
309
+ }
310
+ }.to_json,
311
+ :headers => {'Content-Type' => 'application/json'}
312
+ )
313
+ end
314
+
315
+ it "wraps the response in a resource" do
316
+ expect(get_response).to be_a(GoCardless::Resources::Customer)
317
+ end
318
+ end
319
+ end
320
+
321
+
322
+
323
+
324
+
325
+
326
+ describe "#update" do
327
+ subject(:put_update_response) { client.customers.update(id, update_params) }
328
+ let(:id) { "ABC123" }
329
+
330
+ context "with a valid request" do
331
+ let(:update_params) { { "hello" => "world" } }
332
+
333
+ let!(:stub) do
334
+ stub_request(:put, /.*api.gocardless.com\/customers\/ABC123/).to_return(
335
+ body: {
336
+ customers: {
337
+
338
+ "address_line1" => "address_line1-input",
339
+ "address_line2" => "address_line2-input",
340
+ "address_line3" => "address_line3-input",
341
+ "city" => "city-input",
342
+ "country_code" => "country_code-input",
343
+ "created_at" => "created_at-input",
344
+ "email" => "email-input",
345
+ "family_name" => "family_name-input",
346
+ "given_name" => "given_name-input",
347
+ "id" => "id-input",
348
+ "metadata" => "metadata-input",
349
+ "postal_code" => "postal_code-input",
350
+ "region" => "region-input",
351
+ }
352
+ }.to_json,
353
+ :headers => {'Content-Type' => 'application/json'}
354
+ )
355
+ end
356
+
357
+ it "updates and returns the resource" do
358
+ expect(put_update_response).to be_a(GoCardless::Resources::Customer)
359
+ expect(stub).to have_been_requested
360
+ end
361
+ end
362
+ end
363
+
364
+
365
+ end