-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,374 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Dnsimple | ||
class Client | ||
|
||
class ClientService < Struct.new(:client) | ||
private | ||
|
||
def validate_mandatory_attributes(attributes, required) | ||
required.each do |name| | ||
attributes.key?(name) or raise(ArgumentError, ":#{name} is required") | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module Dnsimple | ||
class Client | ||
class ContactsService < ClientService | ||
|
||
# Lists the contacts in the account. | ||
# | ||
# @see http://developer.dnsimple.com/contacts/#list | ||
# | ||
# @return [Array<Record>] | ||
# @raise [RequestError] When the request fails. | ||
def list | ||
response = client.get("v1/contacts") | ||
|
||
response.map { |r| Contact.new(r["contact"]) } | ||
end | ||
|
||
# Creates a contact in the account. | ||
# | ||
# @see http://developer.dnsimple.com/contacts/#create | ||
# | ||
# @param [Hash] attributes | ||
# | ||
# @return [Contact] | ||
# @raise [RequestError] When the request fails. | ||
def create(attributes = {}) | ||
validate_mandatory_attributes(attributes, [:first_name, :last_name, :address1, :city, :state_province, :postal_code, :country, :phone, :email_address]) | ||
options = { body: { contact: attributes }} | ||
response = client.post("v1/contacts", options) | ||
|
||
Contact.new(response["contact"]) | ||
end | ||
|
||
# Gets a contact from the account. | ||
# | ||
# @see http://developer.dnsimple.com/contacts/#get | ||
# | ||
# @param [Fixnum] contact The contact id. | ||
# | ||
# @return [Contact] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def find(contact) | ||
response = client.get("v1/contacts/#{contact}") | ||
|
||
Contact.new(response["contact"]) | ||
end | ||
|
||
# Updates a contact in the account. | ||
# | ||
# @see http://developer.dnsimple.com/contacts/#update | ||
# | ||
# @param [Fixnum] contact The contact id. | ||
# @param [Hash] attributes | ||
# | ||
# @return [Contact] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def update(contact, attributes = {}) | ||
options = { body: { contact: attributes }} | ||
response = client.put("v1/contacts/#{contact}", options) | ||
|
||
Contact.new(response["contact"]) | ||
end | ||
|
||
# Deletes a contact from the account. | ||
# | ||
# WARNING: this cannot be undone. | ||
# | ||
# @see http://developer.dnsimple.com/contacts/#delete | ||
# | ||
# @param [Fixnum] contact The contact id. | ||
# | ||
# @return [void] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def delete(contact) | ||
client.delete("v1/contacts/#{contact}") | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Dnsimple | ||
class Client | ||
class NameServersService < ClientService | ||
|
||
# Lists the name servers for a domain. | ||
# | ||
# @see http://developer.dnsimple.com/domains/nameservers/#list | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# | ||
# @return [Array<String>] The delegates name servers. | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def list(domain) | ||
response = client.get("v1/domains/#{domain}/name_servers") | ||
response.parsed_response | ||
end | ||
|
||
# Changes the name servers for a domain. | ||
# | ||
# @see http://developer.dnsimple.com/domains/nameservers/#change | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Array<String>] servers The name server list. | ||
# | ||
# @return [Array<String>] The delegates name servers. | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def change(domain, servers) | ||
servers = servers.inject({}) { |hash, server| hash.merge("ns#{hash.length + 1}" => server) } | ||
options = { body: { name_servers: servers } } | ||
response = client.post("v1/domains/#{domain}/name_servers", options) | ||
response.parsed_response | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
module Dnsimple | ||
class Client | ||
class RecordsService < ClientService | ||
|
||
# Lists the records in the account. | ||
# | ||
# @see http://developer.dnsimple.com/domains/records/#list | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Hash] options | ||
# | ||
# @return [Array<Record>] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def list(domain, options = {}) | ||
response = client.get("v1/domains/#{domain}/records", options) | ||
|
||
response.map { |r| Record.new(r["record"]) } | ||
end | ||
|
||
# Creates a record in the account. | ||
# | ||
# @see http://developer.dnsimple.com/domains/records/#create | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Hash] attributes | ||
# | ||
# @return [Record] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def create(domain, attributes = {}) | ||
validate_mandatory_attributes(attributes, [:name, :record_type, :content]) | ||
options = { body: { record: attributes }} | ||
response = client.post("v1/domains/#{domain}/records", options) | ||
|
||
Record.new(response["record"]) | ||
end | ||
|
||
# Gets a record from the account. | ||
# | ||
# @see http://developer.dnsimple.com/domains/records/#get | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Fixnum] record The record id. | ||
# | ||
# @return [Record] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def find(domain, record) | ||
response = client.get("v1/domains/#{domain}/records/#{record}") | ||
|
||
Record.new(response["record"]) | ||
end | ||
|
||
# Updates a record in the account. | ||
# | ||
# @see http://developer.dnsimple.com/domains/records/#update | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Fixnum] record The record id. | ||
# @param [Hash] attributes | ||
# | ||
# @return [Record] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def update(domain, record, attributes = {}) | ||
options = { body: { record: attributes }} | ||
response = client.put("v1/domains/#{domain}/records/#{record}", options) | ||
|
||
Record.new(response["record"]) | ||
end | ||
|
||
# Deletes a record from the account. | ||
# | ||
# WARNING: this cannot be undone. | ||
# | ||
# @see http://developer.dnsimple.com/domains/records/#delete | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Fixnum] record The record id. | ||
# | ||
# @return [void] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def delete(domain, record) | ||
client.delete("v1/domains/#{domain}/records/#{record}") | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
module Dnsimple | ||
class Client | ||
class ServicesService < ClientService | ||
|
||
# Lists the supported services. | ||
# | ||
# @see http://developer.dnsimple.com/services/#list | ||
# | ||
# @return [Array<Service>] | ||
# @raise [RequestError] When the request fails. | ||
def list | ||
response = client.get("v1/services") | ||
|
||
response.map { |r| Service.new(r["service"]) } | ||
end | ||
|
||
# Gets a service. | ||
# | ||
# @see http://developer.dnsimple.com/services/#get | ||
# | ||
# @param [Fixnum] service The service id. | ||
# | ||
# @return [Service] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def find(service) | ||
response = client.get("v1/services/#{service}") | ||
|
||
Service.new(response["service"]) | ||
end | ||
|
||
# List the services applied to a domain. | ||
# | ||
# @see http://developer.dnsimple.com/services/#applied | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# | ||
# @return [Array<Service>] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def applied(domain) | ||
response = client.get("v1/domains/#{domain}/applied_services") | ||
|
||
response.map { |r| Service.new(r["service"]) } | ||
end | ||
|
||
# List the services not applied to a domain. | ||
# | ||
# @see http://developer.dnsimple.com/services/#available | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# | ||
# @return [Array<Service>] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def available(domain) | ||
response = client.get("v1/domains/#{domain}/available_services") | ||
|
||
response.map { |r| Service.new(r["service"]) } | ||
end | ||
|
||
# Apply a service to a domain. | ||
# | ||
# @see http://developer.dnsimple.com/services/#apply | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Fixnum] service The service id. | ||
# | ||
# @return [void] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def apply(domain, service) | ||
options = { body: { service: { id: service }}} | ||
response = client.post("v1/domains/#{domain}/applied_services", options) | ||
response.code == 200 | ||
end | ||
|
||
# Un-apply a service from a domain. | ||
# | ||
# @see http://developer.dnsimple.com/services/#unapply | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Fixnum] service The service id. | ||
# | ||
# @return [void] | ||
# @raise [RecordNotFound] | ||
# @raise [RequestError] When the request fails. | ||
def unapply(domain, service) | ||
response = client.delete("v1/domains/#{domain}/applied_services/#{service}") | ||
response.code == 200 | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.