pin_up 0.9.4 → 0.9.5

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: 391267df12d830f0f10802fe7db17cfaedd16ba8
4
- data.tar.gz: 5bb490e4420cd5f985e9cbb37f053013b6217c1e
3
+ metadata.gz: 569c2387bbe572f2e680d34ccc7319d663fd2941
4
+ data.tar.gz: 2e4ff4fc878584bf9938d2d7dd0bdd4b20b248e7
5
5
  SHA512:
6
- metadata.gz: 38c198c75ef69a73fb7901329e67fac7b4196e37177f22b807fc8c157f099f31b16a970eaeeb27a797a62793bd27fafcd4787deae8f62caacda264d18823133b
7
- data.tar.gz: 4bed768f5b877730539027b5cb3bae4cc826aa2eacf3577a61da7bb040dd4271c632c35a0208dfe7995fdcc090540367cee8afa677ea01fa3fa4d05fa9cf2898
6
+ metadata.gz: 429922018edf82e1cd70f9982961a43f2a335937655463af14640c821bfb6cdad01cb51ffcbe5ec34f0201ce0454e19bc12a48c8ba758f5edbeab86f8be9860a
7
+ data.tar.gz: 1a65fd45399e990c5730c166b91d5f88155323cd66aa9604c3f1ef1d3d75e95eb340c204d398e5cff4b7c96879ce51e73ad50a3b55c883282ae0bf0fcf9c742b
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ LineLength:
2
+ Enabled: false
3
+
4
+ BlockAlignment:
5
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.0-preview1
data/Guardfile CHANGED
@@ -2,7 +2,7 @@
2
2
  # More info at https://github.com/guard/guard#readme
3
3
  guard :rspec do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
6
  watch('spec/spec_helper.rb') { "spec" }
7
7
 
8
8
  # Rails example
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  guard :rspec do
26
26
  watch(%r{^spec/.+_spec\.rb$})
