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