Class: Moip2::CustomerApi

Inherits:
Object
  • Object
show all
Defined in:
lib/moip2/customer_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CustomerApi

Returns a new instance of CustomerApi.



5
6
7
# File 'lib/moip2/customer_api.rb', line 5

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/moip2/customer_api.rb', line 3

def client
  @client
end

Instance Method Details

#add_credit_card(customer_external_id, credit_card) ⇒ Object



25
26
27
28
29
30
# File 'lib/moip2/customer_api.rb', line 25

def add_credit_card(customer_external_id, credit_card)
  Resource::CreditCard.new client, client.post(
    "#{base_path}/#{customer_external_id}/fundinginstruments",
    credit_card,
  )
end

#base_pathObject



9
10
11
# File 'lib/moip2/customer_api.rb', line 9

def base_path
  "/v2/customers"
end

#base_path_credit_cardObject



13
14
15
# File 'lib/moip2/customer_api.rb', line 13

def base_path_credit_card
  "/v2/fundinginstruments"
end

#create(customer) ⇒ Object



21
22
23
# File 'lib/moip2/customer_api.rb', line 21

def create(customer)
  Resource::Customer.new client, client.post(base_path, customer)
end

#delete_credit_card!(credit_card_id) ⇒ Object



32
33
34
35
36
# File 'lib/moip2/customer_api.rb', line 32

def delete_credit_card!(credit_card_id)
  resp = client.delete("#{base_path_credit_card}/#{credit_card_id}")

  resp.success?
end

#show(customer_external_id) ⇒ Object



17
18
19
# File 'lib/moip2/customer_api.rb', line 17

def show(customer_external_id)
  Resource::Customer.new client, client.get("#{base_path}/#{customer_external_id}")
end