Class: Io::Flow::V0::Clients::CustomerAddressBookContacts

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CustomerAddressBookContacts

Returns a new instance of CustomerAddressBookContacts.



5501
5502
5503
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5501

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#delete_by_id(organization, number, id) ⇒ Object

Delete the contact with this id.



5551
5552
5553
5554
5555
5556
5557
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5551

def delete_by_id(organization, number, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}/addresses/book/contacts/#{CGI.escape(id)}").delete
  nil
end

#get(organization, number, incoming = {}) ⇒ Object

Search contacts. Always paginated.



5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5506

def get(organization, number, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, 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) }),
    :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/#{CGI.escape(number)}/addresses/book/contacts").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::CustomerAddressBookContact.new(x) }
end

#get_by_id(organization, number, id) ⇒ Object

Returns information about a specific contact.



5532
5533
5534
5535
5536
5537
5538
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5532

def get_by_id(organization, number, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}/addresses/book/contacts/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::CustomerAddressBookContact.new(r)
end

#post(organization, number, customer_address_book_contact_form) ⇒ Object

Create a contact.



5523
5524
5525
5526
5527
5528
5529
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5523

def post(organization, number, customer_address_book_contact_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = customer_address_book_contact_form; x.is_a?(::Io::Flow::V0::Models::CustomerAddressBookContactForm) ? x : ::Io::Flow::V0::Models::CustomerAddressBookContactForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}/addresses/book/contacts").with_json(customer_address_book_contact_form.to_json).post
  ::Io::Flow::V0::Models::CustomerAddressBookContact.new(r)
end

#put_by_id(organization, number, id, customer_address_book_contact_form) ⇒ Object

Update or create a contact with the specified id.



5541
5542
5543
5544
5545
5546
5547
5548
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5541

def put_by_id(organization, number, id, customer_address_book_contact_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = customer_address_book_contact_form; x.is_a?(::Io::Flow::V0::Models::CustomerAddressBookContactForm) ? x : ::Io::Flow::V0::Models::CustomerAddressBookContactForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/customers/#{CGI.escape(number)}/addresses/book/contacts/#{CGI.escape(id)}").with_json(customer_address_book_contact_form.to_json).put
  ::Io::Flow::V0::Models::CustomerAddressBookContact.new(r)
end