Module: BookingSync::API::Client::Contacts

Included in:
BookingSync::API::Client
Defined in:
lib/bookingsync/api/client/contacts.rb

Instance Method Summary collapse

Instance Method Details

#contact(contact, options = {}) ⇒ BookingSync::API::Resource

Get a single contact

Parameters:

  • contact (BookingSync::API::Resource|Integer)

    Contact or ID of the contact.

  • options (Hash) (defaults to: {})

    A customizable set of query options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

Returns:



28
29
30
# File 'lib/bookingsync/api/client/contacts.rb', line 28

def contact(contact, options = {})
  get("contacts/#{contact}", options).pop
end

#contacts(options = {}, &block) ⇒ Array<BookingSync::API::Resource>

List contacts

Returns contacts for the account user is authenticated with.

Examples:

Get the list of contacts for the current account

contacts = @api.contacts
contacts.first.fullname # => "John Smith"

Get the list of contacts only with fullname and phone for smaller response

@api.contacts(fields: [:fullname, :phone])

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

Returns:

See Also:



17
18
19
# File 'lib/bookingsync/api/client/contacts.rb', line 17

def contacts(options = {}, &block)
  paginate :contacts, options, &block
end

#create_contact(options = {}) ⇒ BookingSync::API::Resource

Create a new contact

Parameters:

  • options (Hash) (defaults to: {})

    Contact attributes

Returns:



36
37
38
# File 'lib/bookingsync/api/client/contacts.rb', line 36

def create_contact(options = {})
  post(:contacts, contacts: [options]).pop
end

#delete_contact(contact) ⇒ NilClass

Delete a contact

Parameters:

Returns:

  • (NilClass)

    Returns nil on success.



58
59
60
# File 'lib/bookingsync/api/client/contacts.rb', line 58

def delete_contact(contact)
  delete "contacts/#{contact}"
end

#edit_contact(contact, options = {}) ⇒ BookingSync::API::Resource

Edit a contact

Examples:

contact = @api.contacts.first
@api.edit_contact(contact, { fullname: "Gary Smith" })

Parameters:

  • contact (BookingSync::API::Resource|Integer)

    Contact or ID of the contact to be updated

  • options (Hash) (defaults to: {})

    Contact attributes to be updated

Returns:



49
50
51
# File 'lib/bookingsync/api/client/contacts.rb', line 49

def edit_contact(contact, options = {})
  put("contacts/#{contact}", contacts: [options]).pop
end