Class: Pin::Customer

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_up/customer.rb

Overview

This class models Pins Customers API

Class Method Summary collapse

Methods inherited from Base

#initialize, #key, #uri

Constructor Details

This class inherits a constructor from Pin::Base

Class Method Details

.all(page = nil, pagination = false) ⇒ Object

Lists all customers for your account args: page (Fixnum), pagination (Boolean) returns: a collection of customer objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pin.net.au/docs/api/customers#get-customers



15
16
17
# File 'lib/pin_up/customer.rb', line 15

def self.all(page=nil, pagination=false)
  build_collection_response(auth_get("customers?page=#{page}"), pagination)
end

.charges(token, page = nil, pagination = false) ⇒ Object

Get a list of charges for a customer args: token (String), page (Fixnum), pagination (Boolean) returns: a collection of charge objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pin.net.au/docs/api/customers#get-customers-charges



62
63
64
# File 'lib/pin_up/customer.rb', line 62

def self.charges(token, page=nil, pagination=false)
  build_collection_response(auth_get("customers/#{token}/charges?page=#{page}"), pagination)
end

.create(email, card) ⇒ Object

Create a customer given customer details and a card OR a card_token args: email(String), card (Hash) returns: a customer object pin.net.au/docs/api/customers#post-customers



24
25
26
27
28
29
30
31
32
# File 'lib/pin_up/customer.rb', line 24

def self.create(email, card)
  options = if card.respond_to?(:to_hash)
    {card: card.to_hash}
  else
    {card_token: card}
  end.merge(email: email)

  build_response(auth_post('customers', options))
end

.find(token) ⇒ Object

Find a customer for your account given a token args: token (String) returns: a customer object pin.net.au/docs/api/customers#get-customers



39
40
41
# File 'lib/pin_up/customer.rb', line 39

def self.find(token)
  build_response(auth_get("customers/#{token}"))
end

.update(token, options = {}) ⇒ Object

Update a customer for your account given a token and any of: email, card (hash),card_token args: token (String), options (Hash) returns: a customer object pin.net.au/docs/api/customers#put-customer NB: When providing a card (hash), you need to specify the full list of details.



49
50
51
# File 'lib/pin_up/customer.rb', line 49

def self.update(token, options = {})
  build_response(auth_put("customers/#{token}", options))
end