27
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
27
+ watch(%r{^lib/pin_up/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
28
28
  watch('spec/spec_helper.rb') { "spec" }
29
29
 
30
30
  # Rails example
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
data/lib/pin_up/base.rb CHANGED
@@ -1,41 +1,38 @@
1
1
  module Pin
2
2
  ##
3
- # This class sets up a few things like the base URL and provides a few utility methods to be shared between classes.
3
+ # This class sets up a few things like the base URL and provides a few
4
+ # utility methods to be shared between classes.
4
5
  class Base
5
6
  include HTTParty
6
7
 
8
+ attr_reader :key
7
9
  ##
8
10
  # Create a new Pin instance
9
11
  # Args:
10
12
  # key: Your Pin secret key
11
- # env: The environment you want to use. Leave blank for live and pass in :test for test
13
+ # env: The environment you want to use.
14
+ # Leave blank for live and pass :test for test
12
15
  # An error is raised if an invalid env is passed in.
13
- def initialize(key = "", env = :live)
16
+ def initialize(key = '', env = :live)
14
17
  @key = key
15
18
  env = env.to_sym
16
- @@auth = {username: key, password: ''}
19
+ @@auth = { username: @key, password: '' }
17
20
  @@base_url = if env == :live
18
- "https://api.pin.net.au/1/"
21
+ 'https://api.pin.net.au/1/'
19
22
  elsif env == :test
20
- "https://test-api.pin.net.au/1/"
23
+ 'https://test-api.pin.net.au/1/'
21
24
  else
22
- raise "'env' option must be :live or :test. Leave blank for live payments"
25
+ fail "'env' option must be :live or :test. Leave blank for live payments"
23
26
  end
24
27
  end
25
28
 
26
- ##
27
- # Provides access to your key if needed
28
- def key
29
- @key
30
- end
31
-
32
29
  ##
33
30
  # Provides access to the base URL if needed
34
- def uri
31
+ def base_uri
35
32
  @@base_url
36
33
  end
37
34
 
38
- protected
35
+ # protected
39
36
 
40
37
  ##
41
38
  # Sends an authorised GET request to pins server
@@ -67,15 +64,19 @@ module Pin
67
64
  end
68
65
 
69
66
  ##
70
- # Builds a response of a collection if the response code is 200 otherwise an empty array is returned
71
- def self.build_collection_response(response, pagination=false)
67
+ # Builds a response of a collection if the response code is 200
68
+ # otherwise an empty array is returned
69
+ def self.build_collection_response(response, pagination = false)
72
70
  models = []
73
71
  if response.code == 200
74
72
  if pagination
75
73
  response.parsed_response['response'].each do |model|
76
74
  models << model
77
75
  end
78
- return {response: models, pagination: response.parsed_response['pagination']}
76
+ return {
77
+ response: models,
78
+ pagination: response.parsed_response['pagination']
79
+ }
79
80
  else
80
81
  response.parsed_response['response'].each do |model|
81
82
  models << model
@@ -87,4 +88,4 @@ module Pin
87
88
  # models
88
89
  end
89
90
  end
90
- end
91
+ end
data/lib/pin_up/card.rb CHANGED
@@ -2,7 +2,6 @@ module Pin
2
2
  ##
3
3
  # This class models Pin's Cards API
4
4
  class Card < Base
5
-
6
5
  ##
7
6
  # creates a card given a hash of options
8
7
  # https://pin.net.au/docs/api/cards
@@ -15,4 +14,4 @@ module Pin
15
14
  build_response(auth_post('cards', options))
16
15
  end
17
16
  end
18
- end
17
+ end
data/lib/pin_up/charge.rb CHANGED
@@ -11,8 +11,8 @@ module Pin
11
11
  # and the pagination hash with [:pagination]
12
12
  #
13
13
  # https://pin.net.au/docs/api/charges#get-charges
14
- def self.all(page=nil, pagination=false)
15
- build_collection_response(auth_get("charges?page=#{page}"),pagination)
14
+ def self.all(page = nil, pagination = false)
15
+ build_collection_response(auth_get("charges?page=#{page}"), pagination)
16
16
  end
17
17
 
18
18
  ##
@@ -29,29 +29,28 @@ module Pin
29
29
  # returns: a collection of charge objects
30
30
  # https://pin.net.au/docs/api/charges#search-charges
31
31
  def self.search(options = {})
32
- term = ""
32
+ term = ''
33
33
  options.each do |key, option|
34
- term += "#{key.to_s}=#{URI::encode(option)}&"
34
+ term += "#{key.to_s}=#{URI.encode(option)}&"
35
35
  end
36
36
  build_response(auth_get("charges/search?#{term}"))
37
37
  end
38
38
 
39
- # Create a charge given charge details and a card, a card_token or acustomer_token
39
+ # Create a charge given charge details and a card,
40
+ # a card_token or a customer_token
40
41
  # args: options (Hash)
41
42
  # returns: a charge object
42
43
  # https://pin.net.au/docs/api/charges#post-charges
43
44
  def self.create(options = {})
44
- build_response(auth_post("charges", options))
45
+ build_response(auth_post('charges', options))
45
46
  end
46
47
 
47
48
  # Captures a previously authorised charge and returns its details.
48
49
  # args: charge-token (String)
49
50
  # returns: charge object
50
51
  # https://pin.net.au/docs/api/charges#put-charges
51
-
52
52
  def self.capture(token)
53
53
  build_response(auth_put("/charges/#{token}/capture"))
54
54
  end
55
-
56
55
  end
57
- end
56
+ end
@@ -2,7 +2,6 @@ module Pin
2
2
  ##
3
3
  # This class models Pins Customers API
4
4
  class Customer < Base
5
-
6
5
  ##
7
6
  # Lists all customers for your account
8
7
  # args: page (Fixnum), pagination (Boolean)
@@ -12,7 +11,7 @@ module Pin
12
11
  # and the pagination hash with [:pagination]
13
12
  #
14
13
  # https://pin.net.au/docs/api/customers#get-customers
15
- def self.all(page=nil, pagination=false)
14
+ def self.all(page = nil, pagination = false)
16
15
  build_collection_response(auth_get("customers?page=#{page}"), pagination)
17
16
  end
18
17
 
@@ -23,9 +22,9 @@ module Pin
23
22
  # https://pin.net.au/docs/api/customers#post-customers
24
23
  def self.create(email, card)
25
24
  options = if card.respond_to?(:to_hash)
26
- {card: card.to_hash}
25
+ { card: card.to_hash }
27
26
  else
28
- {card_token: card}
27
+ { card_token: card }
29
28
  end.merge(email: email)
30
29
 
31
30
  build_response(auth_post('customers', options))
@@ -41,11 +40,13 @@ module Pin
41
40
  end
42
41
 
43
42
  ##
44
- # Update a customer for your account given a token and any of: email, card (hash),card_token
43
+ # Update a customer for your account given a token
44
+ # and any of: email, card (hash),card_token
45
45
  # args: token (String), options (Hash)
46
46
  # returns: a customer object
47
47
  # https://pin.net.au/docs/api/customers#put-customer
48
- # NB: When providing a card (hash), you need to specify the full list of details.
48
+ # NB: When providing a card (hash), you need to specify
49
+ # the full list of details.
49
50
  def self.update(token, options = {})
50
51
  build_response(auth_put("customers/#{token}", options))
51
52
  end
@@ -59,8 +60,10 @@ module Pin
59
60
  # and the pagination hash with [:pagination]
60
61
  #
61
62
  # https://pin.net.au/docs/api/customers#get-customers-charges
62
- def self.charges(token, page=nil, pagination=false)
63
- build_collection_response(auth_get("customers/#{token}/charges?page=#{page}"), pagination)
63
+ def self.charges(token, page = nil, pagination = false)
64
+ build_collection_response(
65
+ auth_get("customers/#{token}/charges?page=#{page}"), pagination
66
+ )
64
67
  end
65
68
  end
66
- end
69
+ end
@@ -1,40 +1,45 @@
1
1
  module Pin
2
+ ##
3
+ # Base Pin Eror class
2
4
  class PinError < Exception
3
-
4
- def initialize(message=nil, http_status=nil)
5
+ def initialize(message = nil, http_status = nil)
5
6
  @message = message
6
7
  @http_status = http_status
7
8
  end
8
9
 
9
10
  def to_s
10
- status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
11
+ status_string = @http_status.nil? ? '' : "(Status #{@http_status}) "
11
12
  "#{status_string}#{@message}"
12
13
  end
13
14
 
14
15
  def self.handle_error(http_status, response)
15
16
  case http_status
16
17
  when 400
17
- raise(Pin::ChargeError, "#{response['error']}: #{response['error_description']}. Charge token: #{response['charge_token']}")
18
+ fail(Pin::ChargeError, "#{response['error']}: #{response['error_description']}. Charge token: #{response['charge_token']}")
18
19
  when 402
19
- raise(Pin::InsufficientPinBalance, "#{response['error_description']}")
20
+ fail(Pin::InsufficientPinBalance, "#{response['error_description']}")
20
21
  when 404
21
- raise(Pin::ResourceNotFound, "#{response['error_description']}")
22
+ fail(Pin::ResourceNotFound, "#{response['error_description']}")
22
23
  when 422
23
- message = ""
24
- begin
25
- response['messages'].each do |m|
26
- message += "#{m['code']}: #{m['message']}"
27
- end
28
- rescue
29
- begin response['messages']['amount'][0]
30
- message = "#{response['error']}: #{response['error_description']}. Amount: #{response['messages']['amount'][0]}"
31
- rescue
32
- message = "#{response['error']}: #{response['error_description']}"
33
- end
24
+ message = handle_bad_response(response)
25
+ fail(Pin::InvalidResource, message)
26
+ end
27
+ end
34
28
 
35
- end
36
- raise(Pin::InvalidResource, message)
29
+ def self.handle_bad_response(response)
30
+ message = ''
31
+ begin
32
+ response['messages'].each do |m|
33
+ message += "#{m['code']}: #{m['message']}"
34
+ end
35
+ rescue
36
+ begin response['messages']['amount'][0]
37
+ message = "#{response['error']}: #{response['error_description']}. Amount: #{response['messages']['amount'][0]}"
38
+ rescue
39
+ message = "#{response['error']}: #{response['error_description']}"
40
+ end
37
41
  end
42
+ message
38
43
  end
39
44
  end
40
45
 
@@ -47,7 +52,6 @@ module Pin
47
52
  class ChargeError < PinError
48
53
  end
49
54
 
50
- class InsufficientPinBalance <PinError
55
+ class InsufficientPinBalance < PinError
51
56
  end
52
-
53
- end
57
+ end
data/lib/pin_up/refund.rb CHANGED
@@ -2,7 +2,6 @@ module Pin
2
2
  ##
3
3
  # This class models Pin's Charges API
4
4
  class Refund < Base
5
-
6
5
  ##
7
6
  # Find a refund by charge token
8
7
  # returns: a collection of refund objects
@@ -23,8 +22,8 @@ module Pin
23
22
  # if no amount is passed in, the full amount of the charge will be refunded
24
23
  # https://pin.net.au/docs/api/refunds#post-refunds
25
24
  def self.create(token, amount = nil)
26
- options = {amount: amount}
25
+ options = { amount: amount }
27
26
  build_response(auth_post("charges/#{token}/refunds", options))
28
27
  end
29
28
  end
30
- end
29
+ end
data/lib/pin_up.rb CHANGED
@@ -8,4 +8,4 @@ require 'pin_up/charge'
8
8
  require 'pin_up/customer'
9
9
  require 'pin_up/refund'
10
10
 
11
- require 'pin_up/pin_errors'
11
+ require 'pin_up/pin_errors'
data/pin_up.gemspec CHANGED
@@ -2,11 +2,11 @@
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 0.9.4 ruby lib
5
+ # stub: pin_up 0.9.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pin_up"
9
- s.version = "0.9.4"
9
+ s.version = "0.9.5"
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"]
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
29
29
  ".idea/scopes/scope_settings.xml",
30
30
  ".idea/vcs.xml",
31
31
  ".idea/workspace.xml",
32
+ ".rubocop.yml",
33
+ ".ruby-version",
32
34
  ".travis.yml",
33
35
  "Gemfile",
34
36
  "Gemfile.lock",
data/spec/base_spec.rb CHANGED
@@ -1,29 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Base", :vcr, class: Pin::Base do
3
+ describe 'Base', :vcr, class: Pin::Base do
4
4
  before(:each) do
5
- @test_pin = Pin::Base.new(ENV["PIN_SECRET"], :test)
5
+ @test_pin = Pin::Base.new(ENV['PIN_SECRET'], :test)
6
6
  end
7
7
 
8
- it "should set key correctly" do
9
- @pin = Pin::Base.new("KEY", :live)
10
- expect(@pin.key).to eq "KEY"
8
+ it 'should set key correctly' do
9
+ @pin = Pin::Base.new('KEY', :live)
10
+ expect(@pin.key).to eq 'KEY'
11
11
  end
12
12
 
13
- it "should set environment to live if no env set" do
14
- @pin = Pin::Base.new("KEY", :live)
15
- expect(@pin.uri).to eq "https://api.pin.net.au/1/"
13
+ it 'should set environment to live if no env set' do
14
+ @pin = Pin::Base.new('KEY', :live)
15
+ expect(@pin.base_uri).to eq 'https://api.pin.net.au/1/'
16
16
  end
17
17
 
18
- it "should set environment to test when set" do
19
- expect(@test_pin.uri).to eq "https://test-api.pin.net.au/1/"
18
+ it 'should set environment to test when set' do
19
+ expect(@test_pin.base_uri).to eq 'https://test-api.pin.net.au/1/'
20
20
  end
21
21
 
22
- it "should raise an error if anything other than '' :live or :test is passed to a new instance" do
23
- expect{Pin::Base.new("KEY", :foo)}.to raise_error(RuntimeError, "'env' option must be :live or :test. Leave blank for live payments")
22
+ it 'should raise an error if anything other than '' :live or :test is passed to a new instance' do
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 list succesfully connect to Pin" do
26
+ it 'should list 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.auth_get('customers').code).to eq 200
29
29
  end
data/spec/cards_spec.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Card", :vcr, class: Pin::Card do
3
+ describe 'Card', :vcr, class: Pin::Card do
4
4
  before(:each) do
5
- Pin::Base.new(ENV["PIN_SECRET"], :test)
5
+ Pin::Base.new(ENV['PIN_SECRET'], :test)
6
6
  end
7
7
 
8
- it "should create a card and respond with the card detail from pin" do
9
- options = {number: "5520000000000000", expiry_month: "12", expiry_year: "2018", cvc: "123", name: "Roland Robot", address_line1: "123 Fake Road", address_line2: "", address_city: "Melbourne", address_postcode: "1223", address_state: "Vic", address_country: "AU"}
8
+ it 'should create a card and respond with the card detail from pin' do
9
+ options = { number: '5520000000000000', expiry_month: '12', expiry_year: '2018', cvc: '123', name: 'Roland Robot', address_line1: '123 Fake Road', address_line2: '', address_city: 'Melbourne', address_postcode: '1223', address_state: 'Vic', address_country: 'AU' }
10
10
  Pin::Card.create(options)['token'].should match(/^[a-z]{4}[_]/)
11
11
  end
12
- end
12
+ end
data/spec/charges_spec.rb CHANGED
@@ -1,47 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Charge", :vcr, class: Pin::Charges do
3
+ describe 'Charge', :vcr, class: Pin::Charges do
4
4
  before(:each) do
5
- Pin::Base.new(ENV["PIN_SECRET"], :test)
5
+ Pin::Base.new(ENV['PIN_SECRET'], :test)
6
6
  end
7
7
 
8
- it "should list charges in Pin" do
8
+ it 'should list charges in Pin' do
9
9
  Pin::Charges.all.should_not == []
10
10
  end
11
11
 
12
- it "should show a charge given a token" do
13
- Pin::Charges.find("ch_0kdOMXP7gG0_W_Vh8qAWdA")["token"].should match(/^[a-z]{2}[_]/)
12
+ it 'should show a charge given a token' do
13
+ Pin::Charges.find('ch_0kdOMXP7gG0_W_Vh8qAWdA')['token'].should match(/^[a-z]{2}[_]/)
14
14
  end
15
15
 
16
- it "should show a charge given a search term" do
17
- Pin::Charges.search({query: "mid Plan - My Focusbook", end_date: "Mar 25, 2013"}).should_not == []
16
+ it 'should show a charge given a search term' do
17
+ Pin::Charges.search(query: 'mid Plan - My Focusbook', end_date: 'Mar 25, 2013').should_not == []
18
18
  end
19
19
 
20
- it "should not show a charge if end_date is out of range" do
21
- Pin::Charges.search({end_date: "Mar 25, 2011"}).should == []
20
+ it 'should not show a charge if end_date is out of range' do
21
+ Pin::Charges.search(end_date: 'Mar 25, 2011').should == []
22
22
  end
23
23
 
24
- it "should create a charge given details" do
25
- 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_8ImkZdEZ6BXUA6NcJDZg_g" }
26
- Pin::Charges.create(options)["success"].should eq true
24
+ it 'should create a charge given details' do
25
+ 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_8ImkZdEZ6BXUA6NcJDZg_g' }
26
+ Pin::Charges.create(options)['success'].should eq true
27
27
  end
28
28
 
29
- it "should return pagination if 'pagination' is true" do
30
- Pin::Charges.all(3,true)[:pagination]["current"] == 3
29
+ it 'should return pagination if "pagination" is true' do
30
+ Pin::Charges.all(3, true)[:pagination]['current'] == 3
31
31
  end
32
32
 
33
- it "should list charges on a page given a page" do
33
+ it 'should list charges on a page given a page' do
34
34
  Pin::Charges.all(1).should_not == []
35
35
  end
36
36
 
37
- it "should create a pre-auth (capture a charge)" do
38
- options = {email: "dNitza@gmail.com", description: "A new captured charge from testing Pin gem", amount: "400", currency: "AUD", ip_address: "127.0.0.1", customer_token: "cus_8ImkZdEZ6BXUA6NcJDZg_g", capture: false }
39
- Pin::Charges.create(options)["captured"].should eq false
37
+ it 'should create a pre-auth (capture a charge)' do
38
+ options = { email: 'dNitza@gmail.com', description: 'A new captured charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_8ImkZdEZ6BXUA6NcJDZg_g', capture: false }
39
+ Pin::Charges.create(options)['captured'].should eq false
40
40
  end
41
41
 
42
- it "should capture a charge" do
43
- options = {email: "dNitza@gmail.com", description: "A new captured charge from testing Pin gem", amount: "400", currency: "AUD", ip_address: "127.0.0.1", customer_token: "cus_8ImkZdEZ6BXUA6NcJDZg_g", capture: false }
44
- token = Pin::Charges.create(options)["token"]
45
- Pin::Charges.capture(token)["success"].should eq true
42
+ it 'should capture a charge' do
43
+ options = { email: 'dNitza@gmail.com', description: 'A new captured charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_8ImkZdEZ6BXUA6NcJDZg_g', capture: false }
44
+ token = Pin::Charges.create(options)['token']
45
+ Pin::Charges.capture(token)['success'].should eq true
46
46
  end
47
- end
47
+ end
@@ -1,63 +1,63 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Customer", :vcr, class: Pin::Customer do
3
+ describe 'Customer', :vcr, class: Pin::Customer do
4
4
  before(:each) do
5
- Pin::Base.new(ENV["PIN_SECRET"], :test)
5
+ Pin::Base.new(ENV['PIN_SECRET'], :test)
6
6
  end
7
7
 
8
- it "should list customers" do
8
+ it 'should list customers' do
9
9
  Pin::Customer.all.should_not == []
10
10
  end
11
11
 
12
- it "should go to a specific page when page paramater is passed" do
13
- request = Pin::Customer.all(20,true)
14
- request[:pagination]["current"].should == 20
12
+ it 'should go to a specific page when page paramater is passed' do
13
+ request = Pin::Customer.all(20, true)
14
+ request[:pagination]['current'].should == 20
15
15
  end
16
16
 
17
- it "should list customers on a page given a page" do
18
- request = Pin::Customer.all(1,true)
17
+ it 'should list customers on a page given a page' do
18
+ request = Pin::Customer.all(1, true)
19
19
  request[:response].should_not == []
20
20
  end
21
21
 
22
- it "should return pagination if true is passed for pagination" do
23
- request = Pin::Customer.all(1,true)
24
- request[:pagination].keys.include?(["current", "previous", "next", "per_page", "pages", "count"])
22
+ it 'should return pagination if true is passed for pagination' do
23
+ request = Pin::Customer.all(1, true)
24
+ request[:pagination].keys.include?(%W('current previous next per_page pages count))
25
25
  end
26
26
 
27
- it "should not list customers on a page given a page if there are no customers" do
28
- request = Pin::Customer.all(25,true)
27
+ it 'should not list customers on a page given a page if there are no customers' do
28
+ request = Pin::Customer.all(25, true)
29
29
  request[:response].should == []
30
30
  end
31
31
 
32
- it "should show a customer given a token" do
33
- Pin::Customer.find('cus_8ImkZdEZ6BXUA6NcJDZg_g')['token'].should == "cus_8ImkZdEZ6BXUA6NcJDZg_g"
32
+ it 'should show a customer given a token' do
33
+ Pin::Customer.find('cus_8ImkZdEZ6BXUA6NcJDZg_g')['token'].should == 'cus_8ImkZdEZ6BXUA6NcJDZg_g'
34
34
  end
35
35
 
36
- it "should list charges to a customer given a token" do
36
+ it 'should list charges to a customer given a token' do
37
37
  Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g')[0]['token'].should match(/^[a-z]{2}[_]/)
38
38
  end
39
39
 
40
- it "should show pagination on a page given a token and a page" do
41
- Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g',5,true)[:pagination]["current"] == 5
40
+ it 'should show pagination on a page given a token and a page' do
41
+ Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g', 5, true)[:pagination]['current'] == 5
42
42
  end
43
43
 
44
- it "should list charges to a customer on a page given a token and a page" do
45
- Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g',1,true)[:response][0]['token'].should match(/^[a-z]{2}[_]/)
44
+ it 'should list charges to a customer on a page given a token and a page' do
45
+ Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g', 1, true)[:response][0]['token'].should match(/^[a-z]{2}[_]/)
46
46
  end
47
47
 
48
- it "should create a customer given an email and card details" do
49
- Pin::Customer.create('dNitza@gmail.com', {number: '5520000000000000', expiry_month: "12", expiry_year: "2014", cvc: "123", name: 'Roland Robot', address_line1: '123 fake street', address_city: 'Melbourne', address_postcode: '1234', address_state: 'Vic', address_country: 'Australia'})["token"].should match(/^[a-z]{3}[_]/)
48
+ it 'should create a customer given an email and card details' do
49
+ Pin::Customer.create('dNitza@gmail.com', number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '123 fake street', address_city: 'Melbourne', address_postcode: '1234', address_state: 'Vic', address_country: 'Australia')['token'].should match(/^[a-z]{3}[_]/)
50
50
  end
51
51
 
52
- it "should update a customer given a token and details to update" do
53
- options = {email: "dNitza@gmail.com", card: {number: "5520000000000000", address_line1: "12345 Fake Street", expiry_month: "05", expiry_year: "2014", cvc: "123", name: "Daniel Nitsikopoulos", address_city: "Melbourne", address_postcode: "1234", address_state: "VIC", address_country: "Australia"}}
54
- Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options)['card']['address_line1'].should == "12345 Fake Street"
52
+ it 'should update a customer given a token and details to update' do
53
+ options = { email: 'dNitza@gmail.com', card: { number: '5520000000000000', address_line1: '12345 Fake Street', expiry_month: '05', expiry_year: '2014', cvc: '123', name: 'Daniel Nitsikopoulos', address_city: 'Melbourne', address_postcode: '1234', address_state: 'VIC', address_country: 'Australia' } }
54
+ Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options)['card']['address_line1'].should == '12345 Fake Street'
55
55
  end
56
56
 
57
- it "should create a customer given a card token customer email" do
58
- options = {number: "5520000000000000", expiry_month: "12", expiry_year: "2018", cvc: "123", name: "Roland TestRobot", address_line1: "123 Fake Road", address_line2: "", address_city: "Melbourne", address_postcode: "1223", address_state: "Vic", address_country: "AU"}
57
+ it 'should create a customer given a card token customer email' do
58
+ options = { number: '5520000000000000', expiry_month: '12', expiry_year: '2018', cvc: '123', name: 'Roland TestRobot', address_line1: '123 Fake Road', address_line2: '', address_city: 'Melbourne', address_postcode: '1223', address_state: 'Vic', address_country: 'AU' }
59
59
  @card = Pin::Card.create(options)
60
60
  Pin::Customer.create('nitza98@hotmail.com', @card['token'])['token'].should match(/^[a-z]{3}[_]/)
61
61
  end
62
62
 
63
- end
63
+ end
data/spec/errors_spec.rb CHANGED
@@ -1,82 +1,81 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Errors", :vcr, class: Pin::PinError do
3
+ describe 'Errors', :vcr, class: Pin::PinError do
4
4
  before(:each) do
5
- Pin::Base.new(ENV["PIN_SECRET"], :test)
5
+ Pin::Base.new(ENV['PIN_SECRET'], :test)
6
6
  end
7
7
 
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.")
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.')
10
10
  end
11
11
 
12
- it "should raise a 422 error when trying to update missing a param" do
13
- options = {email: "dNitza@gmail.com", card: {address_line1: "12345 Fake Street", expiry_month: "05", expiry_year: "2014", cvc: "123", address_city: "Melbourne", address_postcode: "1234", address_state: "VIC", address_country: "Australia"}}
14
- expect{Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options)}.to raise_error(Pin::InvalidResource, "invalid_resource: One or more parameters were missing or invalid")
12
+ it 'should raise a 422 error when trying to update missing a param' do
13
+ options = { email: 'dNitza@gmail.com', card: { address_line1: '12345 Fake Street', expiry_month: '05', expiry_year: '2014', cvc: '123', address_city: 'Melbourne', address_postcode: '1234', address_state: 'VIC', address_country: 'Australia' } }
14
+ expect { Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options) }.to raise_error(Pin::InvalidResource, 'invalid_resource: One or more parameters were missing or invalid')
15
15
  end
