Class: DnsMadeEasy

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsmadeeasy-rest-api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, sandbox = false) ⇒ DnsMadeEasy

Returns a new instance of DnsMadeEasy.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dnsmadeeasy-rest-api.rb', line 11

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

  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_uriObject

Returns the value of attribute base_uri.



9
10
11
# File 'lib/dnsmadeeasy-rest-api.rb', line 9

def base_uri
  @base_uri
end

Instance Method Details

#create_a_record(domain_name, name, value, options = {}) ⇒ Object



83
84
85
86
# File 'lib/dnsmadeeasy-rest-api.rb', line 83

def create_a_record(domain_name, name, value, options = {})
  # todo: match IPv4 for value
  create_record domain_name, name, "A", value, options
end

#create_aaaa_record(domain_name, name, value, options = {}) ⇒ Object



88
89
90
91
# File 'lib/dnsmadeeasy-rest-api.rb', line 88

def create_aaaa_record(domain_name, name, value, options = {})
  # todo: match IPv6 for value
  create_record domain_name, name, "AAAA", value, options
end

#create_cname_record(domain_name, name, value, options = {}) ⇒ Object



103
104
105
106
# File 'lib/dnsmadeeasy-rest-api.rb', line 103

def create_cname_record(domain_name, name, value, options = {})
  # todo: match CNAME value
  create_record domain_name, name, "CNAME", value, options
end

#create_domain(domain_name) ⇒ Object



49
50
51
# File 'lib/dnsmadeeasy-rest-api.rb', line 49

def create_domain(domain_name)
  create_domains([domain_name])
end

#create_domains(names) ⇒ Object



45
46
47
# File 'lib/dnsmadeeasy-rest-api.rb', line 45

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



128
129
130
131
# File 'lib/dnsmadeeasy-rest-api.rb', line 128

def create_httpred_record(domain_name, name, value, redirectType = "STANDARD - 302", description = "", keywords = "", title = "", options = {})
  options.merge!({"redirectType" => redirectType, "description" => description, "keywords" => keywords, "title" => title})
  create_record domain_name, name, "HTTPRED", value, options
end

#create_mx_record(domain_name, name, priority, value, options = {}) ⇒ Object



117
118
119
120
121
# File 'lib/dnsmadeeasy-rest-api.rb', line 117

def create_mx_record(domain_name, name, priority, value, options = {})
  options.merge!({"mxLevel" => priority})

  create_record domain_name, name, "MX", value, options
end

#create_ns_record(domain_name, name, value, options = {}) ⇒ Object



108
109
110
111
# File 'lib/dnsmadeeasy-rest-api.rb', line 108

def create_ns_record(domain_name, name, value, options = {})
  # todo: match domainname for value
  create_record domain_name, name, "NS", value, options
end

#create_ptr_record(domain_name, name, value, options = {}) ⇒ Object



93
94
95
96
# File 'lib/dnsmadeeasy-rest-api.rb', line 93

def create_ptr_record(domain_name, name, value, options = {})
  # todo: match PTR value
  create_record domain_name, name, "PTR", value, options
end

#create_record(domain_name, name, type, value, options = {}) ⇒ Object



78
79
80
81
# File 'lib/dnsmadeeasy-rest-api.rb', line 78

def create_record(domain_name, name, type, value, options = {})
  body = {"name" => name, "type" => type, "value" => value, "ttl" => 3600, "gtdLocation" => "DEFAULT"}
  post "/dns/managed/#{get_id_by_domain(domain_name)}/records/", body.merge(options)
end

#create_spf_record(domain_name, name, value, options = {}) ⇒ Object



113
114
115
# File 'lib/dnsmadeeasy-rest-api.rb', line 113

def create_spf_record(domain_name, name, value, options = {})
  create_record domain_name, name, "SPF", value, options
end

#create_srv_record(domain_name, name, priority, weight, port, value, options = {}) ⇒ Object



123
124
125
126
# File 'lib/dnsmadeeasy-rest-api.rb', line 123

def create_srv_record(domain_name, name, priority, weight, port, value, options = {})
  options.merge!({"priority" => priority, "weight" => weight, "port" => port})
  create_record domain_name, name, "SRV", value, options
end

#create_txt_record(domain_name, name, value, options = {}) ⇒ Object



98
99
100
101
# File 'lib/dnsmadeeasy-rest-api.rb', line 98

def create_txt_record(domain_name, name, value, options = {})
  # todo: match TXT value
  create_record domain_name, name, "TXT", value, options
end

#delete_domain(domain_name) ⇒ Object



41
42
43
# File 'lib/dnsmadeeasy-rest-api.rb', line 41

def delete_domain(domain_name)
  delete "/dns/managed/#{get_id_by_domain(domain_name)}"
end

#delete_record(domain_name, record_id) ⇒ Object



74
75
76
# File 'lib/dnsmadeeasy-rest-api.rb', line 74

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



68
69
70
71
72
# File 'lib/dnsmadeeasy-rest-api.rb', line 68

def delete_records(domain_name, ids = [])
  id = get_id_by_domain(domain_name)

  delete "/dns/managed/#{id}/records/", ids
end

#domain(domain_name) ⇒ Object



37
38
39
# File 'lib/dnsmadeeasy-rest-api.rb', line 37

def domain(domain_name)
  get "/dns/managed/#{get_id_by_domain(domain_name)}"
end

#domainsObject



33
34
35
# File 'lib/dnsmadeeasy-rest-api.rb', line 33

def domains
  get '/dns/managed/'
end

#find_record_id(domain_name, name, type) ⇒ Object



61
62
63
64
65
66
# File 'lib/dnsmadeeasy-rest-api.rb', line 61

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_id_by_domain(domain_name) ⇒ Object


————- DOMAINS ————-




29
30
31
# File 'lib/dnsmadeeasy-rest-api.rb', line 29

def get_id_by_domain(domain_name)
  get("/dns/managed/id/#{domain_name}")['id']
end

#records_for(domain_name) ⇒ Object


————- RECORDS ————-




57
58
59
# File 'lib/dnsmadeeasy-rest-api.rb', line 57

def records_for(domain_name)
  get "/dns/managed/#{get_id_by_domain(domain_name)}/records"
end

#update_record(domain, record_id, name, type, value, options = {}) ⇒ Object



133
134
135
136
# File 'lib/dnsmadeeasy-rest-api.rb', line 133

def update_record(domain, record_id, name, type, value, options = {})
  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(options)
end