pin_up 1.1.1 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 886e0ca286fef6c9bba66913d9316aea2bcf5d77
4
- data.tar.gz: ea47fe9051629aa4ad5245f3221d834d5d95da39
3
+ metadata.gz: c67d8075501e91bd3b435d0e505340c02205a535
4
+ data.tar.gz: 36267918b46bcc3bbeb595f3e8af798daba499f4
5
5
  SHA512:
6
- metadata.gz: 4bab9630b52f2d0a3c4331441a9954f79aed82622044d0c0898a65f4c17a22b842b1d62033a6c0dfcdf4fe0a8be318d1b36bb27781f7e1ead5a4e68be021b0ad
7
- data.tar.gz: 5681976d8d7e39fc61ac9da509a311823b273d12a9e585aeae2dbfc38101887559a8cbabe00ee45cdf7454dd3b7bae76944114ec44935c5d23c04fbcbb4fd372
6
+ metadata.gz: b5cc15ec66e259f6e3ef21c22b7fb4e936195ba84c22a2f8521b0ff130ba9e42bfa1a399b0986beafcfaab0c299d20b89c466c8e71d6b5dcd4129452da6f3500
7
+ data.tar.gz: 1e25012796615fa553563200ca24888d915b06d6c55348f3ac7fdbd6d8696226424593d722add3dda0fcba055f8a36f6a04cff6c3d7f851724b44a880f364ebd
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
@@ -1,7 +1,7 @@
1
1
  module Pin
2
2
  ##
3
3
  # Base Pin Error class
4
- class PinError < StandardError
4
+ class PinError
5
5
  def initialize(message = nil, http_status = nil)
6
6
  @message = message
7
7
  @http_status = http_status
@@ -17,17 +17,17 @@ module Pin
17
17
  when 400
18
18
  case response['error']
19
19
  when 'cannot_delete_primary_card'
20
- raise(Pin::InvalidResource, response['error_description'])
20
+ raise Pin::InvalidResource.new(response, response['error_description'])
21
21
  else
22
- raise(Pin::ChargeError, "#{response['error']}: #{response['error_description']}. Charge token: #{response['charge_token']}")
22
+ raise Pin::ChargeError.new(response)
23
23
  end
24
24
  when 402
25
- raise(Pin::InsufficientPinBalance, "#{response['error_description']}")
25
+ raise Pin::InsufficientPinBalance.new(response)
26
26
  when 404
27
- raise(Pin::ResourceNotFound, "#{response['error_description']}")
27
+ raise Pin::ResourceNotFound.new response
28
28
  when 422
29
29
  message = handle_bad_response(response)
30
- raise(Pin::InvalidResource, message)
30
+ raise Pin::InvalidResource.new(response, message)
31
31
  end
32
32
  end
33
33
 
@@ -48,22 +48,43 @@ module Pin
48
48
  end
49
49
 
50
50
  def self.handle_bad_request
51
- raise(Pin::ClientError, 'request :method must be one of get, post, put, patch or delete')
51
+ raise Pin::ClientError, 'request :method must be one of get, post, put, patch or delete'
52
52
  end
53
53
  end
54
54
 
55
- class ResourceNotFound < PinError
55
+ class SimpleError < StandardError
56
+ attr_accessor :response, :message
57
+ def initialize(response, message=nil)
58
+ @response = response
59
+ @message = message || @response['error_description']
60
+ end
61
+
62
+ def to_s
63
+ @message
64
+ end
65
+ end
66
+
67
+ class ResourceNotFound < SimpleError
56
68
  end
57
69
 
58
- class InvalidResource < PinError
70
+ class InvalidResource < SimpleError
59
71
  end
60
72
 
61
- class ChargeError < PinError
73
+ class ChargeError < StandardError
74
+ attr_accessor :response, :message
75
+ def initialize(response)
76
+ @response = response
77
+ @message = "#{@response['error']}: #{@response['error_description']}. Charge token: #{@response['charge_token']}"
78
+ end
79
+
80
+ def to_s
81
+ @message
82
+ end
62
83
  end
63
84
 
64
- class InsufficientPinBalance < PinError
85
+ class InsufficientPinBalance < SimpleError
65
86
  end
66
87
 
67
- class ClientError < PinError
88
+ class ClientError < StandardError
68
89
  end
69
90
  end
data/pin_up.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: pin_up 1.1.1 ruby lib
5
+ # stub: pin_up 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pin_up"
9
- s.version = "1.1.1"
9
+ s.version = "1.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Daniel Nitsikopoulos"]
14
- s.date = "2015-10-30"
14
+ s.date = "2015-11-14"
15
15
  s.description = "A Ruby gem wrapper for the pin-payments (pin.net.au) API"
16
16
  s.email = "dnitza@gmail.com"
