Class: Fog::DNS::Dreamhost::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/dreamhost/dns.rb,
lib/fog/dreamhost/requests/dns/list_records.rb,
lib/fog/dreamhost/requests/dns/create_record.rb,
lib/fog/dreamhost/requests/dns/delete_record.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/dreamhost/dns.rb', line 49

def initialize(options={})
  @dreamhost_api_key  = options[:dreamhost_api_key]
  if options[:dreamhost_url]
    uri = URI.parse(options[:dreamhost_url])
    options[:host]    = uri.host
    options[:port]    = uri.port
    options[:scheme]  = uri.scheme
  end
  @host       = options[:host]        || "api.dreamhost.com"
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent)
end

Instance Method Details

#create_record(record, type, value, comment = "") ⇒ Object



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

def create_record(record, type, value, comment = "")
  request( :expects  => 200,
           :method   => 'GET',
           :path     => "/",
           :query    => { 
             :record    => record,
             :type      => type,
             :value     => value,
             :cmd       => 'dns-add_record',
             :comment   => comment
           }
         )
end

#delete_record(name, type, value) ⇒ Object



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

def delete_record(name, type, value)
  request( :expects  => 200,
           :method   => "GET",
           :path     => "/",
           :query    => { 
             :cmd      => 'dns-remove_record',
             :type     => type,
             :record   => name,
             :value    => value,
           } 
         )
end

#list_recordsObject



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

def list_records
  request( :expects  => 200,
           :method   => "GET",
           :path     => "/",
           :query    => { :cmd => 'dns-list_records' } )
end

#reloadObject



64
65
66
# File 'lib/fog/dreamhost/dns.rb', line 64

def reload
  @connection.reset
end

#request(params) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/dreamhost/dns.rb', line 68

def request(params)
  params[:query].merge!( { :key => @dreamhost_api_key,
                           :format => 'json' } )
  response = @connection.request(params)

  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  if response.body['result'] != 'success'
    raise response.body['data']
  end
  response
end