Class: DnsMadeEasy::Api::Client
- Inherits:
-
Object
- Object
- DnsMadeEasy::Api::Client
- Defined in:
- lib/dnsmadeeasy/api/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_a_record(domain_name, name, value, options = {}) ⇒ Object
Specific record types.
- #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_secondary_domain(domain_name, ip_set_id) ⇒ Object
- #create_secondary_domains(domain_names, ip_set_id) ⇒ Object
- #create_secondary_ip_set(name, ips) ⇒ 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
- #delete_secondary_domain(domain_name) ⇒ Object
- #delete_secondary_ip_set(ip_set_id) ⇒ Object
- #domain(domain_name) ⇒ Object
- #domains ⇒ Object
- #find_all(domain_name, name, type) ⇒ Object
- #find_first(domain_name, name, type) ⇒ Object
- #find_record_ids(domain_name, name, type) ⇒ Object
-
#get_id_by_domain(domain_name) ⇒ Object
———————————– ————- DOMAINS ————- ———————————–.
- #get_id_by_secondary_domain(domain_name) ⇒ Object
-
#initialize(api_key, api_secret, sandbox = false, options = {}) ⇒ Client
constructor
A new instance of Client.
- #on_production(&block) ⇒ Object
- #on_sandbox(&block) ⇒ Object
-
#records_for(domain_name) ⇒ Object
(also: #all)
———————————– ————- RECORDS ————- ———————————–.
- #secondary_domain(domain_id) ⇒ Object
-
#secondary_domains ⇒ Object
———————————– ——- Secondary Domains ——— ———————————–.
- #secondary_ip_set(ip_set_id) ⇒ Object
-
#secondary_ip_sets ⇒ Object
———————————– ——- Secondary IpSet ———– ———————————–.
- #update_record(domain, record_id, name, type, value, options = {}) ⇒ Object
- #update_records(domain, records, options = {}) ⇒ Object
- #update_secondary_domains(domain_ids, ip_set_id) ⇒ Object
- #update_secondary_ip_set(ip_set_id, name, ips) ⇒ Object
Constructor Details
#initialize(api_key, api_secret, sandbox = false, options = {}) ⇒ Client
Returns a new instance of Client.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dnsmadeeasy/api/client.rb', line 26 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 sandbox ? on_sandbox : on_production end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
21 22 23 |
# File 'lib/dnsmadeeasy/api/client.rb', line 21 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
21 22 23 |
# File 'lib/dnsmadeeasy/api/client.rb', line 21 def api_secret @api_secret end |
#base_uri ⇒ Object
Returns the value of attribute base_uri.
20 21 22 |
# File 'lib/dnsmadeeasy/api/client.rb', line 20 def base_uri @base_uri end |
#request_limit ⇒ Object (readonly)
Returns the value of attribute request_limit.
21 22 23 |
# File 'lib/dnsmadeeasy/api/client.rb', line 21 def request_limit @request_limit end |
#requests_remaining ⇒ Object (readonly)
Returns the value of attribute requests_remaining.
21 22 23 |
# File 'lib/dnsmadeeasy/api/client.rb', line 21 def requests_remaining @requests_remaining end |
Class Method Details
.public_operations ⇒ Object
15 16 17 |
# File 'lib/dnsmadeeasy/api/client.rb', line 15 def public_operations (new('a', 'b').methods - Object.methods).map(&:to_s).reject { |r| r =~ /[=]$|^(api_|on_|request)/ }.sort end |
Instance Method Details
#create_a_record(domain_name, name, value, options = {}) ⇒ Object
Specific record types
128 129 130 131 |
# File 'lib/dnsmadeeasy/api/client.rb', line 128 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
133 134 135 136 |
# File 'lib/dnsmadeeasy/api/client.rb', line 133 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
148 149 150 151 |
# File 'lib/dnsmadeeasy/api/client.rb', line 148 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
71 72 73 |
# File 'lib/dnsmadeeasy/api/client.rb', line 71 def create_domain(domain_name) create_domains([domain_name]) end |
#create_domains(names) ⇒ Object
67 68 69 |
# File 'lib/dnsmadeeasy/api/client.rb', line 67 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
172 173 174 175 |
# File 'lib/dnsmadeeasy/api/client.rb', line 172 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
162 163 164 165 166 |
# File 'lib/dnsmadeeasy/api/client.rb', line 162 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
153 154 155 156 |
# File 'lib/dnsmadeeasy/api/client.rb', line 153 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
138 139 140 141 |
# File 'lib/dnsmadeeasy/api/client.rb', line 138 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
121 122 123 124 |
# File 'lib/dnsmadeeasy/api/client.rb', line 121 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_domain(domain_name, ip_set_id) ⇒ Object
213 214 215 216 |
# File 'lib/dnsmadeeasy/api/client.rb', line 213 def create_secondary_domain(domain_name, ip_set_id) domains = [domain_name] create_secondary_domains(domains, ip_set_id) end |
#create_secondary_domains(domain_names, ip_set_id) ⇒ Object
208 209 210 211 |
# File 'lib/dnsmadeeasy/api/client.rb', line 208 def create_secondary_domains(domain_names, ip_set_id) body = { names: domain_names, ipSetId: ip_set_id } post '/dns/secondary', body end |
#create_secondary_ip_set(name, ips) ⇒ Object
248 249 250 251 |
# File 'lib/dnsmadeeasy/api/client.rb', line 248 def create_secondary_ip_set(name, ips) body = { name: name, ips: ips } post '/dns/secondary/ipSet', body end |
#create_spf_record(domain_name, name, value, options = {}) ⇒ Object
158 159 160 |
# File 'lib/dnsmadeeasy/api/client.rb', line 158 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
168 169 170 171 |
# File 'lib/dnsmadeeasy/api/client.rb', line 168 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
143 144 145 146 |
# File 'lib/dnsmadeeasy/api/client.rb', line 143 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
116 117 118 119 |
# File 'lib/dnsmadeeasy/api/client.rb', line 116 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
63 64 65 |
# File 'lib/dnsmadeeasy/api/client.rb', line 63 def delete_domain(domain_name) delete "/dns/managed/#{get_id_by_domain(domain_name)}" end |
#delete_record(domain_name, record_id) ⇒ Object
104 105 106 |
# File 'lib/dnsmadeeasy/api/client.rb', line 104 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
108 109 110 111 112 113 114 |
# File 'lib/dnsmadeeasy/api/client.rb', line 108 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_domain(domain_name) ⇒ Object
232 233 234 |
# File 'lib/dnsmadeeasy/api/client.rb', line 232 def delete_secondary_domain(domain_name) delete "/dns/secondary/#{get_id_by_secondary_domain(domain_name)}" end |
#delete_secondary_ip_set(ip_set_id) ⇒ Object
258 259 260 |
# File 'lib/dnsmadeeasy/api/client.rb', line 258 def delete_secondary_ip_set(ip_set_id) delete "/dns/secondary/ipSet/#{ip_set_id}" end |
#domain(domain_name) ⇒ Object
59 60 61 |
# File 'lib/dnsmadeeasy/api/client.rb', line 59 def domain(domain_name) get "/dns/managed/#{get_id_by_domain(domain_name)}" end |
#domains ⇒ Object
55 56 57 |
# File 'lib/dnsmadeeasy/api/client.rb', line 55 def domains get '/dns/managed/' end |
#find_all(domain_name, name, type) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/dnsmadeeasy/api/client.rb', line 85 def find_all(domain_name, name, type) records = records_for(domain_name) return nil unless records records['data'].select { |r| r['name'] == name && r['type'] == type } end |
#find_first(domain_name, name, type) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/dnsmadeeasy/api/client.rb', line 92 def find_first(domain_name, name, type) records = records_for(domain_name) return nil unless records records['data'].detect { |r| r['name'] == name && r['type'] == type } end |
#find_record_ids(domain_name, name, type) ⇒ Object
99 100 101 102 |
# File 'lib/dnsmadeeasy/api/client.rb', line 99 def find_record_ids(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_id_by_domain(domain_name) ⇒ Object
————- DOMAINS ————-
51 52 53 |
# File 'lib/dnsmadeeasy/api/client.rb', line 51 def get_id_by_domain(domain_name) get("/dns/managed/id/#{domain_name}")['id'] end |
#get_id_by_secondary_domain(domain_name) ⇒ Object
223 224 225 226 227 228 229 230 |
# File 'lib/dnsmadeeasy/api/client.rb', line 223 def get_id_by_secondary_domain(domain_name) domain_data = secondary_domains['data'].find do |domain| domain['name'] == domain_name end raise NoDomainError, "#{domain_name} does not exist" unless domain_data domain_data['id'] end |
#on_production(&block) ⇒ Object
43 44 45 |
# File 'lib/dnsmadeeasy/api/client.rb', line 43 def on_production(&block) with_url(::DnsMadeEasy::API_BASE_URL_PRODUCTION, &block) end |
#on_sandbox(&block) ⇒ Object
39 40 41 |
# File 'lib/dnsmadeeasy/api/client.rb', line 39 def on_sandbox(&block) with_url(::DnsMadeEasy::API_BASE_URL_SANDBOX, &block) end |
#records_for(domain_name) ⇒ Object Also known as: all
————- RECORDS ————-
79 80 81 |
# File 'lib/dnsmadeeasy/api/client.rb', line 79 def records_for(domain_name) get "/dns/managed/#{get_id_by_domain(domain_name)}/records" end |
#secondary_domain(domain_id) ⇒ Object
204 205 206 |
# File 'lib/dnsmadeeasy/api/client.rb', line 204 def secondary_domain(domain_id) get "/dns/secondary/#{domain_id}" end |
#secondary_domains ⇒ Object
——- Secondary Domains ———
200 201 202 |
# File 'lib/dnsmadeeasy/api/client.rb', line 200 def secondary_domains get '/dns/secondary' end |
#secondary_ip_set(ip_set_id) ⇒ Object
244 245 246 |
# File 'lib/dnsmadeeasy/api/client.rb', line 244 def secondary_ip_set(ip_set_id) get "/dns/secondary/ipSet/#{ip_set_id}" end |
#secondary_ip_sets ⇒ Object
——- Secondary IpSet ———–
240 241 242 |
# File 'lib/dnsmadeeasy/api/client.rb', line 240 def secondary_ip_sets get '/dns/secondary/ipSet' end |
#update_record(domain, record_id, name, type, value, options = {}) ⇒ Object
177 178 179 180 |
# File 'lib/dnsmadeeasy/api/client.rb', line 177 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
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/dnsmadeeasy/api/client.rb', line 182 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_domains(domain_ids, ip_set_id) ⇒ Object
218 219 220 221 |
# File 'lib/dnsmadeeasy/api/client.rb', line 218 def update_secondary_domains(domain_ids, ip_set_id) body = { ids: domain_ids, ipSetId: ip_set_id } put '/dns/secondary', body end |
#update_secondary_ip_set(ip_set_id, name, ips) ⇒ Object
253 254 255 256 |
# File 'lib/dnsmadeeasy/api/client.rb', line 253 def update_secondary_ip_set(ip_set_id, name, ips) body = { name: name, id: ip_set_id, ips: ips } put "/dns/secondary/ipSet/#{ip_set_id}", body end |