16
16
 
17
- it "should raise a 422 error when trying to make a payment with an expired card" do
18
- options = {email: "dNitza@gmail.com", description: "A new charge from testing Pin gem", amount: "400", currency: "AUD", ip_address: "127.0.0.1", card: {
19
- number: "5520000000000000",
20
- expiry_month: "05",
21
- expiry_year: "2012",
22
- cvc: "123",
23
- name: "Roland Robot",
24
- address_line1: "42 Sevenoaks St",
25
- address_city: "Lathlain",
26
- address_postcode: "6454",
27
- address_state: "WA",
28
- address_country: "Australia",
29
- }}
30
- expect{Pin::Charges.create(options)}.to raise_error(Pin::InvalidResource, "card_expiry_month_invalid: Card expiry month is expiredcard_expiry_year_invalid: Card expiry year is expired")
17
+ it 'should raise a 422 error when trying to make a payment with an expired card' do
18
+ options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', card: {
19
+ number: '5520000000000000',
20
+ expiry_month: '05',
21
+ expiry_year: '2012',
22
+ cvc: '123',
23
+ name: 'Roland Robot',
24
+ address_line1: '42 Sevenoaks St',
25
+ address_city: 'Lathlain',
26
+ address_postcode: '6454',
27
+ address_state: 'WA',
28
+ address_country: 'Australia'
29
+ } }
30
+ expect { Pin::Charges.create(options) }.to raise_error(Pin::InvalidResource, 'card_expiry_month_invalid: Card expiry month is expiredcard_expiry_year_invalid: Card expiry year is expired')
31
31
  end
