pin-ruby 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef6026d3b852d6ee89457f5ffa667240e8afeed4
4
- data.tar.gz: 6f6a1d08ac02ff4be018f5db73d37651f29d80d7
3
+ metadata.gz: 356743431583ed5f8d65d66afc14b86284e78673
4
+ data.tar.gz: fdb3e0727ac8ca496c00046a52a6540c681804d9
5
5
  SHA512:
6
- metadata.gz: 0bbf4aa9eec9d2378c714558dbf2c0ae207615ac805df66f0d30012022781d035b3730f0a22c54e688bcd5846bc310cfb4f9e92b3c6793bee7c4bcf0e067ab13
7
- data.tar.gz: 546e874080efdd509125e49e2f8a725dca8f42b0822ed31e01bc3e8f560b81ef6fc163b208cb34a97f427fbf8d0668a6bedfc36e838bff120fca35c126ae6c22
6
+ metadata.gz: fffa9b5c27e783bac2d2641805c0520dd2849fb701f18a8484b1b3d1163635695d8aa88cbd6f3c56d0bb91c7792de2df5c7692027748357c135a78c60035591e
7
+ data.tar.gz: 32125fab08f51c572997cc27c4c3152a1ec1bfc54ce173da8c6ff2e74e9d7cfc998c3ab84c5b50c2398eebeb5c1f5f3799c85c8be49c57433b8733867e21c7ba
data/lib/pin/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  class Pin::Error < StandardError
2
4
 
3
5
  # Possible Responses
@@ -11,18 +13,26 @@ class Pin::Error < StandardError
11
13
  # 404 - (resource_not_found) No resource was found at this URL.
12
14
  # 500 - Server errors
13
15
 
14
- attr_accessor :code, :message
16
+ attr_accessor :status, :json_body
17
+
18
+ def initialize(status, json_body)
19
+ @status = status
20
+ @json_body = JSON.parse(json_body)
21
+ end
22
+
23
+ def error
24
+ @json_body['error']
25
+ end
15
26
 
16
- def initialize code, message
17
- @code = code
18
- @message = message
27
+ def error_description
28
+ @json_body['error_description']
19
29
  end
20
30
 
21
- def message
22
- "HTTP Error #{@code}: #{@message}"
31
+ def details
32
+ @json_body
23
33
  end
24
34
 
25
35
  def to_s
26
- message
36
+ "HTTP Error #{@status}: #{error}"
27
37
  end
28
38
  end
data/lib/pin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pin
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'pin/error'
2
+ require 'spec_helper'
3
+
4
+ describe 'error' do
5
+ it 'requires a status and json body' do
6
+ expect { Pin::Error.new() }.to raise_error(ArgumentError)
7
+ end
8
+
9
+ context 'valid values' do
10
+ status = '402'
11
+ json_body = '{"error":"card_declined","error_description":"The card was declined","charge_token":"ch_X3TI-S1LGFmo30zNc4GUaw"}'
12
+
13
+ subject { Pin::Error.new(status, json_body) }
14
+
15
+ its(:status) { should == '402' }
16
+ its(:error_description) { should == 'The card was declined' }
17
+ its(:error) { should == 'card_declined' }
18
+ its(:details) { should == {'error' => 'card_declined', 'error_description' => 'The card was declined', 'charge_token' => 'ch_X3TI-S1LGFmo30zNc4GUaw'}}
19
+ its(:to_s) { should == 'HTTP Error 402: card_declined'}
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pin-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Shimmins
@@ -156,6 +156,7 @@ files:
156
156
  - lib/pin/version.rb
157
157
  - pin-ruby.gemspec
158
158
  - spec/configuration_spec.rb
159
+ - spec/error_spec.rb
159
160
  - spec/spec_helper.rb
160
161
  homepage: https://bitbucket.org/shimms/pin-ruby
161
162
  licenses:
@@ -183,4 +184,5 @@ specification_version: 4
183
184
  summary: A Ruby library for interacting with v1 of the Pin Payments API
184
185
  test_files:
185
186
  - spec/configuration_spec.rb
187
+ - spec/error_spec.rb
186
188
  - spec/spec_helper.rb