Class: Designate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/designate/client.rb

Direct Known Subclasses

Host, Template, Zone

Constant Summary collapse

API_VERSION =
"1.1"
DOMAIN =
"ns.zerigo.com"

Instance Method Summary collapse

Constructor Details

#initialize(email, key) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/designate/client.rb', line 9

def initialize(email, key)
  @@auth_string = CGI.escape(email) + ':' + CGI.escape(key)
end

Instance Method Details

#create_zone(domain, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/designate/client.rb', line 31

def create_zone(domain, options = {})
  options[:domain] = domain
  options[:default_ttl] ||= 14400
  options[:nx_ttl] ||= 900
  if options[:zone_template_id]
    options[:follow_template] ||= 'no'
  end
  if zone = post("zones.xml", { :zone => options })['zone']
    Zone.new(zone)
  end
end

#find_or_create_zone(domain) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/designate/client.rb', line 43

def find_or_create_zone(domain)
  if zone = find_zone_by_domain(domain)
    return zone
  else
    create_zone(domain)
  end
end

#find_template_by_id(id) ⇒ Object



57
58
59
60
61
# File 'lib/designate/client.rb', line 57

def find_template_by_id(id)
  if template = get("zone_templates/#{id}.xml")['zone_template']
    Template.new(template)
  end
end

#find_zone_by_domain(domain) ⇒ Object



25
26
27
28
29
# File 'lib/designate/client.rb', line 25

def find_zone_by_domain(domain)
  if zone = get("zones/#{domain}.xml")['zone']
    Zone.new(zone)
  end
end

#find_zone_by_id(id) ⇒ Object



19
20
21
22
23
# File 'lib/designate/client.rb', line 19

def find_zone_by_id(id)
  if zone = get("zones/#{id}.xml")['zone']
    Zone.new(zone)
  end
end

#templatesObject



51
52
53
54
55
# File 'lib/designate/client.rb', line 51

def templates
  templates = []
  get('zone_templates.xml')['zone_templates'].each { |template| templates << Template.new(template) }
  return templates
end

#zonesObject



13
14
15
16
17
# File 'lib/designate/client.rb', line 13

def zones
  zones = []
  get('zones.xml')['zones'].each { |zone| zones << Zone.new(zone) }
  return zones
end