pin_up 1.2.0 → 1.3.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/README.md +20 -0
- data/VERSION +1 -1
- data/lib/pin_up.rb +0 -1
- data/lib/pin_up/base.rb +3 -4
- data/lib/pin_up/charge.rb +1 -1
- data/lib/pin_up/client.rb +4 -3
- data/pin_up.gemspec +3 -4
- data/spec/base_spec.rb +5 -2
- data/spec/client_spec.rb +2 -31
- metadata +2 -3
- data/lib/pin_up/retrying_client.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f700bc2aa83973dd14ec89c9bff2bdb7b2fdfd78
|
4
|
+
data.tar.gz: bcc17c7fc2dc62c11cb92b3292d047bee18bc98d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b89a1203f95056d99e4734061a1bc6f2995b170e3ca24975d46087764692f6a61fe8b699a59a750db01bf328da315e21999ef099b9b31dc1d0f490eb4259ef8
|
7
|
+
data.tar.gz: 31b5c8ca1e3ab72d604020d9b1b1e55ec1b820f600ab7004f168eac96479dbc83cf5294004083dbc609f704be10c3e9b119371f488487b6bfd477fef6f81aa0e
|
data/README.md
CHANGED
@@ -233,6 +233,26 @@ A bank account token can only be used once to create a recipient. The token auto
|
|
233
233
|
|
234
234
|
Receipts have been extracted out into their [own gem](https://github.com/dNitza/pin_up_receipts)
|
235
235
|
|
236
|
+
## Exceptions
|
237
|
+
|
238
|
+
A number of different error types are built in:
|
239
|
+
|
240
|
+
### ResourceNotFound
|
241
|
+
The requested resource could not be found in Pin.
|
242
|
+
|
243
|
+
### InvalidResource
|
244
|
+
A number of parameters sent to Pin were invalid.
|
245
|
+
|
246
|
+
### ChargeError
|
247
|
+
Something went wrong while creating a charge in Pin. This could be due to insufficient funds, a card being declined or expired. A full list of possible errors is available [here](https://pin.net.au/docs/api/charges).
|
248
|
+
|
249
|
+
### InsufficientPinBalance
|
250
|
+
|
251
|
+
N.B. All of the above errors return an error object with a `message` and a `response` attribute. The response is the raw response from Pin (useful for logging).
|
252
|
+
|
253
|
+
### ClientError
|
254
|
+
An unsupported HTTP verb was used.
|
255
|
+
|
236
256
|
## Testing locally
|
237
257
|
Create a YAML file under 'spec' called 'test_data.yml' and add in:
|
238
258
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/pin_up.rb
CHANGED
data/lib/pin_up/base.rb
CHANGED
@@ -13,10 +13,11 @@ module Pin
|
|
13
13
|
# env: The environment you want to use.
|
14
14
|
# Leave blank for live and pass :test for test
|
15
15
|
# An error is raised if an invalid env is passed in.
|
16
|
-
def initialize(key = '', env = :live)
|
16
|
+
def initialize(key = '', env = :live, timeout = 1800)
|
17
17
|
@key = key
|
18
18
|
env = env.to_sym
|
19
19
|
@@auth = { username: @key, password: '' }
|
20
|
+
@@timeout = timeout
|
20
21
|
@@base_url = if env == :live
|
21
22
|
'https://api.pin.net.au/1/'
|
22
23
|
elsif env == :test
|
@@ -37,9 +38,7 @@ module Pin
|
|
37
38
|
# args: method (Symbol), args (Hash)
|
38
39
|
# eg. args => { url: 'cards', options: { ... } }
|
39
40
|
def self.make_request(method, args)
|
40
|
-
|
41
|
-
retrying_client = Pin::RetryingClient.new(client)
|
42
|
-
retrying_client.make_request
|
41
|
+
Pin::Client.new(method, args, @@base_url, @@auth, @@timeout).make_request
|
43
42
|
end
|
44
43
|
|
45
44
|
##
|
data/lib/pin_up/charge.rb
CHANGED
@@ -50,7 +50,7 @@ module Pin
|
|
50
50
|
# returns: charge object
|
51
51
|
# https://pin.net.au/docs/api/charges#put-charges
|
52
52
|
def self.capture(token)
|
53
|
-
build_response(make_request(:put, { url: "
|
53
|
+
build_response(make_request(:put, { url: "charges/#{token}/capture" } ))
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/pin_up/client.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
module Pin
|
2
2
|
class Client
|
3
|
-
def initialize(method, args, base_url, auth)
|
3
|
+
def initialize(method, args, base_url, auth, timeout)
|
4
4
|
@method = method
|
5
5
|
@args = args
|
6
6
|
@base_url = base_url
|
7
7
|
@auth = auth
|
8
|
+
@timeout = timeout
|
8
9
|
end
|
9
10
|
|
10
11
|
##
|
11
12
|
# Sends an authenticated request to pin's server
|
12
13
|
# args: method (Symbol), args (Hash)
|
13
14
|
# eg. args => { url: 'cards', options: { ... } }
|
14
|
-
def make_request
|
15
|
+
def make_request
|
15
16
|
if %i(get post put patch delete).include? @method
|
16
|
-
HTTParty.send(@method, "#{@base_url}#{@args[:url]}", body: @args[:options], basic_auth: @auth)
|
17
|
+
HTTParty.send(@method, "#{@base_url}#{@args[:url]}", body: @args[:options], basic_auth: @auth, timeout: @timeout)
|
17
18
|
else
|
18
19
|
Pin::PinError.handle_bad_request
|
19
20
|
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.
|
5
|
+
# stub: pin_up 1.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "pin_up"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.3.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 = "
|
14
|
+
s.date = "2016-03-31"
|
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 = [
|
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/pin_up/pin_errors.rb",
|
41
41
|
"lib/pin_up/recipient.rb",
|
42
42
|
"lib/pin_up/refund.rb",
|
43
|
-
"lib/pin_up/retrying_client.rb",
|
44
43
|
"lib/pin_up/transfer.rb",
|
45
44
|
"pin_up.gemspec",
|
46
45
|
"spec/balance_spec.rb",
|
data/spec/base_spec.rb
CHANGED
@@ -23,10 +23,13 @@ RSpec.describe 'Base', :vcr, class: Pin::Base do
|
|
23
23
|
expect { Pin::Base.new('KEY', :foo) }.to raise_error(RuntimeError, "'env' option must be :live or :test. Leave blank for live payments")
|
24
24
|
end
|
25
25
|
|
26
|
-
it 'should
|
26
|
+
it 'should succesfully connect to Pin' do
|
27
27
|
stub_request(:get, "https://#{@test_pin.key}:''@test-api.pin.net.au/1/customers")
|
28
28
|
expect(Pin::Base.make_request(:get, { url: 'customers' }).code).to eq 200
|
29
|
-
# expect(Pin::Base.auth_get('customers').code).to eq 200
|
30
29
|
end
|
31
30
|
|
31
|
+
it "raises a timeout error if we don't get a response in time" do
|
32
|
+
@test_pin = Pin::Base.new(ENV['PIN_SECRET'], :test, 0)
|
33
|
+
expect { Pin::Base.make_request(:get, { url: 'customers' }) }.to raise_error(Net::ReadTimeout)
|
34
|
+
end
|
32
35
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,37 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe 'Client', class: Pin::Client do
|
4
|
-
it 'delegates http requests to an inner object' do
|
5
|
-
inner = double(make_request: 'RESULT')
|
6
|
-
client = Pin::RetryingClient.new(inner)
|
7
|
-
expect(client.make_request).to eq('RESULT')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'retries if a request fails' do
|
11
|
-
inner = double
|
12
|
-
client = Pin::RetryingClient.new(inner)
|
13
|
-
times = 2
|
14
|
-
allow(inner).to receive(:make_request) do
|
15
|
-
raise "Oops" if (times -= 1) > 0
|
16
|
-
'RESULT'
|
17
|
-
end
|
18
|
-
expect(client.make_request).to eq('RESULT')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'gives up after a few tries' do
|
22
|
-
inner = double
|
23
|
-
client = Pin::RetryingClient.new(inner)
|
24
|
-
times = 4
|
25
|
-
allow(inner).to receive(:make_request) do
|
26
|
-
raise "Ooops!" if (times -= 1) > 0
|
27
|
-
end
|
28
|
-
expect{client.make_request}.to raise_error('Ooops!')
|
29
|
-
expect(inner).to have_received(:make_request).exactly(3).times
|
30
|
-
end
|
31
|
-
|
32
4
|
it 'fails if invalid http verb is used' do
|
33
|
-
|
34
|
-
client = Pin::RetryingClient.new(inner)
|
5
|
+
client = Pin::Client.new(:foo, {}, '', '', 30)
|
35
6
|
expect {client.make_request}.to raise_error(Pin::ClientError, 'request :method must be one of get, post, put, patch or delete')
|
36
7
|
end
|
37
|
-
end
|
8
|
+
end
|
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.
|
4
|
+
version: 1.3.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:
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -179,7 +179,6 @@ files:
|
|
179
179
|
- lib/pin_up/pin_errors.rb
|
180
180
|
- lib/pin_up/recipient.rb
|
181
181
|
- lib/pin_up/refund.rb
|
182
|
-
- lib/pin_up/retrying_client.rb
|
183
182
|
- lib/pin_up/transfer.rb
|
184
183
|
- pin_up.gemspec
|
185
184
|
- spec/balance_spec.rb
|