Class: Unleashed::CustomerResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Unleashed::CustomerResource
- Defined in:
- lib/unleashed/resources/customer_resource.rb
Overview
Resource for the Customers API The Customers resource allows Customers to be listed, viewed, created, and updated. An individual Customer’s details can be viewed, or updated by appending its identifier (a GUID formatted as XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) to the URI
Instance Method Summary collapse
-
#all(options = { Page: 1, PageSize: 200 }) ⇒ Array<Unleashed::Customer>
List all customers /Customers - also returns the first 200 customers because page number 1 is the default.
-
#create_or_update(attributes) ⇒ Unleashed::Customer
Create a new customer.
-
#find(guid) ⇒ Unleashed::Customer
Get a single customer /Customers/E6E8163F-6911-40e9-B740-90E5A0A3A996 - returns details of a particular customer.
-
#first ⇒ Unleashed::Customer
Get a first customer in all.
-
#last ⇒ Unleashed::Customer
Get a last customer in all.
- #model ⇒ Object
Methods inherited from BaseResource
#initialize, #method_missing, #respond_to?
Constructor Details
This class inherits a constructor from Unleashed::BaseResource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Unleashed::BaseResource
Instance Method Details
#all(options = { Page: 1, PageSize: 200 }) ⇒ Array<Unleashed::Customer>
List all customers /Customers - also returns the first 200 customers because page number 1 is the default.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/unleashed/resources/customer_resource.rb', line 33 def all( = { Page: 1, PageSize: 200 }) endpoint = 'Customers' params = .dup # Handle Page option endpoint << "/#{params[:Page]}" if params[:Page].present? response = JSON.parse(@client.get(endpoint, params).body) customers = response.key?('Items') ? response['Items'] : [] customers.map { |attributes| Unleashed::Customer.new(@client, attributes) } end |
#create_or_update(attributes) ⇒ Unleashed::Customer
Create a new customer
attributes = { Guid: “59f21e05-07fe-4d9d-b460-a09db4c3caa9”, Addresses: [ { AddressType: “Shipping”,
AddressName: "Example Address", StreetAddress: "Example Address",
StreetAddress2: "Example Address 2", Suburb: "Example Suburb", City: "Auckland",
Region: "Auckland", Country: "New Zealand", PostalCode: "1061", IsDefault: false,
DeliveryInstruction: "Have a good day" } ], TaxCode: "", TaxRate: nil,
CustomerCode: "UnleashedCustomer", CustomerName: "Unleashed Customer", GSTVATNumber: nil,
BankName: nil, BankBranch: nil, BankAccount: nil, Website: nil, PhoneNumber: nil, FaxNumber: nil,
MobileNumber: nil, DDINumber: nil, TollFreeNumber: nil, Email: nil, EmailCC: nil,
Currency: { CurrencyCode: "NZD", Description: "New Zealand, Dollars",
Guid: "6cb5d67a-1c96-4fa8-bf59-b23c2d69f22a" }, Notes: nil, Taxable: true, SalesPerson: nil,
DiscountRate: 0, PrintPackingSlipInsteadOfInvoice: false, PrintInvoice: false,
StopCredit: false, Obsolete: false, XeroSalesAccount: nil, XeroCostOfGoodsAccount: nil,
SellPriceTier: "", SellPriceTierReference: nil, CustomerType: "Cash",
PaymentTerm: "20th Month following", ContactFirstName: nil, ContactLastName: nil }
89 90 91 92 93 94 95 |
# File 'lib/unleashed/resources/customer_resource.rb', line 89 def create_or_update(attributes) id = attributes[:Guid].present? ? attributes[:Guid] : '' endpoint = 'Customers' endpoint << "/#{id}" if id.present? response = JSON.parse(@client.post(endpoint, attributes).body) Unleashed::Customer.new(@client, response) end |
#find(guid) ⇒ Unleashed::Customer
Get a single customer /Customers/E6E8163F-6911-40e9-B740-90E5A0A3A996 - returns details of a particular customer.
50 51 52 53 54 |
# File 'lib/unleashed/resources/customer_resource.rb', line 50 def find(guid) endpoint = "Customers/#{guid}" response = JSON.parse(@client.get(endpoint).body) Unleashed::Customer.new(@client, response) end |
#first ⇒ Unleashed::Customer
Get a first customer in all
59 60 61 |
# File 'lib/unleashed/resources/customer_resource.rb', line 59 def first all.first end |
#last ⇒ Unleashed::Customer
Get a last customer in all
66 67 68 |
# File 'lib/unleashed/resources/customer_resource.rb', line 66 def last all.last end |