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,8 @@
1
+
2
+ module GoCardless
3
+ end
4
+
5
+ module GoCardless
6
+ # Current version of the GC gem
7
+ VERSION = '0.1.0'
8
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::ApiService do
4
+ subject(:service) { described_class.new("https://api.example.com", "ak123", "abc123") }
5
+
6
+ it "uses basic auth" do
7
+ stub = stub_request(:get, 'https://ak123:abc123@api.example.com/customers')
8
+ service.make_request(:get, "/customers")
9
+ expect(stub).to have_been_requested
10
+ end
11
+
12
+ describe "making a get request without any parameters" do
13
+ it "is expected to call the correct stub" do
14
+ stub = stub_request(:get, /.*api.example.com\/customers/)
15
+ service.make_request(:get, "/customers")
16
+ expect(stub).to have_been_requested
17
+ end
18
+ end
19
+
20
+ describe "making a get request with query parameters" do
21
+ it "correctly passes the query parameters" do
22
+ stub = stub_request(:get, /.*api.example.com\/customers\?a=1&b=2/)
23
+ service.make_request(:get, "/customers", { a: 1, b: 2 })
24
+ expect(stub).to have_been_requested
25
+ end
26
+ end
27
+
28
+ describe "making a post request with some data" do
29
+ it "passes the data in as the post body" do
30
+ stub = stub_request(:post, /.*api.example.com\/customers/).
31
+ with(body: { given_name: "Jack", family_name: "Franklin" })
32
+ service.make_request(:post, "/customers", {
33
+ given_name: "Jack",
34
+ family_name: "Franklin"
35
+ })
36
+ expect(stub).to have_been_requested
37
+ end
38
+ end
39
+
40
+ describe "making a post request with data and custom header" do
41
+ it "passes the data in as the post body" do
42
+ stub = stub_request(:post, /.*api.example.com\/customers/).
43
+ with(
44
+ body: { given_name: "Jack", family_name: "Franklin" },
45
+ headers: { 'Foo' => 'Bar' }
46
+ )
47
+
48
+ service.make_request(:post, "/customers", {
49
+ given_name: "Jack",
50
+ family_name: "Franklin"
51
+ }, {
52
+ 'Foo' => 'Bar'
53
+ })
54
+ expect(stub).to have_been_requested
55
+ end
56
+ end
57
+
58
+ describe "making a put request with some data" do
59
+ it "passes the data in as the request body" do
60
+ stub = stub_request(:put, /.*api.example.com\/customers\/CU123/).
61
+ with(body: { given_name: "Jack", family_name: "Franklin" })
62
+ service.make_request(:put, "/customers/CU123",
63
+ given_name: "Jack",
64
+ family_name: "Franklin"
65
+ )
66
+ expect(stub).to have_been_requested
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Client do
4
+ subject { -> { described_class.new(options) } }
5
+
6
+ let(:options) do
7
+ {
8
+ environment: environment,
9
+ api_key: api_key,
10
+ api_secret: api_secret
11
+ }
12
+ end
13
+
14
+ context "when initialised without an API key" do
15
+ let(:environment) { :live }
16
+ let(:api_secret) { "MYSECRETTOKEN" }
17
+ let(:api_key) { nil }
18
+
19
+ it { is_expected.to raise_error("No API key ID given to GoCardless Client") }
20
+ end
21
+
22
+ context "when initialised without an API secret" do
23
+ let(:api_secret) { nil }
24
+ let(:environment) { :live }
25
+ let(:api_key) { "AK123" }
26
+
27
+ it { is_expected.to raise_error("No API secret given to GoCardless Client") }
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Error do
4
+ subject(:error) { described_class.new(api_error) }
5
+
6
+ let(:api_error) do
7
+ {
8
+ "documentation_url" => "https://developer.gocardless.com/pro#validation_failed",
9
+ "message" => "Validation failed",
10
+ "type" => "validation_failed",
11
+ "code" => 422,
12
+ "request_id" => "dd50eaaf-8213-48fe-90d6-5466872efbc4",
13
+ "errors" => [
14
+ {
15
+ "message" => "must be a number",
16
+ "field" => "branch_code"
17
+ }, {
18
+ "message" => "is the wrong length (should be 8 characters)",
19
+ "field" => "branch_code"
20
+ }
21
+ ]
22
+ }
23
+ end
24
+
25
+ specify do
26
+ expect(error.documentation_url).to eq("https://developer.gocardless.com/pro#validation_failed")
27
+ end
28
+
29
+ specify { expect(error.message).to eq("Validation failed") }
30
+ specify { expect(error.type).to eq("validation_failed") }
31
+ specify { expect(error.code).to eq(422) }
32
+ specify { expect(error.request_id).to eq("dd50eaaf-8213-48fe-90d6-5466872efbc4") }
33
+ specify do
34
+ expect(error.errors).to eq([
35
+ {
36
+ "message" => "must be a number",
37
+ "field" => "branch_code"
38
+ }, {
39
+ "message" => "is the wrong length (should be 8 characters)",
40
+ "field" => "branch_code"
41
+ }
42
+ ])
43
+ end
44
+ end
@@ -0,0 +1,85 @@
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
+
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Resources::CreditorBankAccount do
4
+ describe "initialising" do
5
+ let(:data) do
6
+ {
7
+
8
+
9
+ "account_holder_name" => "account_holder_name-input",
10
+
11
+
12
+
13
+ "account_number_ending" => "account_number_ending-input",
14
+
15
+
16
+
17
+ "bank_name" => "bank_name-input",
18
+
19
+
20
+
21
+ "country_code" => "country_code-input",
22
+
23
+
24
+
25
+ "created_at" => "created_at-input",
26
+
27
+
28
+
29
+ "currency" => "currency-input",
30
+
31
+
32
+
33
+ "enabled" => "enabled-input",
34
+
35
+
36
+
37
+ "id" => "id-input",
38
+
39
+
40
+
41
+ "links" => {
42
+
43
+ "creditor" => "creditor-input",
44
+
45
+ },
46
+
47
+
48
+
49
+ "metadata" => "metadata-input",
50
+
51
+
52
+ }
53
+ end
54
+
55
+ it "can be initialized from an uneveloped response" do
56
+ resource = described_class.new(data)
57
+
58
+
59
+ expect(resource.account_holder_name).to eq("account_holder_name-input")
60
+
61
+
62
+
63
+ expect(resource.account_number_ending).to eq("account_number_ending-input")
64
+
65
+
66
+
67
+ expect(resource.bank_name).to eq("bank_name-input")
68
+
69
+
70
+
71
+ expect(resource.country_code).to eq("country_code-input")
72
+
73
+
74
+
75
+ expect(resource.created_at).to eq("created_at-input")
76
+
77
+
78
+
79
+ expect(resource.currency).to eq("currency-input")
80
+
81
+
82
+
83
+ expect(resource.enabled).to eq("enabled-input")
84
+
85
+
86
+
87
+ expect(resource.id).to eq("id-input")
88
+
89
+
90
+
91
+
92
+ expect(resource.links.creditor).to eq("creditor-input")
93
+
94
+
95
+
96
+
97
+ expect(resource.metadata).to eq("metadata-input")
98
+
99
+
100
+ end
101
+
102
+ describe "#to_h" do
103
+ it "returns a hash representing the resource" do
104
+ expect(described_class.new(data).to_h).to eq(data)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Resources::Creditor do
4
+ describe "initialising" do
5
+ let(:data) do
6
+ {
7
+
8
+
9
+ "address_line1" => "address_line1-input",
10
+
11
+
12
+
13
+ "address_line2" => "address_line2-input",
14
+
15
+
16
+
17
+ "address_line3" => "address_line3-input",
18
+
19
+
20
+
21
+ "city" => "city-input",
22
+
23
+
24
+
25
+ "country_code" => "country_code-input",
26
+
27
+
28
+
29
+ "created_at" => "created_at-input",
30
+
31
+
32
+
33
+ "id" => "id-input",
34
+
35
+
36
+
37
+ "links" => {
38
+
39
+ "default_eur_payout_account" => "default_eur_payout_account-input",
40
+
41
+ "default_gbp_payout_account" => "default_gbp_payout_account-input",
42
+
43
+ "logo" => "logo-input",
44
+
45
+ },
46
+
47
+
48
+
49
+ "name" => "name-input",
50
+
51
+
52
+
53
+ "postal_code" => "postal_code-input",
54
+
55
+
56
+
57
+ "region" => "region-input",
58
+
59
+
60
+ }
61
+ end
62
+
63
+ it "can be initialized from an uneveloped response" do
64
+ resource = described_class.new(data)
65
+
66
+
67
+ expect(resource.address_line1).to eq("address_line1-input")
68
+
69
+
70
+
71
+ expect(resource.address_line2).to eq("address_line2-input")
72
+
73
+
74
+
75
+ expect(resource.address_line3).to eq("address_line3-input")
76
+
77
+
78
+
79
+ expect(resource.city).to eq("city-input")
80
+
81
+
82
+
83
+ expect(resource.country_code).to eq("country_code-input")
84
+
85
+
86
+
87
+ expect(resource.created_at).to eq("created_at-input")
88
+
89
+
90
+
91
+ expect(resource.id).to eq("id-input")
92
+
93
+
94
+
95
+
96
+ expect(resource.links.default_eur_payout_account).to eq("default_eur_payout_account-input")
97
+
98
+ expect(resource.links.default_gbp_payout_account).to eq("default_gbp_payout_account-input")
99
+
100
+ expect(resource.links.logo).to eq("logo-input")
101
+
102
+
103
+
104
+
105
+ expect(resource.name).to eq("name-input")
106
+
107
+
108
+
109
+ expect(resource.postal_code).to eq("postal_code-input")
110
+
111
+
112
+
113
+ expect(resource.region).to eq("region-input")
114
+
115
+
116
+ end
117
+
118
+ describe "#to_h" do
119
+ it "returns a hash representing the resource" do
120
+ expect(described_class.new(data).to_h).to eq(data)
121
+ end
122
+ end
123
+ end
124
+ end
125
+