Class: OvhDnsup::DomainUpdater
- Inherits:
-
Object
- Object
- OvhDnsup::DomainUpdater
- Defined in:
- lib/ovh_dnsup/domain_manager.rb
Overview
Once authorized, can be used to change a DNS zone entry.
Instance Method Summary collapse
-
#initialize(endpoint: nil, application_key: nil, application_secret: nil, state: nil) ⇒ DomainUpdater
constructor
A new instance of DomainUpdater.
- #login(domain:, subdomain:, type_map:) ⇒ Object
- #state ⇒ Object
- #state=(h) ⇒ Object
- #update(new_ip) ⇒ Object
Constructor Details
#initialize(endpoint: nil, application_key: nil, application_secret: nil, state: nil) ⇒ DomainUpdater
Returns a new instance of DomainUpdater.
151 152 153 154 155 156 157 158 159 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 151 def initialize(endpoint: nil, application_key: nil, application_secret: nil, state: nil) if state self.state = state else @api = OvhApi.new(endpoint: endpoint, application_key: application_key, application_secret: application_secret) end end |
Instance Method Details
#login(domain:, subdomain:, type_map:) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 175 def login(domain:, subdomain:, type_map:) @domain = domain @subdomain = subdomain @type_map = type_map access_rules = type_map.map() { |type, id| { method: 'PUT', path: "/domain/zone/#{domain}/record/#{id}" } } access_rules.push({method: 'POST', path: "/domain/zone/#{@domain}/refresh"}) @api.login(access_rules) end |
#state ⇒ Object
161 162 163 164 165 166 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 161 def state { 'api_state' => @api.state, 'domain' => @domain, 'subdomain' => @subdomain, 'type_map' => @type_map } end |
#state=(h) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 168 def state= h @api = OvhApi.new(state: h['api_state']) @domain = h['domain'] @subdomain = h['subdomain'] @type_map = h['type_map'] end |
#update(new_ip) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 188 def update(new_ip) type = (/:/ =~ new_ip) ? 'AAAA' : 'A' id = @type_map[type] if !id then raise "Subdomain has no #{type} record" end obj = {'ttl' => 300, 'target' => new_ip } @api.put("domain/zone/#{@domain}/record/#{id}", obj) @api.post("domain/zone/#{@domain}/refresh") end |