Class: Gandi::Contact
- Inherits:
-
Object
- Object
- Gandi::Contact
- Includes:
- GandiObjectMethods
- Defined in:
- lib/gandi/contact.rb
Constant Summary collapse
- TYPES =
Contact types mapping
{ 0 => 'person', 1 => 'company', 2 => 'association', 3 => 'organization', 4 => 'reseller' }
- SECURITY_QUESTION_NUM_VALUES =
Security questions mapping
{ 1 => "What is the name of your favorite city?", 2 => "What is your mother’s maiden name?", 3 => "What is your favorite food?", 4 => "What year were you born in?", 5 => "What is your cell phone number?", 6 => "In what year was your Gandi account created?" }
- WRITABLE_ATTRIBUTES =
Settable contact attributes (ie. not the id or handle)
:type, :orgname, :given, :family, :streetaddr, :city, :state, :zip, :country, :phone, :fax, :mobile, :tva_number, :siren, :marque, :lang, :newsletter, :obfuscated, :whois_obfuscated, :resell, :shippingaddress, :extra_parameters
- CREATE_PARAMETERS_ATTRIBUTES =
Additional attributes used when creating an account
:password, :email, :jo_announce_page, :jo_announce_number, :jo_declaration_date, :jo_publication_date, :security_question_num, :security_question_answer
- INFORMATION_ATTRIBUTES =
Attributes returned when calling contact.info or creating/updating a contact
WRITABLE_ATTRIBUTES + [:id]
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Class Method Summary collapse
-
.can_associate(contact, domain) ⇒ Object
(also: can_associate?)
Test if a contact (full contact description) can be associated to the domains.
-
.create(contact) ⇒ Object
Should have a all optional contact dict then look if he is a person or a company and depending on that call create_person or create_company.
-
.info ⇒ Object
Give all information on the contact linked to the apikey currently used.
-
.list(opts = {}, map_contacts = true) ⇒ Object
List all contacts linked to the connected user (it will only return contacts when the apikey belong to a reseller).
-
.update(handle, contact) ⇒ Object
Check the same way as check and then update.
Instance Method Summary collapse
-
#[]=(attribute, value) ⇒ Object
Sets a contact attribute value.
-
#can_associate_domain(domain) ⇒ Object
(also: #can_associate_domain?)
Test if a contact (defined by its handle) can create that domain.
-
#id ⇒ Object
Returns the contact unique identifier.
-
#info ⇒ Object
Give all information on the given contact.
-
#initialize(handle = nil, contact = nil) ⇒ Contact
constructor
A new instance of Contact.
-
#persisted? ⇒ Boolean
Returns true if the contact exists on Gandi databases.
-
#to_s ⇒ Object
Returns a string containing the handle of the contact.
-
#type ⇒ Object
Returns the contact type string.
-
#type=(type_string_or_id) ⇒ Object
Sets the contact type (provided with a type string or id).
-
#update(contact) ⇒ Object
Update a contact with the given information.
Methods included from GandiObjectMethods
#[], included, #inspect, #to_hash
Constructor Details
#initialize(handle = nil, contact = nil) ⇒ Contact
A new instance of Contact. Takes a Gandi handle and/or a contact hash with string keys. When providing only a handle the contact info will be fetched from the API.
44 45 46 47 48 |
# File 'lib/gandi/contact.rb', line 44 def initialize(handle = nil, contact = nil) @handle = handle @attributes = {} self.attributes=(contact) if (@handle || contact) end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
39 40 41 |
# File 'lib/gandi/contact.rb', line 39 def handle @handle end |
Class Method Details
.can_associate(contact, domain) ⇒ Object Also known as: can_associate?
Test if a contact (full contact description) can be associated to the domains. Takes a contact hash and a domain hash. TODO allow giving a string for the domain and converting it transparently, or a domain object. FIXME is checking multiple domains at once possible ? (it may be according to the Gandi documentation). FIXME OT&E seems to fail instead of returning an error hash (Error on object : OBJECT_APPLICATION (CAUSE_UNKNOWN) [Internal Server Error]).
138 139 140 |
# File 'lib/gandi/contact.rb', line 138 def can_associate(contact, domain) call('contact.can_associate', contact, domain) end |
.create(contact) ⇒ Object
Should have a all optional contact dict then look if he is a person or a company and depending on that call create_person or create_company. Returns a contact object. TODO filter params.
122 123 124 125 |
# File 'lib/gandi/contact.rb', line 122 def create(contact) contact = call('contact.create', contact) self.new(contact['handle'], contact) end |
.info ⇒ Object
Give all information on the contact linked to the apikey currently used. Returns a hash.
129 130 131 |
# File 'lib/gandi/contact.rb', line 129 def info call('contact.info') end |
.list(opts = {}, map_contacts = true) ⇒ Object
List all contacts linked to the connected user (it will only return contacts when the apikey belong to a reseller). The array of returned contacts are mapped to contact objects, set map_contacts to false to get contact info hashes.
147 148 149 150 151 152 153 154 155 |
# File 'lib/gandi/contact.rb', line 147 def list(opts = {}, map_contacts = true) contacts = call('contact.list', opts) if map_contacts contacts.map! do |contact| self.new(contact['handle'], contact) end end contacts end |
.update(handle, contact) ⇒ Object
Check the same way as check and then update. Returns a contact object. TODO filter params.
160 161 162 163 |
# File 'lib/gandi/contact.rb', line 160 def update(handle, contact) contact = call('contact.update', handle, contact) self.new(contact['handle'], contact) end |
Instance Method Details
#[]=(attribute, value) ⇒ Object
Sets a contact attribute value.
103 104 105 106 |
# File 'lib/gandi/contact.rb', line 103 def []=(attribute, value) raise DataError, "Attribute #{attribute} is read-only" unless WRITABLE_ATTRIBUTES.include?(attribute.to_sym) @attributes[attribute.to_s] = value end |
#can_associate_domain(domain) ⇒ Object Also known as: can_associate_domain?
Test if a contact (defined by its handle) can create that domain. Takes a domain hash. TODO allow giving a string for the domain and converting it transparently, or a domain object. FIXME is checking multiple domains at once possible ? (it may be according to the Gandi documentation). FIXME OT&E seems to fail instead of returning an error hash (Error on object : OBJECT_APPLICATION (CAUSE_UNKNOWN) [Internal Server Error]).
55 56 57 58 |
# File 'lib/gandi/contact.rb', line 55 def can_associate_domain(domain) return false unless persisted? self.class.call('contact.can_associate_domain', @handle, domain) end |
#id ⇒ Object
Returns the contact unique identifier.
88 89 90 |
# File 'lib/gandi/contact.rb', line 88 def id @attributes['id'] end |
#info ⇒ Object
Give all information on the given contact. This should not be directly used as initializing the class already fetches the contact info.
65 66 67 68 |
# File 'lib/gandi/contact.rb', line 65 def info raise DataError, "Cannot get informations for a new contact" unless persisted? self.class.call('contact.info', @handle) end |
#persisted? ⇒ Boolean
Returns true if the contact exists on Gandi databases.
114 115 116 |
# File 'lib/gandi/contact.rb', line 114 def persisted? !!@handle end |
#to_s ⇒ Object
Returns a string containing the handle of the contact.
109 110 111 |
# File 'lib/gandi/contact.rb', line 109 def to_s @handle || '' end |
#type ⇒ Object
Returns the contact type string.
93 94 95 |
# File 'lib/gandi/contact.rb', line 93 def type TYPES[@attributes['type']] end |
#type=(type_string_or_id) ⇒ Object
Sets the contact type (provided with a type string or id).
98 99 100 |
# File 'lib/gandi/contact.rb', line 98 def type=(type_string_or_id) @attributes['type'] = TYPES.invert[type_string_or_id] || type_string_or_id end |
#update(contact) ⇒ Object
Update a contact with the given information. If the contact is associated to domains, it will check the same rules as can_associate* and then update if possible.
72 73 74 75 |
# File 'lib/gandi/contact.rb', line 72 def update(contact) raise DataError, "Cannot update a new contact, use Gandi::Contact.create instead" unless persisted? self.attributes = self.class.call('contact.update', @handle, contact) end |