lib/dnsimple/contact.rb in dnsimple-2.0.0.a vs lib/dnsimple/contact.rb in dnsimple-2.0.0.alpha2

- old
+ new

@@ -1,6 +1,6 @@ -module DNSimple +module Dnsimple # Represents a contact. class Contact < Base Aliases = { @@ -66,11 +66,11 @@ # 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. def self.resolve(name) - DNSimple::Contact::Aliases[name.to_s] || name + Contact::Aliases[name.to_s] || name end def self.resolve_attributes(attributes) resolved_attributes = {} attributes.each do |k, v| @@ -84,22 +84,22 @@ # and raises an error otherwise. def self.create(attributes, options={}) contact_hash = resolve_attributes(attributes) options.merge!({:body => {:contact => contact_hash}}) - response = DNSimple::Client.post("/v1/contacts", options) + response = Client.post("/v1/contacts", options) case response.code when 201 new(response["contact"]) else raise RequestError.new("Error creating contact", response) end end def self.find(id, options={}) - response = DNSimple::Client.get("/v1/contacts/#{id}", options) + response = Client.get("/v1/contacts/#{id}", options) case response.code when 200 new(response["contact"]) when 404 @@ -108,11 +108,11 @@ raise RequestError.new("Error finding contact", response) end end def self.all(options={}) - response = DNSimple::Client.get("/v1/contacts", options) + response = Client.get("/v1/contacts", options) case response.code when 200 response.map { |r| new(r["contact"]) } else @@ -127,27 +127,30 @@ def save(options={}) 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) + contact_hash[Contact.resolve(attribute)] = self.send(attribute) end options.merge!({:body => {:contact => contact_hash}}) - response = DNSimple::Client.put("/v1/contacts/#{id}", options) + response = Client.put("/v1/contacts/#{id}", options) case response.code when 200 return self else raise RequestError.new("Error updating contact", response) end end - # Delete the contact from DNSimple. WARNING: this cannot be undone. + # #delete the contact from DNSimple. + # + # WARNING: this cannot be undone. + # def delete(options={}) - DNSimple::Client.delete("/v1/contacts/#{id}", options) + Client.delete("/v1/contacts/#{id}", options) end alias :destroy :delete end end