32
32
 
33
- it "should raise a 400 error when trying to make a payment and a valid card gets declined" do
34
- options = {email: "dNitza@gmail.com", description: "A new charge from testing Pin gem", amount: "400", currency: "AUD", ip_address: "127.0.0.1", card: {
35
- number: "5560000000000001",
36
- expiry_month: "05",
37
- expiry_year: "2018",
38
- cvc: "123",
39
- name: "Roland Robot",
40
- address_line1: "42 Sevenoaks St",
41
- address_city: "Lathlain",
42
- address_postcode: "6454",
43
- address_state: "WA",
44
- address_country: "Australia",
45
- }}
46
- expect{Pin::Charges.create(options)}.to raise_error(Pin::ChargeError)
33
+ it 'should raise a 400 error when trying to make a payment and a valid card gets declined' do
34
+ options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', card: {
35
+ number: '5560000000000001',
36
+ expiry_month: '05',
37
+ expiry_year: '2018',
38
+ cvc: '123',
39
+ name: 'Roland Robot',
40
+ address_line1: '42 Sevenoaks St',
41
+ address_city: 'Lathlain',
42
+ address_postcode: '6454',
43
+ address_state: 'WA',
44
+ address_country: 'Australia'
45
+ } }
46
+ expect { Pin::Charges.create(options) }.to raise_error(Pin::ChargeError)
47
47
  end
