class DME

Public Class Methods

new(api_key, secret_key, domain) click to toggle source
# File lib/dme-api.rb, line 12
def initialize(api_key, secret_key, domain)

  @@dme_rest_url = "http://api.dnsmadeeasy.com/V1.2/domains/"

  @api_key = api_key
  @secret_key = secret_key
  @domain = domain
end

Public Instance Methods

create(record) click to toggle source
# File lib/dme-api.rb, line 28
def create(record)
  response = RestClient.post get_url(),
                          record.to_json,
                          get_headers(:"content-type" => :json)
  JSON.parse(response)
end
delete(id) click to toggle source
# File lib/dme-api.rb, line 35
def delete(id)
  response = RestClient.delete get_url(id), get_headers()
end
get(name) click to toggle source
# File lib/dme-api.rb, line 21
def get(name)
  response = RestClient.get(get_url(), get_headers())

  # find the record we want
  JSON.parse(response.to_str).select { |x| x["name"] == name }.first
end

Private Instance Methods

get_headers(additional_headers = {}) click to toggle source
# File lib/dme-api.rb, line 50
def get_headers(additional_headers = {})
  t = Time.now.httpdate
  hmac = OpenSSL::HMAC.hexdigest('sha1', @secret_key, t)
  {
    :"x-dnsme-apiKey"      => @api_key,
    :"x-dnsme-hmac"        => hmac,
    :"x-dnsme-requestDate" => t,
    :accept                =>:json
  }.merge(additional_headers)
end
get_url(id = nil) click to toggle source
# File lib/dme-api.rb, line 42
def get_url(id = nil)
  u = @@dme_rest_url + @domain + "/records"
  if not id.nil? then
    u += "/#{id}"
  end
  return u
end