gocardless 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 994ce7a109fb1c42f0f66f94e7fb38cff7ea1197
4
- data.tar.gz: 8ac64f43f760b62644faccb532fadc0f86b89413
3
+ metadata.gz: d2a95fa2b5f9981334a068170e263b5e731e7de9
4
+ data.tar.gz: d8b06692dc05013bffc425c8d9cea9e6f9c96093
5
5
  SHA512:
6
- metadata.gz: 815fb08aef927dbdfc4f285534b4cea78e346949fb0cbee8a5c36ba2cd679f978ebfa5bc652dd5925854feaf17a3d977b7563d9a887cd69904de99c6c25b9c6e
7
- data.tar.gz: 47e2766271e9d6df79f1909409c8f128632e4ff1d9476bc81b5bbd3e810eb8a4a14ac360475dd0459c534375151b8a073261ae5a2c40a3727726ae23903ea4f6
6
+ metadata.gz: 897beea106a75050566280a6627fa28da35006e77acc267fcbd68ec087bbdc77b475edd721ece791a822a5028e6da41adba32af1402c8b6f75770392e9a9ed4c
7
+ data.tar.gz: 23d195be6de1f617a5b2aaf7de2485e3419545f439af1faa340c8bff73072299f98c52f4bd83b775ee70ced58bcdd42f4227341f02732cf357813996ba91224b
@@ -6,6 +6,8 @@ rvm:
6
6
  - 1.9.2
7
7
  - jruby-19mode
8
8
  - rbx-2
9
+ install:
10
+ - bundle install --retry=3
9
11
  notifications:
10
12
  email:
11
13
  recipients:
@@ -1,3 +1,8 @@
1
+ ## 1.13.0 - May 05, 2015
2
+
3
+ - Better handling of API error messages
4
+
5
+
1
6
  ## 1.12.0 - October 31, 2014
2
7
 
3
8
  - Update Gem Dependencies
@@ -10,15 +10,34 @@ module GoCardless
10
10
  def initialize(response)
11
11
  @response = response
12
12
  @code = response.status
13
- body = MultiJson.decode(response.body) rescue nil
14
- if body.is_a? Hash
15
- @description = body["error"] || response.body.strip || "Unknown error"
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
@@ -1,3 +1,3 @@
1
1
  module GoCardless
2
- VERSION = '1.12.0'.freeze
2
+ VERSION = '1.13.0'.freeze
3
3
  end
@@ -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"
@@ -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.12.0
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: 2014-10-31 00:00:00.000000000 Z
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.1
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