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/dynect/dns.rb

81 lines
2.3 KiB
Ruby
Raw Normal View History

module Fog
module DNS
class Dynect < Fog::Service
requires :dynect_customer, :dynect_username, :dynect_password
recognizes :timeout, :persistent
recognizes :provider # remove post deprecation
model_path 'fog/dynect/models/dns'
2011-06-16 17:51:13 -04:00
model :record
collection :records
model :zone
collection :zones
request_path 'fog/dynect/requests/dns'
request :delete_record
request :delete_zone
request :get_node_list
request :get_record
2011-06-17 06:51:37 -04:00
request :get_zone
request :post_record
request :post_session
request :post_zone
request :put_zone
class Mock
def initialize(options={})
@dynect_customer = options[:dynect_customer]
@dynect_username = options[:dynect_username]
@dynect_password = options[:dynect_password]
end
end
class Real
def initialize(options={})
require 'multi_json'
2011-06-15 12:38:26 -04:00
@dynect_customer = options[:dynect_customer]
@dynect_username = options[:dynect_username]
@dynect_password = options[:dynect_password]
2011-02-08 21:31:24 -05:00
@host = "api2.dynect.net"
@port = options[:port] || 443
@path = options[:path] || '/REST'
@scheme = options[:scheme] || 'https'
@version = options[:version] || '2.3.1'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent] || true)
end
2011-02-08 21:47:44 -05:00
def auth_token
@auth_token ||= post_session.body['data']['token']
2011-02-08 21:47:44 -05:00
end
def request(params)
begin
params[:headers] ||= {}
params[:headers]['Content-Type'] = 'application/json'
params[:headers]['API-Version'] = @version
2011-02-08 21:47:44 -05:00
params[:headers]['Auth-Token'] = auth_token unless params[:path] == "Session"
2011-02-08 21:31:24 -05:00
params[:path] = "#{@path}/#{params[:path]}"
response = @connection.request(params.merge!({:host => @host}))
unless response.body.empty?
response.body = MultiJson.decode(response.body)
end
response
rescue Excon::Errors::HTTPStatusError => error
2011-02-08 21:47:44 -05:00
raise error
end
response
end
end
end
end
end