2012-05-15 14:54:20 -04:00
|
|
|
require 'fog/dnsimple'
|
2011-08-31 16:52:53 -04:00
|
|
|
require 'fog/dns'
|
|
|
|
|
2011-02-23 22:35:05 -05:00
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class DNSimple < Fog::Service
|
2011-02-23 22:35:05 -05:00
|
|
|
|
|
|
|
requires :dnsimple_email, :dnsimple_password
|
2011-05-24 16:43:08 -04:00
|
|
|
recognizes :dnsimple_url, :host, :path, :port, :scheme, :persistent
|
2011-02-23 22:35:05 -05:00
|
|
|
|
2011-08-24 20:56:22 -04:00
|
|
|
model_path 'fog/dnsimple/models/dns'
|
2011-02-24 20:14:50 -05:00
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
|
|
|
|
2011-08-24 20:56:22 -04:00
|
|
|
request_path 'fog/dnsimple/requests/dns'
|
2011-02-23 22:35:05 -05:00
|
|
|
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-03-09 18:26:21 -05:00
|
|
|
request :get_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|
|
2013-07-28 14:07:29 -04:00
|
|
|
hash[key] = {
|
|
|
|
:domains => [],
|
|
|
|
:records => {}
|
|
|
|
}
|
2011-02-24 20:14:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-19 10:05:33 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2011-02-24 20:14:50 -05:00
|
|
|
def initialize(options={})
|
|
|
|
@dnsimple_email = options[:dnsimple_email]
|
|
|
|
@dnsimple_password = options[:dnsimple_password]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@dnsimple_email]
|
2011-02-24 20:14:50 -05:00
|
|
|
end
|
2011-03-10 14:16:55 -05:00
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@dnsimple_email)
|
|
|
|
end
|
|
|
|
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@dnsimple_email = options[:dnsimple_email]
|
|
|
|
@dnsimple_password = options[:dnsimple_password]
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
2011-05-24 16:43:08 -04:00
|
|
|
if options[:dnsimple_url]
|
|
|
|
uri = URI.parse(options[:dnsimple_url])
|
|
|
|
options[:host] = uri.host
|
|
|
|
options[:port] = uri.port
|
|
|
|
options[:scheme] = uri.scheme
|
|
|
|
end
|
2011-09-12 11:01:48 -04:00
|
|
|
@host = options[:host] || "dnsimple.com"
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:headers] ||= {}
|
|
|
|
key = "#{@dnsimple_email}:#{@dnsimple_password}"
|
2012-02-06 17:00:51 -05:00
|
|
|
params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).gsub("\n",''),
|
2011-02-23 22:35:05 -05:00
|
|
|
"Accept" => "application/json",
|
|
|
|
"Content-Type" => "application/json" })
|
|
|
|
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
|
|
|
|
|
|
|
unless response.body.empty?
|
2012-04-25 10:31:28 -04:00
|
|
|
response.body = Fog::JSON.decode(response.body)
|
2011-02-23 22:35:05 -05:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|