Class: Io::Flow::V0::Clients::Customers

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Customers

Returns a new instance of Customers.



5551
5552
5553
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5551

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.



5598
5599
5600
5601
5602
5603
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5598

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.



5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5556

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.



5581
5582
5583
5584
5585
5586
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5581

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.



5573
5574
5575
5576
5577
5578
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5573

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

#put_by_number(organization, number, customer_put_form) ⇒ Object

Update or create a customer with the specified number.



5589
5590
5591
5592
5593
5594
5595
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5589

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