Class: Io::Flow::V0::Clients::Customers
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Customers
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_number(organization, number) ⇒ Object
Delete the customer with this number.
-
#get(organization, incoming = {}) ⇒ Object
Search customers.
-
#get_by_number(organization, number) ⇒ Object
Returns information about a specific customer.
-
#initialize(client) ⇒ Customers
constructor
A new instance of Customers.
-
#post(organization, customer_form) ⇒ Object
Create a customer.
-
#post_client_and_tokens(organization, customer_client_token) ⇒ Object
Returns information about a specific customer given a client token.
-
#put_by_number(organization, number, customer_put_form) ⇒ Object
Update or create a customer with the specified number.
Constructor Details
#initialize(client) ⇒ Customers
Returns a new instance of Customers.
5647 5648 5649 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5647 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_number(organization, number) ⇒ Object
Delete the customer with this number.
5702 5703 5704 5705 5706 5707 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5702 def delete_by_number(organization, number) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}").delete nil end |
#get(organization, incoming = {}) ⇒ Object
Search customers. Always paginated.
5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5652 def get(organization, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }), :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }), :email => (x = opts.delete(:email); x.nil? ? nil : HttpClient::Preconditions.assert_class('email', x, Array).map { |v| HttpClient::Preconditions.assert_class('email', v, String) }), :phone => (x = opts.delete(:phone); x.nil? ? nil : HttpClient::Preconditions.assert_class('phone', x, Array).map { |v| HttpClient::Preconditions.assert_class('phone', v, String) }), :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer), :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/customers").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::Customer.new(x) } end |
#get_by_number(organization, number) ⇒ Object
Returns information about a specific customer.
5685 5686 5687 5688 5689 5690 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5685 def get_by_number(organization, number) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}").get ::Io::Flow::V0::Models::Customer.new(r) end |
#post(organization, customer_form) ⇒ Object
Create a customer.
5669 5670 5671 5672 5673 5674 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5669 def post(organization, customer_form) HttpClient::Preconditions.assert_class('organization', organization, String) (x = customer_form; x.is_a?(::Io::Flow::V0::Models::CustomerForm) ? x : ::Io::Flow::V0::Models::CustomerForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/customers").with_json(customer_form.to_json).post ::Io::Flow::V0::Models::Customer.new(r) end |
#post_client_and_tokens(organization, customer_client_token) ⇒ Object
Returns information about a specific customer given a client token.
5677 5678 5679 5680 5681 5682 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5677 def post_client_and_tokens(organization, customer_client_token) HttpClient::Preconditions.assert_class('organization', organization, String) (x = customer_client_token; x.is_a?(::Io::Flow::V0::Models::CustomerClientToken) ? x : ::Io::Flow::V0::Models::CustomerClientToken.new(x)) r = @client.request("/#{CGI.escape(organization)}/customers/client/tokens").with_json(customer_client_token.to_json).post ::Io::Flow::V0::Models::Customer.new(r) end |
#put_by_number(organization, number, customer_put_form) ⇒ Object
Update or create a customer with the specified number.
5693 5694 5695 5696 5697 5698 5699 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5693 def put_by_number(organization, number, customer_put_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) (x = customer_put_form; x.is_a?(::Io::Flow::V0::Models::CustomerPutForm) ? x : ::Io::Flow::V0::Models::CustomerPutForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}").with_json(customer_put_form.to_json).put ::Io::Flow::V0::Models::Customer.new(r) end |