Module: Pin::API::Customers

Included in:
Client
Defined in:
lib/pin/api/customers.rb

Instance Method Summary collapse

Instance Method Details

#create_customer(email, card) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pin/api/customers.rb', line 20

def create_customer(email, card)
  require_field email, :email

  params = {
      :email => email
  }

  params[card.is_a?(Hash) ? :card : :card_token] = card

  raw_response = api_call(:post, 'customers', params)

  pin_response(raw_response, Pin::Models::Customer.new(raw_response['response']))
end

#customer(token) ⇒ Object



8
9
10
11
12
# File 'lib/pin/api/customers.rb', line 8

def customer(token)
  raw_response = api_call(:get, "customers/#{token}")

  pin_response(raw_response, Pin::Models::Customer.new(raw_response['response']))
end

#customer_charges(token, page = 1) ⇒ Object



14
15
16
17
18
# File 'lib/pin/api/customers.rb', line 14

def customer_charges(token, page=1)
  raw_response = api_call(:get, "customers/#{token}/charges", {:page => page})

  pin_response(raw_response, raw_response['response'].map { |e| Pin::Models::Charge.new(e) })
end

#customers(page = 1) ⇒ Object



3
4
5
6
# File 'lib/pin/api/customers.rb', line 3

def customers(page=1)
  raw_response = api_call(:get, 'customers', {page: page})
  pin_response(raw_response, raw_response['response'].map { |e| Pin::Models::Customer.new(e) })
end

#update_customer(token, params) ⇒ Object



34
35
36
37
# File 'lib/pin/api/customers.rb', line 34

def update_customer(token, params)
  raw_response = api_call(:put, "customers/#{token}", params)
  pin_response(raw_response, Pin::Models::Customer.new(raw_response['response']))
end