48
48
 
49
- it "should raise a 422 error when trying to make a payment with an invalid card" do
50
- options = {email: "dNitza@gmail.com", description: "A new charge from testing Pin gem", amount: "400", currency: "AUD", ip_address: "127.0.0.1", card: {
51
- number: "5520000000000099",
52
- expiry_month: "05",
53
- expiry_year: "2014",
54
- cvc: "123",
55
- name: "Roland Robot",
56
- address_line1: "42 Sevenoaks St",
57
- address_city: "Lathlain",
58
- address_postcode: "6454",
59
- address_state: "WA",
60
- address_country: "Australia",
61
- }}
62
- expect{Pin::Charges.create(options)}.to raise_error(Pin::InvalidResource, "card_number_invalid: Card number is not a valid Visa or Mastercard number")
49
+ it 'should raise a 422 error when trying to make a payment with an invalid card' do
50
+ options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', card: {
51
+ number: '5520000000000099',
52
+ expiry_month: '05',
53
+ expiry_year: '2014',
54
+ cvc: '123',
55
+ name: 'Roland Robot',
56
+ address_line1: '42 Sevenoaks St',
57
+ address_city: 'Lathlain',
58
+ address_postcode: '6454',
59
+ address_state: 'WA',
60
+ address_country: 'Australia'
61
+ } }
62
+ expect { Pin::Charges.create(options) }.to raise_error(Pin::InvalidResource, 'card_number_invalid: Card number is not a valid Visa or Mastercard number')
63
63
  end
