class Hover::Api

Constants

AUTH_URL
URL

Attributes

client[RW]
password[RW]
username[RW]

Public Class Methods

new(username, password) click to toggle source
# File lib/hover/api.rb, line 11
def initialize(username, password)
  self.username = username
  self.password = password

  session = authenticate(username, password)
  self.client = RestClient::Resource.new(URL, :cookies => {:hoverauth => session})
end

Public Instance Methods

authenticate(username, password) click to toggle source
# File lib/hover/api.rb, line 19
def authenticate(username, password)
  auth = {username: username, password: password}
  RestClient.post(AUTH_URL, auth) do |response, request, result|
    if [302,200].include?(response.code)
      return response.cookies["hoverauth"]
    else
      raise "Failed to authenticate"
    end
  end
end
create_record(id, name, type, content) click to toggle source
# File lib/hover/api.rb, line 50
def create_record(id, name, type, content)
  params = {:name => name, :type => type, :content => content}
  response = post("domains/#{id}/dns", params)
  JSON.parse(response)
end
dns(params = {}) click to toggle source
# File lib/hover/api.rb, line 35
def dns(params = {})
  response = get("dns", params)
  JSON.parse(response)["domains"]
end
domain(id, params={}) click to toggle source
# File lib/hover/api.rb, line 40
def domain(id, params={})
  response = get("domains/#{id}", params)
  JSON.parse(response)["domain"]
end
domain_dns(id, params={}) click to toggle source
# File lib/hover/api.rb, line 45
def domain_dns(id, params={})
  response = get("domains/#{id}/dns", params)
  JSON.parse(response)["domains"].first["entries"]
end
domains(params = {}) click to toggle source
# File lib/hover/api.rb, line 30
def domains(params = {})
  response = get("domains", params)
  JSON.parse(response)["domains"]
end
update_record(id, params={}) click to toggle source
# File lib/hover/api.rb, line 56
def update_record(id, params={})
  response = put("dns/#{id}", params)
  JSON.parse(response)
end