Class: Fog::DNS::DNSimple::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/dnsimple/dns.rb,
lib/fog/dnsimple/requests/dns/get_domain.rb,
lib/fog/dnsimple/requests/dns/get_record.rb,
lib/fog/dnsimple/requests/dns/list_domains.rb,
lib/fog/dnsimple/requests/dns/list_records.rb,
lib/fog/dnsimple/requests/dns/create_domain.rb,
lib/fog/dnsimple/requests/dns/create_record.rb,
lib/fog/dnsimple/requests/dns/delete_domain.rb,
lib/fog/dnsimple/requests/dns/delete_record.rb,
lib/fog/dnsimple/requests/dns/update_record.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/dnsimple/dns.rb', line 60

def initialize(options={})
  @dnsimple_email = options[:dnsimple_email]
  @dnsimple_password  = options[:dnsimple_password]
  @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::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#create_domain(name) ⇒ Object

Create a single domain in DNSimple in your account.

Parameters

  • name<~String> - domain name to host (ie example.com)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘domain’<~Hash> The representation of the domain.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/dnsimple/requests/dns/create_domain.rb', line 15

def create_domain(name)
  body = {
    "domain" => {
      "name" => name
    }
  }

  request(
    :body     => Fog::JSON.encode(body),
    :expects  => 201,
    :method   => 'POST',
    :path     => "/domains"
  )
end

#create_record(domain, name, type, content, options = {}) ⇒ Object

Create a new host in the specified zone

Parameters

  • domain<~String> - domain name or numeric ID

  • name<~String>

  • type<~String>

  • content<~String>

  • options<~Hash> - optional

    • priority<~Integer>

    • ttl<~Integer>

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘record’<~Hash> The representation of the record.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/dnsimple/requests/dns/create_record.rb', line 21

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_domain(domain) ⇒ Object

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.

Parameters

  • domain<~String> - domain name or numeric ID



15
16
17
18
19
20
21
# File 'lib/fog/dnsimple/requests/dns/delete_domain.rb', line 15

def delete_domain(domain)
  request(
    :expects  => 200,
    :method   => 'DELETE',
    :path     => "/domains/#{domain}"
  )
end

#delete_record(domain, record_id) ⇒ Object

Delete the record with the given ID for the given domain.

Parameters

  • domain<~String> - domain name or numeric ID

  • record_id<~String>



11
12
13
14
15
16
17
# File 'lib/fog/dnsimple/requests/dns/delete_record.rb', line 11

def delete_record(domain, record_id)
  request(
    :expects  => 200,
    :method   => "DELETE",
    :path     => "/domains/#{domain}/records/#{record_id}"
  )
end

#get_domain(domain) ⇒ Object

Get the details for a specific domain in your account. You may pass either the domain numeric ID or the domain name itself.

Parameters

  • domain<~String> - domain name or numeric ID

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘domain’<~Hash> The representation of the domain.



17
18
19
20
21
22
23
# File 'lib/fog/dnsimple/requests/dns/get_domain.rb', line 17

def get_domain(domain)
  request(
    :expects  => 200,
    :method   => "GET",
    :path     => "/domains/#{domain}"
  )
end

#get_record(domain, record_id) ⇒ Object

Gets record from given domain.

Parameters

  • domain<~String> - domain name or numeric ID

  • record_id<~String>

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘record’<~Hash> The representation of the record.



16
17
18
19
20
21
22
# File 'lib/fog/dnsimple/requests/dns/get_record.rb', line 16

def get_record(domain, record_id)
  request(
    :expects  => 200,
    :method   => "GET",
    :path     => "/domains/#{domain}/records/#{record_id}"
  )
end

#list_domainsObject

Get the details for a specific domain in your account. You may pass either the domain numeric ID or the domain name itself.

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • <~Array>:

        • ‘domain’<~Hash> The representation of the domain.



16
17
18
19
20
21
22
# File 'lib/fog/dnsimple/requests/dns/list_domains.rb', line 16

def list_domains
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => '/domains'
  )
end

#list_records(domain) ⇒ Object

Get the list of records for the specific domain.

Parameters

  • domain<~String> - domain name or numeric ID

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • <~Array>:

        • ‘record’<~Hash> The representation of the record.



16
17
18
19
20
21
22
# File 'lib/fog/dnsimple/requests/dns/list_records.rb', line 16

def list_records(domain)
  request(
    :expects  => 200,
    :method   => "GET",
    :path     => "/domains/#{domain}/records"
  )
end

#reloadObject



77
78
79
# File 'lib/fog/dnsimple/dns.rb', line 77

def reload
  @connection.reset
end

#request(params) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fog/dnsimple/dns.rb', line 81

def request(params)
  params[:headers] ||= {}
  key = "#{@dnsimple_email}:#{@dnsimple_password}"
  params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).gsub("\n",''),
                            "Accept" => "application/json",
                            "Content-Type" => "application/json" })

  version = params.delete(:version) || 'v1'
  params[:path] = "/#{version}#{params[:path]}"

  response = @connection.request(params)

  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#update_record(domain, record_id, options) ⇒ Object

Update the given record for the given domain.

Parameters

  • domain<~String> - domain name or numeric ID

  • record_id<~String>

  • options<~Hash> - optional

    • type<~String>

    • content<~String>

    • priority<~Integer>

    • ttl<~Integer>

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘record’<~Hash> The representation of the record.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/dnsimple/requests/dns/update_record.rb', line 21

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