64
64
 
65
- 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.")
65
+ 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.')
67
67
  end
68
68
 
69
-
70
- it "should raise a 422 error if no 2nd argument is given" do
71
- 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_8ImkZdEZ6BXUA6NcJDZg_g" }
69
+ it 'should raise a 422 error if no 2nd argument is given' do
70
+ 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_8ImkZdEZ6BXUA6NcJDZg_g' }
72
71
  @charge = Pin::Charges.create(options)
73
- expect{Pin::Refund.create(@charge['token'])}.to raise_error(Pin::InvalidResource, "invalid_resource: One or more parameters were missing or invalid. Amount: can't be blank")
72
+ expect { Pin::Refund.create(@charge['token']) }.to raise_error(Pin::InvalidResource, 'invalid_resource: One or more parameters were missing or invalid. Amount: can\'t be blank')
74
73
  end
75
74
 
76
- xit "should raise a 422 error if a value of < 100 is given" do
77
- 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_8ImkZdEZ6BXUA6NcJDZg_g" }
75
+ xit 'should raise a 422 error if a value of < 100 is given' do
76
+ 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_8ImkZdEZ6BXUA6NcJDZg_g' }
78
77
  @charge = Pin::Charges.create(options)
79
- expect{Pin::Refund.create(@charge['token'], 90)}.to raise_error(Pin::InvalidResource, "One or more parameters were missing or invalid")
78
+ expect { Pin::Refund.create(@charge['token'], 90) }.to raise_error(Pin::InvalidResource, 'One or more parameters were missing or invalid')
80
79
  end
