Class: MercadoPago::API::Clients

Inherits:
Base
  • Object
show all
Defined in:
lib/mercadopago/api.rb,
lib/mercadopago/api/clients.rb

Instance Attribute Summary

Attributes inherited from Base

#access_token

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from MercadoPago::Base

Instance Method Details

#create_customer(payload) ⇒ Object

Argument must be an Hash request.create_customer(email: ‘[email protected]’)



16
17
18
19
20
21
22
23
24
# File 'lib/mercadopago/api/clients.rb', line 16

def create_customer(payload)
  response = connection.post(customer_endpoint, payload) do |req|
    req.params['access_token'] = access_token
  end
  response = process_response(response)
  OpenStruct.new(success?: true, body: response)
rescue Faraday::ClientError => exception
  OpenStruct.new(success?: false, message: 'Los datos no son correctos', details: exception.response[:body].to_s)
end

#remove_customer(customer_id) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/mercadopago/api/clients.rb', line 57

def remove_customer(customer_id)
  response = connection.delete(customer_id_endpoint(customer_id)) do |req|
    req.params['access_token'] = access_token
  end
  response = process_response(response)
  OpenStruct.new(success?: true, body: response)
rescue Faraday::ClientError => exception
  OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
end

#search_by(criteria = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/mercadopago/api/clients.rb', line 37

def search_by(criteria={})
  response = connection.get(customers_search_endpoint, criteria) do |req|
    req.params['access_token'] = access_token
  end
  response = process_response(response)
  OpenStruct.new(success?: true, body: response)
rescue Faraday::ClientError => exception
  OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
end

#search_customers_by_email(email) ⇒ Object

Argument must be an Hash



27
28
29
30
31
32
33
34
35
# File 'lib/mercadopago/api/clients.rb', line 27

def search_customers_by_email(email)
  response = connection.get(customers_search_endpoint, email: email) do |req|
    req.params['access_token'] = access_token
  end
  response = process_response(response)
  OpenStruct.new(success?: true, body: response)
rescue Faraday::ClientError => exception
  OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
end

#service_urlObject

Override parent class method Place here main base URL



10
11
12
# File 'lib/mercadopago/api/clients.rb', line 10

def service_url
  'https://api.mercadopago.com'
end

#update_customer(customer_id, payload) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/mercadopago/api/clients.rb', line 47

def update_customer(customer_id, payload)
  response = connection.put(customer_id_endpoint(customer_id), payload) do |req|
    req.params['access_token'] = access_token
  end
  response = process_response(response)
  OpenStruct.new(success?: true, body: response)
rescue Faraday::ClientError => exception
  OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
end