Class: DNSimple::Contact
Overview
Represents a contact.
Constant Summary collapse
- Aliases =
{ 'first' => 'first_name', 'last' => 'last_name', 'state' => 'state_province', 'province' => 'state_province', 'state_or_province' => 'state_province', 'email' => 'email_address', }
Instance Attribute Summary collapse
-
#address1 ⇒ Object
The contact street address.
-
#address2 ⇒ Object
Apartment or suite number.
-
#city ⇒ Object
The city name.
-
#country ⇒ Object
The contact country (as a 2-character country code).
-
#created_at ⇒ Object
When the contact was created in DNSimple.
-
#email_address ⇒ Object
The contact email address.
-
#fax ⇒ Object
The contact fax number (may be omitted).
-
#first_name ⇒ Object
The contact first name.
-
#id ⇒ Object
The contact ID in DNSimple.
-
#job_title ⇒ Object
The contact’s job title.
-
#last_name ⇒ Object
The contact last name.
-
#organization_name ⇒ Object
The name of the organization in which the contact works.
-
#phone ⇒ Object
The contact phone number.
-
#phone_ext ⇒ Object
The contact phone extension (may be omitted).
-
#postal_code ⇒ Object
The contact postal code.
-
#state_province ⇒ Object
The state or province name.
-
#updated_at ⇒ Object
When the contact was last updated in DNSimple.
Class Method Summary collapse
- .all(options = {}) ⇒ Object
-
.create(attributes, options = {}) ⇒ Object
Create the contact with the given attributes in DNSimple.
- .find(id, options = {}) ⇒ Object
-
.resolve(name) ⇒ Object
Map an aliased field name to it’s real name.
- .resolve_attributes(attributes) ⇒ Object
Instance Method Summary collapse
-
#delete(options = {}) ⇒ Object
(also: #destroy)
Delete the contact from DNSimple.
- #name ⇒ Object
- #save(options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from DNSimple::Base
Instance Attribute Details
#address1 ⇒ Object
The contact street address
43 44 45 |
# File 'lib/dnsimple/contact.rb', line 43 def address1 @address1 end |
#address2 ⇒ Object
Apartment or suite number
46 47 48 |
# File 'lib/dnsimple/contact.rb', line 46 def address2 @address2 end |
#city ⇒ Object
The city name
49 50 51 |
# File 'lib/dnsimple/contact.rb', line 49 def city @city end |
#country ⇒ Object
The contact country (as a 2-character country code)
58 59 60 |
# File 'lib/dnsimple/contact.rb', line 58 def country @country end |
#created_at ⇒ Object
When the contact was created in DNSimple
61 62 63 |
# File 'lib/dnsimple/contact.rb', line 61 def created_at @created_at end |
#email_address ⇒ Object
The contact email address
31 32 33 |
# File 'lib/dnsimple/contact.rb', line 31 def email_address @email_address end |
#fax ⇒ Object
The contact fax number (may be omitted)
40 41 42 |
# File 'lib/dnsimple/contact.rb', line 40 def fax @fax end |
#first_name ⇒ Object
The contact first name
19 20 21 |
# File 'lib/dnsimple/contact.rb', line 19 def first_name @first_name end |
#id ⇒ Object
The contact ID in DNSimple
16 17 18 |
# File 'lib/dnsimple/contact.rb', line 16 def id @id end |
#job_title ⇒ Object
The contact’s job title
25 26 27 |
# File 'lib/dnsimple/contact.rb', line 25 def job_title @job_title end |
#last_name ⇒ Object
The contact last name
22 23 24 |
# File 'lib/dnsimple/contact.rb', line 22 def last_name @last_name end |
#organization_name ⇒ Object
The name of the organization in which the contact works
28 29 30 |
# File 'lib/dnsimple/contact.rb', line 28 def organization_name @organization_name end |
#phone ⇒ Object
The contact phone number
34 35 36 |
# File 'lib/dnsimple/contact.rb', line 34 def phone @phone end |
#phone_ext ⇒ Object
The contact phone extension (may be omitted)
37 38 39 |
# File 'lib/dnsimple/contact.rb', line 37 def phone_ext @phone_ext end |
#postal_code ⇒ Object
The contact postal code
55 56 57 |
# File 'lib/dnsimple/contact.rb', line 55 def postal_code @postal_code end |
#state_province ⇒ Object
The state or province name
52 53 54 |
# File 'lib/dnsimple/contact.rb', line 52 def state_province @state_province end |
#updated_at ⇒ Object
When the contact was last updated in DNSimple
64 65 66 |
# File 'lib/dnsimple/contact.rb', line 64 def updated_at @updated_at end |
Class Method Details
.all(options = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/dnsimple/contact.rb', line 112 def self.all(={}) response = DNSimple::Client.get("/v1/contacts", ) case response.code when 200 response.map { |r| new(r["contact"]) } else raise RequestError.new("Error listing contacts", response) end end |
.create(attributes, options = {}) ⇒ Object
Create the contact with the given attributes in DNSimple. This method returns a Contact instance of the contact is created and raises an error otherwise.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dnsimple/contact.rb', line 85 def self.create(attributes, ={}) contact_hash = resolve_attributes(attributes) .merge!({:body => {:contact => contact_hash}}) response = DNSimple::Client.post("/v1/contacts", ) case response.code when 201 new(response["contact"]) else raise RequestError.new("Error creating contact", response) end end |
.find(id, options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/dnsimple/contact.rb', line 99 def self.find(id, ={}) response = DNSimple::Client.get("/v1/contacts/#{id}", ) case response.code when 200 new(response["contact"]) when 404 raise RecordNotFound, "Could not find contact #{id}" else raise RequestError.new("Error finding contact", response) end end |
.resolve(name) ⇒ Object
Map an aliased field name to it’s real name. For example, if you pass “first” it will be resolved to “first_name”, “email” is resolved to “email_address” and so on.
70 71 72 |
# File 'lib/dnsimple/contact.rb', line 70 def self.resolve(name) DNSimple::Contact::Aliases[name.to_s] || name end |
.resolve_attributes(attributes) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/dnsimple/contact.rb', line 74 def self.resolve_attributes(attributes) resolved_attributes = {} attributes.each do |k, v| resolved_attributes[resolve(k)] = v end resolved_attributes end |
Instance Method Details
#delete(options = {}) ⇒ Object Also known as: destroy
Delete the contact from DNSimple. WARNING: this cannot be undone.
148 149 150 |
# File 'lib/dnsimple/contact.rb', line 148 def delete(={}) DNSimple::Client.delete("/v1/contacts/#{id}", ) end |
#name ⇒ Object
124 125 126 |
# File 'lib/dnsimple/contact.rb', line 124 def name [first_name, last_name].join(' ') end |
#save(options = {}) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/dnsimple/contact.rb', line 128 def save(={}) contact_hash = {} %w(first_name last_name organization_name job_title address1 address2 city state_province postal_code country email_address phone phone_ext fax).each do |attribute| contact_hash[DNSimple::Contact.resolve(attribute)] = self.send(attribute) end .merge!({:body => {:contact => contact_hash}}) response = DNSimple::Client.put("/v1/contacts/#{id}", ) case response.code when 200 return self else raise RequestError.new("Error updating contact", response) end end |