# File lib/fog/dnsimple/dns.rb, line 56 def initialize(options={}) @dnsimple_email = options[:dnsimple_email] @dnsimple_password = options[:dnsimple_password] @dnsimple_token = options[:dnsimple_token] @dnsimple_domain = options[:dnsimple_domain] @connection_options = options[:connection_options] || {} if options[:dnsimple_url] uri = URI.parse(options[:dnsimple_url]) options[:host] = uri.host options[:port] = uri.port options[:scheme] = uri.scheme end @host = options[:host] || "api.dnsimple.com" @persistent = options[:persistent] || false @port = options[:port] || 443 @scheme = options[:scheme] || 'https' @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end
Create a single domain in DNSimple in your account.
name<~String> - domain name to host (ie example.com)
response<~Excon::Response>:
body<~Hash>:
'domain'<~Hash> The representation of the domain.
# File lib/fog/dnsimple/requests/dns/create_domain.rb, line 14 def create_domain(name) body = { "domain" => { "name" => name } } request( :body => Fog::JSON.encode(body), :expects => 201, :method => 'POST', :path => "/domains" ) end
Create a new host in the specified zone
domain<~String> - domain name or numeric ID
name<~String>
type<~String>
content<~String>
options<~Hash> - optional
priority<~Integer>
ttl<~Integer>
response<~Excon::Response>:
body<~Hash>:
'record'<~Hash> The representation of the record.
# File lib/fog/dnsimple/requests/dns/create_record.rb, line 20 def create_record(domain, name, type, content, options = {}) body = { "record" => { "name" => name, "record_type" => type, "content" => content } } body["record"].merge!(options) request( :body => Fog::JSON.encode(body), :expects => 201, :method => 'POST', :path => "/domains/#{domain}/records" ) end
Delete the given domain from your account. You may use either the domain ID or the domain name.
Please note that for domains which are registered with DNSimple this will not delete the domain from the registry.
domain<~String> - domain name or numeric ID
# File lib/fog/dnsimple/requests/dns/delete_domain.rb, line 14 def delete_domain(domain) request( :expects => 200, :method => 'DELETE', :path => "/domains/#{domain}" ) end
Delete the record with the given ID for the given domain.
domain<~String> - domain name or numeric ID
record_id<~String>
# File lib/fog/dnsimple/requests/dns/delete_record.rb, line 10 def delete_record(domain, record_id) request( :expects => 200, :method => "DELETE", :path => "/domains/#{domain}/records/#{record_id}" ) end
Get the details for a specific domain in your account. You may pass either the domain numeric ID or the domain name itself.
domain<~String> - domain name or numeric ID
response<~Excon::Response>:
body<~Hash>:
'domain'<~Hash> The representation of the domain.
# File lib/fog/dnsimple/requests/dns/get_domain.rb, line 16 def get_domain(domain) request( :expects => 200, :method => "GET", :path => "/domains/#{domain}" ) end
Gets record from given domain.
domain<~String> - domain name or numeric ID
record_id<~String>
response<~Excon::Response>:
body<~Hash>:
'record'<~Hash> The representation of the record.
# File lib/fog/dnsimple/requests/dns/get_record.rb, line 15 def get_record(domain, record_id) request( :expects => 200, :method => "GET", :path => "/domains/#{domain}/records/#{record_id}" ) end
Get the details for a specific domain in your account. You may pass either the domain numeric ID or the domain name itself.
response<~Excon::Response>:
body<~Hash>:
<~Array>:
'domain'<~Hash> The representation of the domain.
# File lib/fog/dnsimple/requests/dns/list_domains.rb, line 15 def list_domains request( :expects => 200, :method => 'GET', :path => '/domains' ) end
Get the list of records for the specific domain.
domain<~String> - domain name or numeric ID
response<~Excon::Response>:
body<~Hash>:
<~Array>:
'record'<~Hash> The representation of the record.
# File lib/fog/dnsimple/requests/dns/list_records.rb, line 15 def list_records(domain) request( :expects => 200, :method => "GET", :path => "/domains/#{domain}/records" ) end
# File lib/fog/dnsimple/dns.rb, line 75 def reload @connection.reset end
# File lib/fog/dnsimple/dns.rb, line 79 def request(params) params[:headers] ||= {} if(@dnsimple_password) key = "#{@dnsimple_email}:#{@dnsimple_password}" params[:headers].merge!("Authorization" => "Basic " + Base64.encode64(key).gsub("\n",'')) elsif(@dnsimple_token) if(@dnsimple_domain) params[:headers].merge!("X-DNSimple-Domain-Token" => @dnsimple_token) else params[:headers].merge!("X-DNSimple-Token" => "#{@dnsimple_email}:#{@dnsimple_token}") end else raise ArgumentError.new("Insufficient credentials to properly authenticate!") end params[:headers].merge!( "Accept" => "application/json", "Content-Type" => "application/json" ) version = params.delete(:version) || 'v1' params[:path] = File.join('/', version, params[:path]) response = @connection.request(params) unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end
Update the given record for the given domain.
domain<~String> - domain name or numeric ID
record_id<~String>
options<~Hash> - optional
type<~String>
content<~String>
priority<~Integer>
ttl<~Integer>
response<~Excon::Response>:
body<~Hash>:
'record'<~Hash> The representation of the record.
# File lib/fog/dnsimple/requests/dns/update_record.rb, line 20 def update_record(domain, record_id, options) body = { "record" => options } request( :body => Fog::JSON.encode(body), :expects => 200, :method => "PUT", :path => "/domains/#{domain}/records/#{record_id}" ) end