Class: PDNS::API

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

Overview

The superclass for all PDNS objects.

Direct Known Subclasses

Client, Config, CryptoKey, Metadata, Override, Server, Zone

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#classObject (readonly)

Returns the class of the resource object.

Returns:

  • the class of the resource object.


32
33
34
# File 'lib/pdns_api/api.rb', line 32

def class
  @class
end

#urlObject (readonly)

Returns the url of the resource object.

Returns:

  • the url of the resource object.


28
29
30
# File 'lib/pdns_api/api.rb', line 28

def url
  @url
end

Instance Method Details

#change(rrsets) ⇒ Hash

Changes this object's information on the server.

Parameters:

  • rrsets (Array)

    is used as changeset for the change.

Returns:

  • (Hash)

    result of the change.


40
41
42
# File 'lib/pdns_api/api.rb', line 40

def change(rrsets)
  @http.put(@url, rrsets)
end

#create(info = nil) ⇒ Hash

Creates this object on the server

If info is set this method updates the current information. The current information is used to create the object.

Examples:

zone.create(
  name: zone.id,
  kind: 'Native',
  dnssec: true,
  nameservers: %w( ns0.example.com. ns1.example.com. )
)

Parameters:

  • info (Hash, nil) (defaults to: nil)

    Information to set when creating the object.

Returns:

  • (Hash)

    result of the creation.


61
62
63
64
# File 'lib/pdns_api/api.rb', line 61

def create(info = nil)
  info(info)
  @http.post("#{@parent.url}/#{@class}", @info)
end

#deleteHash

Deletes this object.

Returns:

  • (Hash)

    result of the deletion.


71
72
73
# File 'lib/pdns_api/api.rb', line 71

def delete
  @http.delete @url
end

#ensure_array(item) ⇒ Array

Ensures the object is an array. If it is not, an array containing the item is returned.

Parameters:

  • item

    anything that might or might not be an Array.

Returns:

  • (Array)

    item as an array.


105
106
107
108
# File 'lib/pdns_api/api.rb', line 105

def ensure_array(item)
  return item if item.is_a? Array
  [item]
end

#getHash

Gets the information of this object from the API and use it to update the object's information.

Returns:

  • (Hash)

    the object's information from the API.


81
82
83
# File 'lib/pdns_api/api.rb', line 81

def get
  @info = @http.get @url
end

#info(info = nil) ⇒ Hash

Gets and sets the object information. This does not cause an API request.

Parameters:

  • info (Hash, nil) (defaults to: nil)

    Information to change.

Returns:

  • (Hash)

    this object's information.


92
93
94
95
96
# File 'lib/pdns_api/api.rb', line 92

def info(info = nil)
  return @info if info.nil?

  @info.merge!(info)
end