81
80
 
82
- end
81
+ end
data/spec/refund_spec.rb CHANGED
@@ -1,27 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
- describe "Refund", :vcr, class: Pin::Refund do
3
+ describe 'Refund', :vcr, class: Pin::Refund do
5
4
  before(:each) do
6
- Pin::Base.new(ENV["PIN_SECRET"], :test)
5
+ Pin::Base.new(ENV['PIN_SECRET'], :test)
7
6
  end
8
7
 
9
- it "should list all refunds made to a charge given a token" do
10
- Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ')[0]['token'].should == "rf_O4lHrNzwXYmMmTbBq0ZLPw"
8
+ it 'should list all refunds made to a charge given a token' do
9
+ Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ')[0]['token'].should == 'rf_O4lHrNzwXYmMmTbBq0ZLPw'
11
10
  end
12
11
 
13
- it "should return nothing if looking for a charge without a refund" do
12
+ it 'should return nothing if looking for a charge without a refund' do
14
13
  Pin::Refund.find('ch_rqPIWDK71YU46M4MAQHQKg').should == []
15
14
  end
16
15
 
17
- it "should return a page of refunds given a page and token" do
18
- Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ',1,true)[:response].should_not == []
16
+ it 'should return a page of refunds given a page and token' do
17
+ Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ', 1, true)[:response].should_not == []
19
18
  end
