Module: Dnsimple::Client::Contacts

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

Instance Method Summary collapse

Instance Method Details

#contact(contact, options = {}) ⇒ Struct::Contact

Gets a contact from the account.

Parameters:

  • contact (Fixnum)

    The contact id.

Returns:

Raises:

See Also:



46
47
48
49
50
# File 'lib/dnsimple/client/contacts.rb', line 46

def contact(contact, options = {})
  response = client.get(Client.versioned("/contacts/#{contact}"), options)

  Struct::Contact.new(response["contact"])
end

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

Lists the contacts in the account.

Returns:

Raises:

See Also:



12
13
14
15
16
# File 'lib/dnsimple/client/contacts.rb', line 12

def contacts(options = {})
  response = client.get(Client.versioned("/contacts"), options)

  response.map { |r| Struct::Contact.new(r["contact"]) }
end

#create_contact(attributes = {}, options = {}) ⇒ Struct::Contact Also known as: create

Creates a contact in the account.

Parameters:

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

Returns:

Raises:

See Also:



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

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

  Struct::Contact.new(response["contact"])
end

#delete_contact(contact, options = {}) ⇒ void Also known as: delete

This method returns an undefined value.

Deletes a contact from the account.

WARNING: this cannot be undone.

Parameters:

  • contact (Fixnum)

    The contact id.

Raises:

See Also:



81
82
83
# File 'lib/dnsimple/client/contacts.rb', line 81

def delete_contact(contact, options = {})
  client.delete(Client.versioned("contacts/#{contact}"), options)
end

#update_contact(contact, attributes = {}, options = {}) ⇒ Struct::Contact Also known as: update

Updates a contact in the account.

Parameters:

  • contact (Fixnum)

    The contact id.

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

Returns:

Raises:

See Also:



62
63
64
65
66
67
# File 'lib/dnsimple/client/contacts.rb', line 62

def update_contact(contact, attributes = {}, options = {})
  options  = options.merge(contact: attributes)
  response = client.put(Client.versioned("/contacts/#{contact}"), options)

  Struct::Contact.new(response["contact"])
end