1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/dnsimple/dns.rb

93 lines
2.5 KiB
Ruby
Raw Normal View History

module Fog
module DNS
class DNSimple < Fog::Service
requires :dnsimple_email, :dnsimple_password
recognizes :dnsimple_url, :host, :path, :port, :scheme, :persistent
model_path 'fog/dnsimple/models/dns'
2011-02-24 20:14:50 -05:00
model :record
collection :records
model :zone
collection :zones
request_path 'fog/dnsimple/requests/dns'
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
request :get_record
class Mock
2011-02-24 20:14:50 -05:00
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end
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
def reset_data
self.class.data.delete(@dnsimple_email)
end
end
class Real
def initialize(options={})
2011-07-15 22:34:16 -04:00
require 'multi_json'
@dnsimple_email = options[:dnsimple_email]
@dnsimple_password = options[:dnsimple_password]
if options[:dnsimple_url]
uri = URI.parse(options[:dnsimple_url])
options[:host] = uri.host
options[:port] = uri.port
options[:scheme] = uri.scheme
end
2011-02-25 00:15:44 -05:00
@host = options[:host] || "dnsimple.com"
@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])
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?
2011-07-20 12:08:11 -04:00
response.body = MultiJson.decode(response.body)
end
response
end
end
end
end
end