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_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_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_record(domain_name, record_id) ⇒ Object
- #delete_records(domain_name, ids = []) ⇒ 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.
-
#records_for(domain_name) ⇒ Object
———————————– ————- RECORDS ————- ———————————–.
- #update_failover_config(record_id, ips, desc, protocol = 'TCP', options = {}) ⇒ Object
- #update_record(domain, record_id, name, type, value, options = {}) ⇒ Object
- #update_records(domain, records, options = {}) ⇒ Object
Constructor Details
#initialize(api_key, api_secret, sandbox = false, options = {}) ⇒ DnsMadeEasy
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 13 def initialize(api_key, api_secret, sandbox = false, = {}) fail 'api_key is undefined' unless api_key fail 'api_secret is undefined' unless api_secret @api_key = api_key @api_secret = api_secret = @requests_remaining = -1 @request_limit = -1 if sandbox self.base_uri = 'https://api.sandbox.dnsmadeeasy.com/V2.0' else self.base_uri = 'https://api.dnsmadeeasy.com/V2.0' end end |
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
9 10 11 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 9 def base_uri @base_uri end |
#request_limit ⇒ Object (readonly)
Returns the value of attribute request_limit.
11 12 13 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 11 def request_limit @request_limit end |
#requests_remaining ⇒ Object (readonly)
Returns the value of attribute requests_remaining.
10 11 12 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 10 def requests_remaining @requests_remaining end |
Instance Method Details
#create_a_record(domain_name, name, value, options = {}) ⇒ Object
98 99 100 101 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 98 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
103 104 105 106 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 103 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
118 119 120 121 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 118 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
54 55 56 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 54 def create_domain(domain_name) create_domains([domain_name]) end |
#create_domains(names) ⇒ Object
50 51 52 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 50 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
143 144 145 146 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 143 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_mx_record(domain_name, name, priority, value, options = {}) ⇒ Object
132 133 134 135 136 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 132 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
123 124 125 126 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 123 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
108 109 110 111 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 108 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
93 94 95 96 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 93 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_spf_record(domain_name, name, value, options = {}) ⇒ Object
128 129 130 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 128 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
138 139 140 141 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 138 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
113 114 115 116 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 113 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
88 89 90 91 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 88 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
46 47 48 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 46 def delete_domain(domain_name) delete "/dns/managed/#{get_id_by_domain(domain_name)}" end |
#delete_record(domain_name, record_id) ⇒ Object
77 78 79 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 77 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
81 82 83 84 85 86 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 81 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 |
#disable_failover(record_id, options = {}) ⇒ Object
209 210 211 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 209 def disable_failover(record_id, ={}) put "/monitor/#{record_id}", { 'failover' => false, 'monitor' => false }.merge() end |
#domain(domain_name) ⇒ Object
42 43 44 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 42 def domain(domain_name) get "/dns/managed/#{get_id_by_domain(domain_name)}" end |
#domains ⇒ Object
38 39 40 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 38 def domains get '/dns/managed/' end |
#find(domain_name, name, type) ⇒ Object
66 67 68 69 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 66 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
71 72 73 74 75 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 71 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 ————-
171 172 173 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 171 def get_failover_config(record_id) get "/monitor/#{record_id}" end |
#get_id_by_domain(domain_name) ⇒ Object
————- DOMAINS ————-
34 35 36 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 34 def get_id_by_domain(domain_name) get("/dns/managed/id/#{domain_name}")['id'] end |
#records_for(domain_name) ⇒ Object
————- RECORDS ————-
62 63 64 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 62 def records_for(domain_name) get "/dns/managed/#{get_id_by_domain(domain_name)}/records" end |
#update_failover_config(record_id, ips, desc, protocol = 'TCP', options = {}) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 175 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_record(domain, record_id, name, type, value, options = {}) ⇒ Object
148 149 150 151 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 148 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
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/dnsmadeeasy-rest-api.rb', line 153 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 |