Class: PDNS::Metadata

Inherits:
API
  • Object
show all
Defined in:
lib/pdns_api/metadata.rb

Overview

Metadata for a zone.

Instance Attribute Summary collapse

Attributes inherited from API

#class, #url

Instance Method Summary collapse

Methods inherited from API

#create, #delete, #ensure_array, #info

Constructor Details

#initialize(http, parent, kind, value = []) ⇒ Metadata

Creates a configuration option object.

Parameters:

  • http (HTTP)

    An HTTP object for interaction with the PowerDNS server.

  • parent (API)

    This object’s parent.

  • kind (String)

    Kind of the metadata.

  • value (String) (defaults to: [])

    Optional value of the metadata.



36
37
38
39
40
41
42
43
44
# File 'lib/pdns_api/metadata.rb', line 36

def initialize(http, parent, kind, value = [])
  @class  = :metadata
  @http   = http
  @parent = parent
  @kind   = kind
  @url    = "#{parent.url}/#{@class}/#{kind}"
  @value  = get if value.empty?
  value(@value)
end

Instance Attribute Details

#kindname

Returns the kind of metadata.

Returns:

  • (name)

    the kind of metadata.



26
27
28
# File 'lib/pdns_api/metadata.rb', line 26

def kind
  @kind
end

Instance Method Details

#change(value = nil) ⇒ Hash

Changes this object’s information on the server.

Examples:

 = zone.('ALLOW-AXFR-FROM')
.change('AUTO-NS')

Parameters:

  • value (String, nil) (defaults to: nil)

    Value to change the object to.

    • If value is set, the current value is used.

    • If value is not set, value is updated and then used.

Returns:

  • (Hash)

    result of the change.



89
90
91
92
# File 'lib/pdns_api/metadata.rb', line 89

def change(value = nil)
  value(value)
  @http.put(@url, @info)
end

#getHash

Gets the current information. This also updates value.

Returns:

  • (Hash)

    the object’s information from the API.



70
71
72
73
74
# File 'lib/pdns_api/metadata.rb', line 70

def get
  res = @http.get @url
  value(res[:value]) if res.key? :value
  res
end

#value(value = nil) ⇒ String

Gets or sets the value attribute.

Parameters:

  • value (String, nil) (defaults to: nil)

    the value of the object.

Returns:

  • (String)

    the value of the object. If value is set the object’s value is updated.



53
54
55
56
57
58
59
60
61
62
# File 'lib/pdns_api/metadata.rb', line 53

def value(value = nil)
  return @info[:metadata] if value.nil?

  # Convert to array if value is string
  value = ensure_array(value)

  # Set value and info
  @info  = { type: 'Metadata', kind: @kind, metadata: value }
  @value = value
end