Skip to content

Commit

Permalink
Merge pull request #4 from matiasmansilla1989/master
Browse files Browse the repository at this point in the history
Include the Customer endpoint logic
  • Loading branch information
yazinsai committed Feb 19, 2015
2 parents 8db8da3 + 84afffe commit 1c1f3da
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
white (1.0.0)
white_payments (2.0)
httparty (~> 0.13)
json (~> 1.8.1)

Expand All @@ -28,4 +28,4 @@ DEPENDENCIES
minitest
rake
turn
white!
white_payments!
3 changes: 2 additions & 1 deletion lib/white.rb
@@ -1,4 +1,5 @@
require "httparty"
require "white/customer"
require "white/charge"
require "white/errors/white_error"
require "white/errors/authentication_error"
Expand Down Expand Up @@ -61,4 +62,4 @@ def self.get(url, query={})
class << self
attr_accessor :api_key
end
end
end
7 changes: 6 additions & 1 deletion lib/white/charge.rb
Expand Up @@ -5,8 +5,13 @@ def self.create(params={})
White.post(White.api_url('charges/'), params)
end

def self.get(id)
White.get(White.api_url('charges/' + id.to_s))
end

def self.all
White.get(White.api_url('charges/'))
end

end
end
end
17 changes: 17 additions & 0 deletions lib/white/customer.rb
@@ -0,0 +1,17 @@
module White
class Customer

def self.create(params={})
White.post(White.api_url('customers/'), params)
end

def self.get(id)
White.get(White.api_url('customers/' + id.to_s))
end

def self.all
White.get(White.api_url('customers/'))
end

end
end
4 changes: 3 additions & 1 deletion spec/lib/white/charge_spec.rb
Expand Up @@ -8,7 +8,9 @@
response = White::Charge.create(
:amount => 400,
:currency => "usd",
:email => "ahmed@example.com",
:card => {
:name => "Abdullah Ahmed",
:number => "4242424242424242",
:exp_month => 11,
:exp_year => 2016,
Expand All @@ -25,4 +27,4 @@
response.wont_be_empty
end

end
end
29 changes: 29 additions & 0 deletions spec/lib/white/customer_spec.rb
@@ -0,0 +1,29 @@
require_relative '../../spec_helper'
# require_relative '../../../lib/white/customer'

describe White::Customer do

it "must create a new customer" do
White.api_key = "test_sec_k_25dd497d7e657bb761ad6"

response = White::Customer.create(
:name => "Abdullah Ahmed",
:email => "abdullah@msn.com",
:card => {
:number => "4242424242424242",
:exp_month => 11,
:exp_year => 2016,
:cvc => 123
},
:description => "Signed up at the Trade Show in Dec 2014"
)

response['name'].must_equal "Abdullah Ahmed"
end

it "must list created customers" do
response = White::Customer.all()
response.wont_be_empty
end

end
4 changes: 3 additions & 1 deletion spec/lib/white/error/banking_error_spec.rb
Expand Up @@ -9,7 +9,9 @@
response = White::Charge.create(
:amount => 400,
:currency => "usd",
:email => "abdullah@msn.com",
:card => {
:name => "Abdullah Ahmed",
:number => "4000000000000002",
:exp_month => 11,
:exp_year => 2016,
Expand All @@ -23,4 +25,4 @@
end
end

end
end
2 changes: 1 addition & 1 deletion spec/lib/white/error/request_error_spec.rb
Expand Up @@ -126,4 +126,4 @@
e.http_status.must_equal 422
end
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -5,4 +5,4 @@

#dependencies
gem 'minitest'
require 'minitest/autorun'
require 'minitest/autorun'

0 comments on commit 1c1f3da

Please sign in to comment.