17
17
  s.extra_rdoc_files = [
data/spec/errors_spec.rb CHANGED
@@ -6,12 +6,20 @@ describe 'Errors', :vcr, class: Pin::PinError do
6
6
  end
7
7
 
8
8
  it 'should raise a 404 error when looking for a customer that doesn\'t exist' do
9
- expect { Pin::Customer.find('foo') }.to raise_error(Pin::ResourceNotFound, 'The requested resource could not be found.')
9
+ expect { Pin::Customer.find('foo') }.to raise_error do |error|
10
+ expect(error).to be_a Pin::ResourceNotFound
11
+ expect(error.message).to eq 'The requested resource could not be found.'
12
+ expect(error.response).to be_a Hash
13
+ end
10
14
  end
11
15
 
12
16
  it 'should raise a 422 error when trying to update missing a param' do
13
17
  options = { email: 'dNitza@gmail.com', card: { address_line1: '12345 Fake Street', expiry_month: '05', expiry_year: '2016', cvc: '123', address_city: 'Melbourne', address_postcode: '1234', address_state: 'VIC', address_country: 'Australia' } }
14
- expect { Pin::Customer.update('cus_6XnfOD5bvQ1qkaf3LqmhfQ', options) }.to raise_error(Pin::InvalidResource, "card_number_invalid: Card number can't be blank card_name_invalid: Card name can't be blank ")
18
+ expect { Pin::Customer.update('cus_6XnfOD5bvQ1qkaf3LqmhfQ', options) }.to raise_error do |error|
19
+ expect(error).to be_a Pin::InvalidResource
20
+ expect(error.message).to eq "card_number_invalid: Card number can't be blank card_name_invalid: Card name can't be blank "
21
+ expect(error.response).to be_a Hash
22
+ end
15
23
  end
16
24
 
17
25
  it 'should raise a 422 error when trying to make a payment with an expired card' do
@@ -27,7 +35,11 @@ describe 'Errors', :vcr, class: Pin::PinError do
27
35
  address_state: 'WA',
28
36
  address_country: 'Australia'
29
37
  } }
30
- expect { Pin::Charges.create(options) }.to raise_error(Pin::InvalidResource, 'card_expiry_month_invalid: Card expiry month is expired card_expiry_year_invalid: Card expiry year is expired ')
38
+ expect { Pin::Charges.create(options) }.to raise_error do |error|
39
+ expect(error).to be_a Pin::InvalidResource
40
+ expect(error.message).to eq 'card_expiry_month_invalid: Card expiry month is expired card_expiry_year_invalid: Card expiry year is expired '
41
+ expect(error.response).to be_a Hash
42
+ end
31
43
  end
32
44
 
33
45
  it 'should raise a 400 error when trying to make a payment and a valid card gets declined' do
@@ -59,30 +71,40 @@ describe 'Errors', :vcr, class: Pin::PinError do
59
71
  address_state: 'WA',
60
72
  address_country: 'Australia'
61
73
  } }
62
- expect { Pin::Charges.create(options) }.to raise_error(Pin::InvalidResource, 'card_number_invalid: Card number is not valid ')
74
+ expect { Pin::Charges.create(options) }.to raise_error do |error|
75
+ expect(error).to be_a Pin::InvalidResource
76
+ expect(error.message).to eq 'card_number_invalid: Card number is not valid '
77
+ expect(error.response).to be_a Hash
78
+ end
63
79
  end
64
80
 
65
81
  it 'Should raise a ResourceNotFound error when can\'t find customer' do
66
- expect { Pin::Customer.charges('foo') }.to raise_error(Pin::ResourceNotFound, 'The requested resource could not be found.')
82
+ expect { Pin::Customer.charges('foo') }.to raise_error do |error|
83
+ expect(error).to be_a Pin::ResourceNotFound
84
+ expect(error.message).to eq 'The requested resource could not be found.'
85
+ expect(error.response).to be_a Hash
86
+ end
67
87
  end
68
88
 
69
89
  it 'should raise a 422 error if no 2nd argument is given' do
70
90
  options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_6XnfOD5bvQ1qkaf3LqmhfQ' }
71
91
  @charge = Pin::Charges.create(options)
72
- expect { Pin::Refund.create(@charge['token']) }.to raise_error(Pin::InvalidResource, "amount_invalid: Amount can't be blank amount_invalid: Amount is not a number ")
73
- end
74
-
75
- it 'should raise a 422 error if a value of less than 100 is given' do
76
- options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '100', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_6XnfOD5bvQ1qkaf3LqmhfQ' }
77
- @charge = Pin::Charges.create(options)
78
- # expect { Pin::Refund.create(@charge['token'], 90) }.to raise_error(Pin::InvalidResource, 'amount_invalid: Amount must be more than 100 ($1.00 AUD)')
92
+ expect { Pin::Refund.create(@charge['token']) }.to raise_error do |error|
93
+ expect(error).to be_a Pin::InvalidResource
94
+ expect(error.message).to eq "amount_invalid: Amount can't be blank amount_invalid: Amount is not a number "
95
+ expect(error.response).to be_a Hash
96
+ end
79
97
  end
80
98
 
81
99
  it 'should raise a 400 error when attempting to delete customer\'s primary card' do
82
100
  customer_token = 'cus_6XnfOD5bvQ1qkaf3LqmhfQ'
83
101
  cards = Pin::Customer.cards(customer_token)
84
102
  primary_card_token = cards.select{|card| card['primary'] }.first['token']
85
- expect { Pin::Customer.delete_card(customer_token, primary_card_token) }.to raise_error(Pin::InvalidResource, 'You cannot delete a customer\'s primary card token')
103
+ expect { Pin::Customer.delete_card(customer_token, primary_card_token) }.to raise_error do |error|
104
+ expect(error).to be_a Pin::InvalidResource
105
+ expect(error.message).to eq 'You cannot delete a customer\'s primary card token'
106
+ expect(error.response).to be_a Hash
107
+ end
86
108
  end
87
109
 
88
110
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "codeclimate-test-reporter"
1
+ require 'codeclimate-test-reporter'
2
2
  require 'simplecov'
3
3
 
4
4
  CodeClimate::TestReporter.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pin_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Nitsikopoulos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty