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,
lib/fog/dnsimple/requests/dns/list_all_domains.rb,
lib/fog/dnsimple/requests/dns/list_all_records.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



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

def initialize(options = {})
  @dnsimple_token = options[:dnsimple_token]
  @dnsimple_account = options[:dnsimple_account]

  if options[:dnsimple_url]
    uri = URI.parse(options[:dnsimple_url])
    options[:host]    = uri.host
    options[:port]    = uri.port
    options[:scheme]  = uri.scheme
  end

  connection_options = options[:connection_options] || {}
  connection_options[:headers] ||= {}
  connection_options[:headers]["User-Agent"] = "#{Fog::Core::Connection.user_agents} fog-dnsimple/#{Fog::Dnsimple::VERSION}"

  host       = options[:host]        || "api.dnsimple.com"
  persistent = options[:persistent]  || false
  port       = options[:port]        || 443
  scheme     = options[:scheme]      || "https"
  @connection = Fog::Core::Connection.new("#{scheme}://#{host}:#{port}", persistent, connection_options)
end

Instance Method Details

#create_domain(zone_name) ⇒ Object

Create a single domain in DNSimple in your account.

Parameters

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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • “data”<~Hash> The representation of the domain.



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

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

  request(
    body:     Fog::JSON.encode(body),
    expects:  201,
    method:   "POST",
    path:     "/#{@dnsimple_account}/domains"
  )
end

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

Create a new host in the specified zone

Parameters

  • zone_name<~String> - zone name

  • 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.



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

def create_record(zone_name, name, type, content, options = {})
  body = {
    "name" => name,
    "type" => type,
    "content" => content
  }
  body.merge!(options)

  request(
    body:     Fog::JSON.encode(body),
    expects:  201,
    method:   "POST",
    path:     "/#{@dnsimple_account}/zones/#{zone_name}/records"
  )
end

#delete_domain(zone_name) ⇒ 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

  • account_id<~String> - the account the domain belong to

  • zone_name<~String> - zone name



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

def delete_domain(zone_name)
  request(
    expects:  204,
    method:   "DELETE",
    path:     "/#{@dnsimple_account}/domains/#{zone_name}"
  )
end

#delete_record(zone_name, record_id) ⇒ Object

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

Parameters

  • zone_name<~String> - zone name

  • record_id<~String>



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

def delete_record(zone_name, record_id)
  request(
    expects:  204,
    method:   "DELETE",
    path:     "/#{@dnsimple_account}/zones/#{zone_name}/records/#{record_id}"
  )
end

#get_domain(zone_name) ⇒ 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

  • zone_name<~String> - zone name

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • “data”<~Hash> The representation of the domain.



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

def get_domain(zone_name)
  request(
    expects:  200,
    method:   "GET",
    path:     "/#{@dnsimple_account}/domains/#{zone_name}"
  )
end

#get_record(zone_name, record_id) ⇒ Object

Gets record from given domain.

Parameters

  • zone_name<~String> - zone name

  • record_id<~String>

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • “data”<~Hash> The representation of the record.



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

def get_record(zone_name, record_id)
  request(
    expects:  200,
    method:   "GET",
    path:     "/#{@dnsimple_account}/zones/#{zone_name}/records/#{record_id}"
  )
end

#list_all_domains(query: {}) ⇒ Excon::Response

Get the list of ALL domains in the account.

This method is similar to #list_domains, but instead of returning the results of a specific page it iterates all the pages and returns the entire collection.

Please use this method carefully, as fetching the entire collection will increase the number of requests you send to the API server and you may eventually be rate-limited.



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

def list_all_domains(query: {})
  paginate(query: query) do |current_query|
    list_domains(query: current_query)
  end
end

#list_all_records(zone_name, query: {}) ⇒ Excon::Response

Get the list of ALL records for the specific zone.

This method is similar to #list_domains, but instead of returning the results of a specific page it iterates all the pages and returns the entire collection.

Please use this method carefully, as fetching the entire collection will increase the number of requests you send to the API server and you may eventually be rate-limited.

Parameters:

  • zone_name (String)
  • query (Hash) (defaults to: {})

Returns:

  • (Excon::Response)

See Also:



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

def list_all_records(zone_name, query: {})
  paginate(query: query) do |current_query|
    list_records(zone_name, query: current_query)
  end
end

#list_domains(query: {}) ⇒ Excon::Response

Get the paginated list of domains in the account.



12
13
14
15
16
17
18
19
# File 'lib/fog/dnsimple/requests/dns/list_domains.rb', line 12

def list_domains(query: {})
  request(
    expects: 200,
    method: "GET",
    path: "/#{@dnsimple_account}/domains",
    query: query
  )
end

#list_records(zone_name, query: {}) ⇒ Excon::Response

Get the paginated list of records for the specific zone.

Parameters:

  • zone_name (String)
  • query (Hash) (defaults to: {})

Returns:

  • (Excon::Response)

See Also:



13
14
15
16
17
18
19
20
# File 'lib/fog/dnsimple/requests/dns/list_records.rb', line 13

def list_records(zone_name, query: {})
  request(
    expects: 200,
    method: "GET",
    path: "/#{@dnsimple_account}/zones/#{zone_name}/records",
    query: query
  )
end

#reloadObject



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

def reload
  @connection.reset
end

#request(params) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fog/dnsimple/dns.rb', line 82

def request(params)
  params[:headers] ||= {}

  if @dnsimple_token && @dnsimple_account
    params[:headers].merge!("Authorization" => "Bearer #{@dnsimple_token}")
  else
    raise ArgumentError.new("Insufficient credentials to properly authenticate!")
  end
  params[:headers].merge!(
      "Accept" => "application/json",
      "Content-Type" => "application/json"
  )

  version = params.delete(:version) || "v2"
  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_record(zone_name, record_id, options) ⇒ Object

Update the given record for the given domain.

Parameters

  • zone_name<~String> - zone name

  • record_id<~String>

  • options<~Hash> - optional

    • type<~String>

    • content<~String>

    • priority<~Integer>

    • ttl<~Integer>

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • “data”<~Hash> The representation of the record.



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

def update_record(zone_name, record_id, options)
  body = options

  request(
    body:     Fog::JSON.encode(body),
    expects:  200,
    method:   "PATCH",
    path:     "/#{@dnsimple_account}/zones/#{zone_name}/records/#{record_id}"
  )
end