gocardless 1.12.0 → 1.13.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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +5 -0
- data/lib/gocardless/errors.rb +22 -3
- data/lib/gocardless/version.rb +1 -1
- data/spec/errors_spec.rb +32 -0
- data/spec/pre_authorization_spec.rb +12 -0
- data/spec/resource_spec.rb +12 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2a95fa2b5f9981334a068170e263b5e731e7de9
|
4
|
+
data.tar.gz: d8b06692dc05013bffc425c8d9cea9e6f9c96093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897beea106a75050566280a6627fa28da35006e77acc267fcbd68ec087bbdc77b475edd721ece791a822a5028e6da41adba32af1402c8b6f75770392e9a9ed4c
|
7
|
+
data.tar.gz: 23d195be6de1f617a5b2aaf7de2485e3419545f439af1faa340c8bff73072299f98c52f4bd83b775ee70ced58bcdd42f4227341f02732cf357813996ba91224b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/gocardless/errors.rb
CHANGED
@@ -10,15 +10,34 @@ module GoCardless
|
|
10
10
|
def initialize(response)
|
11
11
|
@response = response
|
12
12
|
@code = response.status
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
|
14
|
+
begin
|
15
|
+
parsed_response = MultiJson.decode(response.body)
|
16
|
+
errors = parsed_response["error"] || parsed_response["errors"]
|
17
|
+
@description = stringify_errors(errors)
|
18
|
+
rescue MultiJson::ParseError
|
19
|
+
@description = response.body ? response.body.strip : "Unknown error"
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def to_s
|
20
24
|
"#{super} [#{self.code}] #{self.description}"
|
21
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def stringify_errors(errors)
|
30
|
+
case errors
|
31
|
+
when Array
|
32
|
+
errors.join(", ")
|
33
|
+
when Hash
|
34
|
+
errors.flat_map do |field, messages|
|
35
|
+
messages.map { |message| "#{field} #{message}" }
|
36
|
+
end.join(", ")
|
37
|
+
else
|
38
|
+
errors.to_s
|
39
|
+
end
|
40
|
+
end
|
22
41
|
end
|
23
42
|
|
24
43
|
class ClientError < Error
|
data/lib/gocardless/version.rb
CHANGED
data/spec/errors_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardless::ApiError do
|
4
|
+
let(:response) { double(body: body, status: 500) }
|
5
|
+
let(:error) { GoCardless::ApiError.new(response) }
|
6
|
+
|
7
|
+
describe "#description" do
|
8
|
+
subject { error.description }
|
9
|
+
|
10
|
+
context "given no response body" do
|
11
|
+
let(:body) { nil }
|
12
|
+
it { is_expected.to eq "Unknown error" }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "given a json response body with an 'errors' hash" do
|
16
|
+
let(:body) do
|
17
|
+
MultiJson.dump(errors: { name: ["too short"], email: ["taken", "invalid"] })
|
18
|
+
end
|
19
|
+
it { is_expected.to eq "name too short, email taken, email invalid" }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "given a json response body with an 'error' array" do
|
23
|
+
let(:body) { MultiJson.dump(error: ["Server Error", "Oops"]) }
|
24
|
+
it { is_expected.to eq "Server Error, Oops" }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with a non-JSON body" do
|
28
|
+
let(:body) { "non-json body" }
|
29
|
+
it { is_expected.to eq "non-json body" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -13,6 +13,18 @@ describe GoCardless::PreAuthorization do
|
|
13
13
|
preauth.cancel!
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should allow you to create a pre-authorised bill" do
|
17
|
+
mocked_data = {
|
18
|
+
:pre_authorization_id=>"009988",
|
19
|
+
:amount=>"15.00",
|
20
|
+
:name=>"150 credits",
|
21
|
+
:charge_customer_at=>DateTime.new(2013,8,27,0,0,0,'0')
|
22
|
+
}
|
23
|
+
|
24
|
+
expect(client).to receive(:api_post).with('/bills/', :bill => mocked_data)
|
25
|
+
preauth.create_bill(mocked_data)
|
26
|
+
end
|
27
|
+
|
16
28
|
it_behaves_like "it has a query method for", "inactive"
|
17
29
|
it_behaves_like "it has a query method for", "active"
|
18
30
|
it_behaves_like "it has a query method for", "cancelled"
|
data/spec/resource_spec.rb
CHANGED
@@ -10,6 +10,18 @@ describe GoCardless::Resource do
|
|
10
10
|
props.each { |k,v| expect(resource.send(k)).to eq(v) }
|
11
11
|
end
|
12
12
|
|
13
|
+
describe "#inspect" do
|
14
|
+
let(:test_resource) do
|
15
|
+
Class.new(GoCardless::Resource) { reference_reader :foo_id }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "shows text" do
|
19
|
+
resource = test_resource.new
|
20
|
+
resource.instance_variable_set(:@foo_id, 123)
|
21
|
+
expect(resource.inspect).to match(/#<#<Class:[a-z0-9]+> foo_id=123>/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
describe "#date_writer" do
|
14
26
|
let(:test_resource) do
|
15
27
|
Class.new(GoCardless::Resource) { date_writer :created_at, :modified_at }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gocardless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Marr
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/gocardless/version.rb
|
129
129
|
- spec/bill_spec.rb
|
130
130
|
- spec/client_spec.rb
|
131
|
+
- spec/errors_spec.rb
|
131
132
|
- spec/gocardless_spec.rb
|
132
133
|
- spec/page_spec.rb
|
133
134
|
- spec/paginator_spec.rb
|
@@ -157,13 +158,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
160
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.4.
|
161
|
+
rubygems_version: 2.4.2
|
161
162
|
signing_key:
|
162
163
|
specification_version: 4
|
163
164
|
summary: Ruby wrapper for the GoCardless API
|
164
165
|
test_files:
|
165
166
|
- spec/bill_spec.rb
|
166
167
|
- spec/client_spec.rb
|
168
|
+
- spec/errors_spec.rb
|
167
169
|
- spec/gocardless_spec.rb
|
168
170
|
- spec/page_spec.rb
|
169
171
|
- spec/paginator_spec.rb
|