class EZDyn::Zone

Abstraction of Dyn REST API DNS Zones

Attributes

name[R]
serial[R]
serial_style[R]
type[R]

Public Class Methods

new(client:, name: nil, type: nil, serial: nil, serial_style: nil, raw: nil, uri: nil) click to toggle source

@private

# File lib/ezdyn/zone.rb, line 7
def initialize(client:, name: nil, type: nil, serial: nil, serial_style: nil, raw: nil, uri: nil)
  EZDyn.debug { "Zone.new( client: Client{}, name: #{name}, type: #{type}, serial: #{serial}, serial_style: #{serial_style}, raw: #{raw.nil? ? nil : raw.to_json}, uri: #{uri} )" }
  @client = client
  @name = name
  @type = type
  @serial = serial
  @serial_style = serial_style
  @in_sync = false

  if not raw.nil?
    self.sync_raw(raw)
  end

  if not uri.nil?
    uri.gsub!(%r{^/?(REST/)?}, '')
    if uri =~ %r{^Zone/([^/]+)/?$}
      @name = $1
    end
  end
end

Public Instance Methods

in_sync?() click to toggle source

Indicates whether the object has been synced with the API.

# File lib/ezdyn/zone.rb, line 52
def in_sync?
  @in_sync
end
sync!() click to toggle source

Attempt to sync the object with the API.

@raise [RuntimeError] if the object does not exist or could not be synced.

# File lib/ezdyn/zone.rb, line 59
def sync!
  EZDyn.debug { "Zone{#{self.name}}.sync!" }
  return self if self.in_sync?

  data = @client.fetch_uri_data(uri: self.uri)
  if data.is_a? Hash
    sync_raw(data)
  else
    raise "Failed to sync zone #{self.name}"
  end

  self
end
sync_raw(raw) click to toggle source

@private

# File lib/ezdyn/zone.rb, line 74
def sync_raw(raw)
  EZDyn.debug { "Zone{#{self.name}}.sync_raw( #{raw.nil? ? nil : raw.to_json} )" }
  @name = raw["zone"]
  @type = raw["zone_type"]
  @serial = raw["serial"]
  @serial_style = raw["serial_style"]
  @in_sync = true
end
to_s() click to toggle source

Returns the name of the zone for display purposes.

# File lib/ezdyn/zone.rb, line 84
def to_s
  self.name
end
uri() click to toggle source

@private

# File lib/ezdyn/zone.rb, line 47
def uri
  "/Zone/#{self.name}"
end