Module: Dnsimple::Client::Contacts

Included in:
ContactsService
Defined in:
lib/dnsimple/client/contacts.rb

Instance Method Summary collapse

Instance Method Details

#all_contacts(account_id, options = {}) ⇒ Dnsimple::CollectionResponse<Dnsimple::Struct::Contact> Also known as: all

Lists ALL the contacts in the account.

This method is similar to #contacts, but instead of returning the results of a specific page it iterates all the pages and returns the entire collection.

Please use this method carefully, as fetching the entire collection will increase the number of requests you send to the API server and you may eventually risk to hit the throttle limit.

Parameters:

  • account_id (Integer)

    the account ID

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

    the filtering and sorting options

Options Hash (options):

  • :page (Integer)

    current page (pagination)

  • :per_page (Integer)

    number of entries to return (pagination)

  • :sort (String)

    sorting policy

Returns:

Raises:

See Also:



54
55
56
# File 'lib/dnsimple/client/contacts.rb', line 54

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

#contact(account_id, contact_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Contact>

Gets a contact from the account.

Parameters:

  • account_id (Integer)

    the account ID

  • contact_id (#to_s)

    the contact ID

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

Returns:

Raises:

See Also:



88
89
90
91
92
# File 'lib/dnsimple/client/contacts.rb', line 88

def contact(, contact_id, options = {})
  response = client.get(Client.versioned("/%s/contacts/%s" % [, contact_id]), options)

  Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
end

#contacts(account_id, options = {}) ⇒ Dnsimple::PaginatedResponse<Dnsimple::Struct::Contact> Also known as: list, list_contacts

Lists the contacts in the account.

Examples:

List contacts in the first page

client.contacts.list(1010)

List contacts, provide a specific page

client.contacts.list(1010, page: 2)

List contacts, provide a sorting policy

client.contacts.list(1010, sort: "email:asc")

Parameters:

  • account_id (Integer)

    the account ID

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

    the filtering and sorting options

Options Hash (options):

  • :page (Integer)

    current page (pagination)

  • :per_page (Integer)

    number of entries to return (pagination)

  • :sort (String)

    sorting policy

Returns:

Raises:

See Also:



27
28
29
30
31
# File 'lib/dnsimple/client/contacts.rb', line 27

def contacts(, options = {})
  response = client.get(Client.versioned("/%s/contacts" % []), Options::ListOptions.new(options))

  Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Contact.new(r) })
end

#create_contact(account_id, attributes, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Contact> Also known as: create

Creates a contact in the account.

Parameters:

  • account_id (Integer)

    the account ID

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

Returns:

Raises:

See Also:



69
70
71
72
73
74
# File 'lib/dnsimple/client/contacts.rb', line 69

def create_contact(, attributes, options = {})
  Extra.validate_mandatory_attributes(attributes, [:first_name, :last_name, :address1, :city, :state_province, :postal_code, :country, :phone, :email])
  response = client.post(Client.versioned("/%s/contacts" % []), attributes, options)

  Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
end

#delete_contact(account_id, contact_id, options = {}) ⇒ Dnsimple::Response<nil> Also known as: delete

Deletes a contact from the account.

WARNING: this cannot be undone.

Parameters:

  • account_id (Integer)

    the account ID

  • contact_id (#to_s)

    the contact ID

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

Returns:

Raises:

See Also:



125
126
127
128
129
# File 'lib/dnsimple/client/contacts.rb', line 125

def delete_contact(, contact_id, options = {})
  response = client.delete(Client.versioned("/%s/contacts/%s" % [, contact_id]), nil, options)

  Dnsimple::Response.new(response, nil)
end

#update_contact(account_id, contact_id, attributes, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Contact> Also known as: update

Updates a contact in the account.

Parameters:

  • account_id (Integer)

    the account ID

  • contact_id (#to_s)

    the contact ID

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

Returns:

Raises:

See Also:



105
106
107
108
109
# File 'lib/dnsimple/client/contacts.rb', line 105

def update_contact(, contact_id, attributes, options = {})
  response = client.patch(Client.versioned("/%s/contacts/%s" % [, contact_id]), attributes, options)

  Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
end