pin-ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pin/error.rb +17 -7
- data/lib/pin/version.rb +1 -1
- data/spec/error_spec.rb +21 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 356743431583ed5f8d65d66afc14b86284e78673
|
4
|
+
data.tar.gz: fdb3e0727ac8ca496c00046a52a6540c681804d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
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
|
17
|
-
@
|
18
|
-
@message = message
|
27
|
+
def error_description
|
28
|
+
@json_body['error_description']
|
19
29
|
end
|
20
30
|
|
21
|
-
def
|
22
|
-
|
31
|
+
def details
|
32
|
+
@json_body
|
23
33
|
end
|
24
34
|
|
25
35
|
def to_s
|
26
|
-
|
36
|
+
"HTTP Error #{@status}: #{error}"
|
27
37
|
end
|
28
38
|
end
|
data/lib/pin/version.rb
CHANGED
data/spec/error_spec.rb
ADDED
@@ -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.
|
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
|