Class: DnsMadeEasy
- Inherits:
-
Object
- Object
- DnsMadeEasy
- Defined in:
- lib/dnsmadeeasy-rest-api.rb
Overview
A class to interact with the DNSMadeEasy REST API v2.0
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#request_limit ⇒ Object
readonly
Returns the value of attribute request_limit.
-
#requests_remaining ⇒ Object
readonly
Returns the value of attribute requests_remaining.
Instance Method Summary collapse
- #create_a_record(domain_name, name, value, options = {}) ⇒ Object
- #create_aaaa_record(domain_name, name, value, options = {}) ⇒ Object
- #create_cname_record(domain_name, name, value, options = {}) ⇒ Object
- #create_domain(domain_name) ⇒ Object
- #create_domains(names) ⇒ Object
- #create_httpred_record(domain_name, name, value, redirectType = 'STANDARD - 302', description = '', keywords = '', title = '', options = {}) ⇒ Object
- #create_ip_set(name, ips = []) ⇒ Object
- #create_mx_record(domain_name, name, priority, value, options = {}) ⇒ Object
- #create_ns_record(domain_name, name, value, options = {}) ⇒ Object
- #create_ptr_record(domain_name, name, value, options = {}) ⇒ Object
- #create_record(domain_name, name, type, value, options = {}) ⇒ Object
- #create_secondary(names = [], ipSetId) ⇒ Object
- #create_spf_record(domain_name, name, value, options = {}) ⇒ Object
- #create_srv_record(domain_name, name, priority, weight, port, value, options = {}) ⇒ Object
- #create_txt_record(domain_name, name, value, options = {}) ⇒ Object
- #delete_all_records(domain_name) ⇒ Object
- #delete_domain(domain_name) ⇒ Object
- #delete_ip_set(id) ⇒ Object
- #delete_record(domain_name, record_id) ⇒ Object
- #delete_records(domain_name, ids = []) ⇒ Object
- #delete_secondary(id) ⇒ Object
- #disable_failover(record_id, options = {}) ⇒ Object
- #domain(domain_name) ⇒ Object
- #domains ⇒ Object
- #find(domain_name, name, type) ⇒ Object
- #find_record_id(domain_name, name, type) ⇒ Object
-
#get_failover_config(record_id) ⇒ Object
———————————– ————- FAILOVER ————- ———————————–.
-
#get_id_by_domain(domain_name) ⇒ Object
———————————– ————- DOMAINS ————- ———————————–.
-
#initialize(api_key, api_secret, sandbox = false, options = {}) ⇒ DnsMadeEasy
constructor
A new instance of DnsMadeEasy.
- #ip_set(id) ⇒ Object
-
#ip_sets ⇒ Object
———————————– ————- IP SETS ————- ———————————–.
-
#records_for(domain_name) ⇒ Object
———————————– ————- RECORDS ————- ———————————–.
- #secondary(id) ⇒ Object
-
#secondarys ⇒ Object
———————————– ——– SECONDARY DOMAINS ——– ———————————–.
- #update_failover_config(record_id, ips, desc, protocol = 'TCP', options = {}) ⇒ Object
- #update_ip_set(id, name, ips = []) ⇒ Object
- #update_record(domain, record_id, name, type, value, options = {}) ⇒ Object
- #update_records(domain, records, options = {}) ⇒ Object
- #update_secondary(ids = [], ipSetId) ⇒ Object
Constructor Details
#initialize(api_key, api_secret, sandbox = false, options = {}) ⇒ DnsMadeEasy
Returns a new instance of DnsMadeEasy.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 15 def initialize(api_key, api_secret, sandbox = false, = {}) raise 'api_key is undefined' unless api_key raise 'api_secret is undefined' unless api_secret @api_key = api_key @api_secret = api_secret @options = @requests_remaining = -1 @request_limit = -1 self.base_uri = if sandbox 'https://api.sandbox.dnsmadeeasy.com/V2.0' else 'https://api.dnsmadeeasy.com/V2.0' end end |
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
11 12 13 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 11 def base_uri @base_uri end |
#request_limit ⇒ Object (readonly)
Returns the value of attribute request_limit.
13 14 15 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 13 def request_limit @request_limit end |
#requests_remaining ⇒ Object (readonly)
Returns the value of attribute requests_remaining.
12 13 14 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 12 def requests_remaining @requests_remaining end |
Instance Method Details
#create_a_record(domain_name, name, value, options = {}) ⇒ Object
149 150 151 152 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 149 def create_a_record(domain_name, name, value, = {}) # TODO: match IPv4 for value create_record domain_name, name, 'A', value, end |
#create_aaaa_record(domain_name, name, value, options = {}) ⇒ Object
154 155 156 157 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 154 def create_aaaa_record(domain_name, name, value, = {}) # TODO: match IPv6 for value create_record domain_name, name, 'AAAA', value, end |
#create_cname_record(domain_name, name, value, options = {}) ⇒ Object
169 170 171 172 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 169 def create_cname_record(domain_name, name, value, = {}) # TODO: match CNAME value create_record domain_name, name, 'CNAME', value, end |
#create_domain(domain_name) ⇒ Object
56 57 58 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 56 def create_domain(domain_name) create_domains([domain_name]) end |
#create_domains(names) ⇒ Object
52 53 54 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 52 def create_domains(names) post('/dns/managed/', names: names) end |
#create_httpred_record(domain_name, name, value, redirectType = 'STANDARD - 302', description = '', keywords = '', title = '', options = {}) ⇒ Object
194 195 196 197 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 194 def create_httpred_record(domain_name, name, value, redirectType = 'STANDARD - 302', description = '', keywords = '', title = '', = {}) .merge!('redirectType' => redirectType, 'description' => description, 'keywords' => keywords, 'title' => title) create_record domain_name, name, 'HTTPRED', value, end |
#create_ip_set(name, ips = []) ⇒ Object
100 101 102 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 100 def create_ip_set(name, ips = []) post('/dns/secondary/ipSet', 'name' => name, 'ips' => ips) end |
#create_mx_record(domain_name, name, priority, value, options = {}) ⇒ Object
183 184 185 186 187 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 183 def create_mx_record(domain_name, name, priority, value, = {}) .merge!('mxLevel' => priority) create_record domain_name, name, 'MX', value, end |
#create_ns_record(domain_name, name, value, options = {}) ⇒ Object
174 175 176 177 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 174 def create_ns_record(domain_name, name, value, = {}) # TODO: match domainname for value create_record domain_name, name, 'NS', value, end |
#create_ptr_record(domain_name, name, value, options = {}) ⇒ Object
159 160 161 162 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 159 def create_ptr_record(domain_name, name, value, = {}) # TODO: match PTR value create_record domain_name, name, 'PTR', value, end |
#create_record(domain_name, name, type, value, options = {}) ⇒ Object
144 145 146 147 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 144 def create_record(domain_name, name, type, value, = {}) body = { 'name' => name, 'type' => type, 'value' => value, 'ttl' => 3600, 'gtdLocation' => 'DEFAULT' } post "/dns/managed/#{get_id_by_domain(domain_name)}/records/", body.merge() end |
#create_secondary(names = [], ipSetId) ⇒ Object
76 77 78 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 76 def create_secondary(names = [], ipSetId) post('/dns/secondary/', "names": names, 'ipSetId' => ipSetId) end |
#create_spf_record(domain_name, name, value, options = {}) ⇒ Object
179 180 181 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 179 def create_spf_record(domain_name, name, value, = {}) create_record domain_name, name, 'SPF', value, end |
#create_srv_record(domain_name, name, priority, weight, port, value, options = {}) ⇒ Object
189 190 191 192 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 189 def create_srv_record(domain_name, name, priority, weight, port, value, = {}) .merge!('priority' => priority, 'weight' => weight, 'port' => port) create_record domain_name, name, 'SRV', value, end |
#create_txt_record(domain_name, name, value, options = {}) ⇒ Object
164 165 166 167 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 164 def create_txt_record(domain_name, name, value, = {}) # TODO: match TXT value create_record domain_name, name, 'TXT', value, end |
#delete_all_records(domain_name) ⇒ Object
139 140 141 142 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 139 def delete_all_records(domain_name) domain_id = get_id_by_domain(domain_name) delete "/dns/managed/#{domain_id}/records" end |
#delete_domain(domain_name) ⇒ Object
48 49 50 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 48 def delete_domain(domain_name) delete "/dns/managed/#{get_id_by_domain(domain_name)}" end |
#delete_ip_set(id) ⇒ Object
104 105 106 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 104 def delete_ip_set(id) delete("/dns/secondary/ipSet/#{id}") end |
#delete_record(domain_name, record_id) ⇒ Object
127 128 129 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 127 def delete_record(domain_name, record_id) delete "/dns/managed/#{get_id_by_domain(domain_name)}/records/#{record_id}/" end |
#delete_records(domain_name, ids = []) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 131 def delete_records(domain_name, ids = []) return if ids.empty? domain_id = get_id_by_domain(domain_name) delete "/dns/managed/#{domain_id}/records?ids=#{ids.join(',')}" end |
#delete_secondary(id) ⇒ Object
80 81 82 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 80 def delete_secondary(id) delete("/dns/secondary/#{id}") end |
#disable_failover(record_id, options = {}) ⇒ Object
260 261 262 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 260 def disable_failover(record_id, = {}) put "/monitor/#{record_id}", { 'failover' => false, 'monitor' => false }.merge() end |
#domain(domain_name) ⇒ Object
44 45 46 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 44 def domain(domain_name) get "/dns/managed/#{get_id_by_domain(domain_name)}" end |
#domains ⇒ Object
40 41 42 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 40 def domains get '/dns/managed/' end |
#find(domain_name, name, type) ⇒ Object
116 117 118 119 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 116 def find(domain_name, name, type) records = records_for(domain_name) records['data'].detect { |r| r['name'] == name && r['type'] == type } end |
#find_record_id(domain_name, name, type) ⇒ Object
121 122 123 124 125 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 121 def find_record_id(domain_name, name, type) records = records_for(domain_name) records['data'].select { |r| r['name'] == name && r['type'] == type }.map { |r| r['id'] } end |
#get_failover_config(record_id) ⇒ Object
————- FAILOVER ————-
222 223 224 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 222 def get_failover_config(record_id) get "/monitor/#{record_id}" end |
#get_id_by_domain(domain_name) ⇒ Object
————- DOMAINS ————-
36 37 38 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 36 def get_id_by_domain(domain_name) get("/dns/managed/id/#{domain_name}")['id'] end |
#ip_set(id) ⇒ Object
92 93 94 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 92 def ip_set(id) get "/dns/secondary/ipSet/#{id}" end |
#ip_sets ⇒ Object
————- IP SETS ————-
88 89 90 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 88 def ip_sets get '/dns/secondary/ipSet' end |
#records_for(domain_name) ⇒ Object
————- RECORDS ————-
112 113 114 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 112 def records_for(domain_name) get "/dns/managed/#{get_id_by_domain(domain_name)}/records" end |
#secondary(id) ⇒ Object
68 69 70 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 68 def secondary(id) get "/dns/secondary/#{id}" end |
#secondarys ⇒ Object
——– SECONDARY DOMAINS ——–
64 65 66 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 64 def secondarys get '/dns/secondary' end |
#update_failover_config(record_id, ips, desc, protocol = 'TCP', options = {}) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 226 def update_failover_config(record_id, ips, desc, protocol = 'TCP', = {}) protocolIds = { 'TCP' => 1, 'UDP' => 2, 'HTTP' => 3, 'DNS' => 4, 'SMTP' => 5, 'HTTPS' => 6 } body = { 'protocolId' => protocolIds[protocol], 'port' => 80, 'systemDescription' => desc, 'sensitivity' => 5, 'failover' => true, 'monitor' => false, 'maxEmails' => 1, 'autoFailover' => false, 'source' => 1 } body = body.merge() ip_config = {} (0..ips.length - 1).each do |idx| ip_config["ip#{idx + 1}"] = ips[idx] end body = body.merge(ip_config) put "/monitor/#{record_id}", body end |
#update_ip_set(id, name, ips = []) ⇒ Object
96 97 98 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 96 def update_ip_set(id, name, ips = []) put("/dns/secondary/ipSet/#{id}", 'name' => name, 'id' => id, 'ips' => ips) end |
#update_record(domain, record_id, name, type, value, options = {}) ⇒ Object
199 200 201 202 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 199 def update_record(domain, record_id, name, type, value, = {}) body = { 'name' => name, 'type' => type, 'value' => value, 'ttl' => 3600, 'gtdLocation' => 'DEFAULT', 'id' => record_id } put "/dns/managed/#{get_id_by_domain(domain)}/records/#{record_id}/", body.merge() end |
#update_records(domain, records, options = {}) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 204 def update_records(domain, records, = {}) body = records.map do |record| { 'id' => record['id'], 'name' => record['name'], 'type' => record['type'], 'value' => record['value'], 'gtdLocation' => record['gtdLocation'], 'ttl' => record['ttl'] }.merge() end put "/dns/managed/#{get_id_by_domain(domain)}/records/updateMulti/", body end |
#update_secondary(ids = [], ipSetId) ⇒ Object
72 73 74 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 72 def update_secondary(ids = [], ipSetId) put('/dns/secondary/', 'ids' => ids, 'ipSetId' => ipSetId) end |