Class: Dynect

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

Instance Method Summary collapse

Constructor Details

#initialize(customer, user, password, driver = nil) ⇒ Dynect

Provide the customer, user, and password information to intiate the SOAP connection. If desired, an alternate driver can be supplied to enable mocking or the use of different protocols.



9
10
11
12
13
14
# File 'lib/dynect.rb', line 9

def initialize(customer, user, password, driver = nil)
  @driver = driver || setup_driver
  @creds = {"cust" => customer, "user" => user, "pass" => password }
  
  add_methods
end

Instance Method Details

#add_a_record(zone, address, options = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/dynect.rb', line 55

def add_a_record(zone, address, options = {})
  args = @creds.merge("type" => "A", "zone" => zone, "rdata" => {"address" => address})
  args.merge!(options)
  
  response = @driver.RecordAdd args
  check_for_errors("when adding an A record", response)
end

#add_cname_record(zone, hostname, options = {}) ⇒ Object

Adds a CNAME record for the specified zone



89
90
91
92
93
94
95
# File 'lib/dynect.rb', line 89

def add_cname_record(zone, hostname, options = {} )
  args = @creds.merge("type" => "CNAME", "zone" => zone, "rdata" => {"cname" => hostname})
  args.merge!(options)
  
  response = @driver.RecordAdd args
  check_for_errors("when adding a CNAME record", response)
end

#add_node(node, zone, options = {}) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/dynect.rb', line 135

def add_node(node, zone, options ={})
  args = @creds.merge("zone" => zone, "node" => "#{node}.#{zone}")
  args.merge!(options)
  
  response = @driver.NodeAdd args
  check_for_errors("when adding a node", response)
end

#create_zone(zone, type, options = {}) ⇒ Object

Create a new zone



27
28
29
30
31
32
33
# File 'lib/dynect.rb', line 27

def create_zone(zone, type, options ={})
  args = @creds.merge("zone" => zone, "type" => type)
  args.merge!(options)
  
  response = @driver.ZoneAdd args
  check_for_errors("when creating a zone", response)
end

#delete_a_record(id) ⇒ Object

Deletes an A record identified by the ID



73
74
75
76
# File 'lib/dynect.rb', line 73

def delete_a_record(id)
  response = @driver.RecordDelete @creds.merge("record_id" => id)
  check_for_errors("when removing an A record", response)
end

#delete_cname_record(id) ⇒ Object



105
106
107
108
# File 'lib/dynect.rb', line 105

def delete_cname_record(id)
  response = @driver.RecordDelete @creds.merge("record_id" => id)
  check_for_errors("when removing a CNAME record", response)
end

#delete_node(node, zone, options = {}) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/dynect.rb', line 143

def delete_node(node, zone, options ={})
  args = @creds.merge("zone" => zone, "node" => "#{node}.#{zone}")
  args.merge!(options)
  
  response = @driver.NodeDelete args
  check_for_errors("when deleting a node", response)
end

#list_a_records(zone, options = {}) ⇒ Object

Lists all the A records associated with the account.

Options

  • node – The fully qualified domain name of the node to retreive records from. Omit or enter an empty string to get the records of the root node

  • record_id – The ID of the record to retreive information of

Useage

d = Dynect.new("customer", "username", "password")
d.list_a_records("myzone.domain.com")


46
47
48
49
50
51
52
53
# File 'lib/dynect.rb', line 46

def list_a_records(zone, options ={})
  args = @creds.merge("type" => "A", "zone" => zone)
  args.merge!(options)
  
  response = @driver.RecordGet args
  check_for_errors("when listing records", response)
  response.records
end

#list_cname_records(zone, options = {}) ⇒ Object

Lists the CNAME records associated with an account



79
80
81
82
83
84
85
86
# File 'lib/dynect.rb', line 79

def list_cname_records(zone, options ={})
  args = @creds.merge("type" => "CNAME", "zone" => zone)
  args.merge!(options)
  
  response = @driver.RecordGet args
  check_for_errors("when listing CNAME records", response)
  response.records
end

#list_nodes(zone, options = {}) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/dynect.rb', line 127

def list_nodes(zone, options = {})
  args = @creds.merge("zone" => zone)
  args.merge!(options)
  
  response = @driver.NodeGet args
  check_for_errors("when listing nodes", response)
end

#list_soa(zone, options = {}) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/dynect.rb', line 118

def list_soa(zone, options = {})
  args = @creds.merge("type" => "SOA", "zone" => zone)
  args.merge!(options)
  
  response = @driver.RecordGet args
  check_for_errors("when listing SOA records", response)
  response.records.first
end

#list_zones(zone = nil) ⇒ Object

Lists the zones associated with the accout. Specify a zone to get information on a specific one



17
18
19
20
21
22
23
24
# File 'lib/dynect.rb', line 17

def list_zones(zone = nil)
  args = @creds
  args["zone"] = zone if zone
  
  response = @driver.ZoneGet args
  check_for_errors("when listing zone(s)", response)
  response.zones
end

#update_a_record(id, options = {}) ⇒ Object

Updates A records identified by the ID



64
65
66
67
68
69
70
# File 'lib/dynect.rb', line 64

def update_a_record(id, options = {})
  args = @creds.merge("record_id" => id)
  args.merge!(options)
  
  response = @driver.RecordUpdate args
  check_for_errors("when updating an A record", response)
end

#update_cname_record(id, options = {}) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/dynect.rb', line 97

def update_cname_record(id, options = {})
  args = @creds.merge("id" => id)
  args.merge!(options)
  
  response = @driver.RecordUpdate args
  check_for_errors("when updating a CNAME record", response)
end

#update_soa(id, options = {}) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/dynect.rb', line 110

def update_soa(id, options = {})
  args = @creds.merge("record_id" => id)
  args.merge!(options)
  
  response = @driver.RecordUpdate args
  check_for_errors("when updating a SOA record", response)
end