2011-02-23 22:35:05 -05:00
|
|
|
module Fog
|
|
|
|
module DNSimple
|
|
|
|
class DNS < Fog::Service
|
|
|
|
|
|
|
|
requires :dnsimple_email, :dnsimple_password
|
2011-02-24 20:14:50 -05:00
|
|
|
recognizes :host, :path, :port, :scheme, :persistent
|
2011-02-23 22:35:05 -05:00
|
|
|
recognizes :provider # remove post deprecation
|
|
|
|
|
2011-02-24 20:14:50 -05:00
|
|
|
model_path 'fog/dns/models/dnsimple'
|
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
|
|
|
|
2011-02-23 22:35:05 -05:00
|
|
|
request_path 'fog/dns/requests/dnsimple'
|
|
|
|
request :list_domains
|
|
|
|
request :create_domain
|
|
|
|
request :get_domain
|
|
|
|
request :delete_domain
|
2011-02-24 00:56:16 -05:00
|
|
|
request :create_record
|
2011-02-24 18:22:38 -05:00
|
|
|
request :list_records
|
|
|
|
request :update_record
|
|
|
|
request :delete_record
|
2011-02-23 22:35:05 -05:00
|
|
|
|
|
|
|
class Mock
|
2011-02-24 20:14:50 -05:00
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::DNS::DNSimple.new is deprecated, use Fog::DNS.new(:provider => 'DNSimple') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
|
|
|
@dnsimple_email = options[:dnsimple_email]
|
|
|
|
@dnsimple_password = options[:dnsimple_password]
|
|
|
|
@data = self.class.data[@dnsimple_email]
|
|
|
|
end
|
2011-03-10 14:16:55 -05:00
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@dnsimple_email)
|
|
|
|
@data = self.class.data[@dnsimple_email]
|
|
|
|
end
|
|
|
|
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::DNSimple::DNS.new is deprecated, use Fog::DNS.new(:provider => 'DNSimple') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'json'
|
|
|
|
|
|
|
|
@dnsimple_email = options[:dnsimple_email]
|
|
|
|
@dnsimple_password = options[:dnsimple_password]
|
2011-02-25 00:15:44 -05:00
|
|
|
@host = options[:host] || "dnsimple.com"
|
2011-02-23 22:35:05 -05:00
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2011-02-24 20:14:50 -05:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:headers] ||= {}
|
|
|
|
key = "#{@dnsimple_email}:#{@dnsimple_password}"
|
|
|
|
params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).chomp,
|
|
|
|
"Accept" => "application/json",
|
|
|
|
"Content-Type" => "application/json" })
|
|
|
|
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
|
|
|
|
|
|
|
unless response.body.empty?
|
|
|
|
response.body = JSON.parse(response.body)
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|