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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/dreamhost/dns.rb', line 44

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::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent)
end

Instance Method Details

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



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/dreamhost/requests/dns/create_record.rb', line 11

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



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/dreamhost/requests/dns/delete_record.rb', line 11

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



11
12
13
14
15
16
# File 'lib/fog/dreamhost/requests/dns/list_records.rb', line 11

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

#reloadObject



59
60
61
# File 'lib/fog/dreamhost/dns.rb', line 59

def reload
  @connection.reset
end

#request(params) ⇒ Object



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

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