Module: TpagaService::CustomerApi

Extended by:
CustomerApi
Included in:
CustomerApi
Defined in:
lib/tpaga_service/api/customer_api.rb

Instance Method Summary collapse

Instance Method Details

#create_customer(data) ⇒ Object

Parameters:

*data Hash - { firstName: ”, lastName: ”, email: ”, phone: ” }

Return:

Hash - "firstName"=>"Sta. Elisa Melgar Arteaga", "lastName"=>"Sta. Elisa Melgar Arteaga", "gender"=>nil, "email"=>"[email protected]", "phone"=>"9521559", "legalIdNumber"=>nil, "merchantCustomerId"=>nil



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tpaga_service/api/customer_api.rb', line 9

def create_customer(data)
  host = Swagger.configuration.host
  api_key = Swagger.configuration.private_api_key

  conn = Faraday.new
  resp = conn.post do |req|
    req.url "https://#{host}/api/customer"
    req.headers['Content-Type'] = 'application/json'
    req.headers['Authorization'] = 'Basic ' + ["#{api_key}:"].pack('m').delete("\r\n")
    req.body = data.to_json
  end
  body = JSON.parse(resp.body)
  Swagger::Response.new(resp.status, body)
  return body
end

#delete_customer_by_id(customer_id) ⇒ Object

Parameters:

*customer_id : String



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tpaga_service/api/customer_api.rb', line 65

def delete_customer_by_id(customer_id)
  host = Swagger.configuration.host
  api_key = Swagger.configuration.private_api_key

  conn = Faraday.new
  resp = conn.delete do |req|
    req.url "https://#{host}/api/customer/#{customer_id}"
    req.headers['Content-Type'] = 'application/json'
    req.headers['Authorization'] = 'Basic ' + ["#{api_key}:"].pack('m').delete("\r\n")
  end
  body = JSON.parse(resp.body)
  Swagger::Response.new(resp.status, body)
  return body
end

#get_customer_by_id(customer_id) ⇒ Object

Parameters:

*customer_id : String

Return:

Hash - {

"id": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"gender": "M",
"phone": "string",
"legalIdNumber": "string",
"merchantCustomerId": "string",
"address": {
  "addressLine1": "string",
  "addressLine2": "string",
  "postalCode": "string",
  "city": {
    "name": "Bogotá",
    "state": "DC",
    "country": "CO"
  }
}

}



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tpaga_service/api/customer_api.rb', line 48

def get_customer_by_id(customer_id)
  host = Swagger.configuration.host
  api_key = Swagger.configuration.private_api_key

  conn = Faraday.new
  resp = conn.get do |req|
    req.url "https://#{host}/api/customer/#{customer_id}"
    req.headers['Content-Type'] = 'application/json'
    req.headers['Authorization'] = 'Basic ' + ["#{api_key}:"].pack('m').delete("\r\n")
  end
  body = JSON.parse(resp.body)
  Swagger::Response.new(resp.status, body)
  return body
end