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