20
19
 
21
- it "should create a refund for a given amount and charge" do
22
- 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_8ImkZdEZ6BXUA6NcJDZg_g" }
20
+ it 'should create a refund for a given amount and charge' do
21
+ 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_8ImkZdEZ6BXUA6NcJDZg_g' }
23
22
  @charge = Pin::Charges.create(options)
24
- Pin::Refund.create(@charge['token'], "400")['amount'].should == 400
23
+ Pin::Refund.create(@charge['token'], '400')['amount'].should == 400
25
24
  end
26
25
 
27
- end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,11 +7,11 @@ require 'webmock/rspec'
7
7
  require 'capybara/rspec'
8
8
  require 'vcr'
9
9
 
10
- require "net/https"
11
- require "uri"
10
+ require 'net/https'
11
+ require 'uri'
12
12
 
13
13
  ## Uncomment to load in a .yml with your pin key
14
- # ENV.update YAML.load(File.read(File.expand_path("../test_data.yml", __FILE__)))
14
+ # ENV.update YAML.load(File.read(File.expand_path('../test_data.yml', __FILE__)))
15
15
 
16
16
  # require pin_up gem
17
17
  require 'pin_up'
@@ -20,15 +20,17 @@ RSpec.configure do |config|
20
20
  config.include WebMock::API
21
21
  config.treat_symbols_as_metadata_keys_with_true_values = true
22
22
  config.around(:each, :vcr) do |example|
23
- name = example.metadata[:full_description].split(/\s+/, 2).join("/").gsub(/[^\w\/]+/, "_")
24
- # options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
23
+ name = example
24
+ .metadata[:full_description]
25
+ .split(/\s+/, 2).join('/')
26
+ .gsub(/[^\w\/]+/, '_')
25
27
  VCR.use_cassette(name) { example.call }
26
28
  end
27
29
  end
28
30
 
29
31
  VCR.configure do |c|
30
- c.cassette_library_dir = "spec/vcr"
32
+ c.cassette_library_dir = 'spec/vcr'
31
33
  c.hook_into :webmock
32
34
  c.allow_http_connections_when_no_cassette = true
33
- c.filter_sensitive_data('<key>') {ENV["PIN_SECRET"]}
35
+ c.filter_sensitive_data('<key>') { ENV['PIN_SECRET'] }
34
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pin_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Nitsikopoulos
@@ -182,6 +182,8 @@ files:
182
182
  - ".idea/scopes/scope_settings.xml"
183
183
  - ".idea/vcs.xml"
184
184
  - ".idea/workspace.xml"
185
+ - ".rubocop.yml"
186
+ - ".ruby-version"
185
187
  - ".travis.yml"
186
188
  - Gemfile
187
189
  - Gemfile.lock