Class: BeyondApi::Customers
- Includes:
- Utils
- Defined in:
- lib/beyond_api/resources/customers.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#all(params = {}) ⇒ OpenStruct
A
GET
request is used to list all customers of the shop in a paged way. -
#create(body) ⇒ OpenStruct
A
POST
request is used to create a customer. -
#delete(customer_id) ⇒ Object
A
DELETE
request is used to delete a customer. -
#find(customer_id) ⇒ OpenStruct
A
GET
request is used to retrieve the details of a customer. -
#update(customer_id, body) ⇒ OpenStruct
A
PUT
request is used to update a customer.
Methods included from Utils
#file_content_type, #handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct
Methods inherited from Base
Constructor Details
This class inherits a constructor from BeyondApi::Base
Instance Method Details
#all(params = {}) ⇒ OpenStruct
A GET
request is used to list all customers of the shop in a paged way. Each item in the response represents a summary of the customer data.
$ curl 'https://api-shop.beyondshop.cloud/api/customers' -i -X GET \
-H 'Authorization: Bearer <Access token>'
26 27 28 |
# File 'lib/beyond_api/resources/customers.rb', line 26 def all(params = {}) handle_all_request("/customers", :customers, params) end |
#create(body) ⇒ OpenStruct
A POST
request is used to create a customer.
$ curl 'https://api-shop.beyondshop.cloud/api/customers' -i -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"defaultPaymentMethodId" : "69923864-74a7-4ea9-92c7-0d17181b39f4",
"defaultShippingMethodId" : "a5976ec2-d99a-4d16-bd2b-1fa5c48d68aa",
"shippingAddress" : {
"salutation" : "Mrs",
"gender" : "FEMALE",
"company" : "Astrid Alster GmbH",
"title" : "",
"firstName" : "Astrid",
"middleName" : "Agnes",
"lastName" : "Alster",
"street" : "Alsterwasserweg",
"houseNumber" : "2",
"street2" : "Erdgeschoss",
"addressExtension" : "Hinterhof",
"postalCode" : "20999",
"dependentLocality" : "Seevetal",
"city" : "Alsterwasser",
"country" : "DE",
"state" : "Hamburg",
"email" : "[email protected]",
"phone" : "(800) 555-0102",
"mobile" : "(800) 555-0103",
"doorCode" : "456",
"_id" : null
},
"email" : "[email protected]",
"initialPassword" : "MyVeryStrongPassword",
"billingAddress" : {
"salutation" : "Mrs",
"gender" : "FEMALE",
"company" : "Astrid Alster GmbH",
"title" : "",
"firstName" : "Astrid",
"middleName" : "Agnes",
"lastName" : "Alster",
"street" : "Alsterwasserweg",
"houseNumber" : "2",
"street2" : "Erdgeschoss",
"addressExtension" : "Hinterhof",
"postalCode" : "20999",
"dependentLocality" : "Seevetal",
"city" : "Alsterwasser",
"country" : "DE",
"state" : "Hamburg",
"email" : "[email protected]",
"phone" : "(800) 555-0102",
"mobile" : "(800) 555-0103",
"vatId" : "DE123456789",
"taxNumber" : "HRE 987654/32123/864516",
"birthDate" : "1985-05-11",
"_id" : "b61ca0e0-411f-485e-83f3-035d717095da"
}
}'
156 157 158 159 160 |
# File 'lib/beyond_api/resources/customers.rb', line 156 def create(body) response, status = BeyondApi::Request.post(@session, "/customers", body) handle_response(response, status) end |
#delete(customer_id) ⇒ Object
A DELETE
request is used to delete a customer.
$ curl 'https://api-shop.beyondshop.cloud/api/customers/9e2a61d9-a1ac-4771-bd02-32bf50386392' -i -X DELETE \
-H 'Authorization: Bearer <Access token>'
177 178 179 180 181 |
# File 'lib/beyond_api/resources/customers.rb', line 177 def delete(customer_id) response, status = BeyondApi::Request.delete(@session, "/customers/#{customer_id}") handle_response(response, status, respond_with_true: true) end |
#find(customer_id) ⇒ OpenStruct
A GET
request is used to retrieve the details of a customer.
$ curl 'https://api-shop.beyondshop.cloud/api/customers/d6a8132e-29b3-4258-b8c0-aee34df42aa1' -i -X GET \
-H 'Authorization: Bearer <Access token>'
198 199 200 201 202 |
# File 'lib/beyond_api/resources/customers.rb', line 198 def find(customer_id) response, status = BeyondApi::Request.get(@session, "/customers/#{customer_id}") handle_response(response, status) end |
#update(customer_id, body) ⇒ OpenStruct
A PUT
request is used to update a customer.
$ curl 'https://api-shop.beyondshop.cloud/api/customers/34c5566b-e82a-486d-9a7d-3c3aafef6901' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"defaultPaymentMethodId" : "d94790cd-ec27-4461-85a9-457fffcc0271",
"defaultShippingMethodId" : "976e7d66-0eb2-4ca3-8b44-5e6d0aeb9e63",
"shippingAddress" : {
"salutation" : "Mrs",
"gender" : "FEMALE",
"company" : "Astrid Alster GmbH",
"title" : "",
"firstName" : "Astrid",
"middleName" : "Agnes",
"lastName" : "Alster",
"street" : "Alsterwasserweg",
"houseNumber" : "2",
"street2" : "Erdgeschoss",
"addressExtension" : "Hinterhof",
"postalCode" : "20999",
"dependentLocality" : "Seevetal",
"city" : "Alsterwasser",
"country" : "DE",
"state" : "Hamburg",
"email" : "[email protected]",
"phone" : "(800) 555-0102",
"mobile" : "(800) 555-0103",
"doorCode" : "456",
"_id" : "112d46ff-fc72-4be8-9e48-588b4f5c7829"
},
"billingAddress" : {
"salutation" : "Mrs",
"gender" : "FEMALE",
"company" : "Astrid Alster GmbH",
"title" : "",
"firstName" : "Astrid",
"middleName" : "Agnes",
"lastName" : "Alster",
"street" : "Alsterwasserweg",
"houseNumber" : "2",
"street2" : "Erdgeschoss",
"addressExtension" : "Hinterhof",
"postalCode" : "20999",
"dependentLocality" : "Seevetal",
"city" : "Alsterwasser",
"country" : "DE",
"state" : "Hamburg",
"email" : "[email protected]",
"phone" : "(800) 555-0102",
"mobile" : "(800) 555-0103",
"vatId" : "DE123456789",
"taxNumber" : "HRE 987654/32123/864516",
"birthDate" : "1985-05-11",
"_id" : "85de80fc-8467-46ca-b20c-55f5d4d1eaec"
}
}'
326 327 328 329 330 |
# File 'lib/beyond_api/resources/customers.rb', line 326 def update(customer_id, body) response, status = BeyondApi::Request.put(@session, "/customers/#{customer_id}", body) handle_response(response, status) end |