Class: PDNS::Client

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

Overview

Class for interaction with the top level API.

Instance Attribute Summary collapse

Attributes inherited from API

#class, #url

Instance Method Summary collapse

Methods inherited from API

#create, #delete, #ensure_array, #get, #info

Constructor Details

#initialize(args) ⇒ Client

Creates a Client object.

Parameters:

  • args (Hash)

    Arguments used to create an HTTP object, which is used by all created objects.


42
43
44
45
46
47
48
49
# File 'lib/pdns_api/client.rb', line 42

def initialize(args)
  @class   = :client
  @http    = PDNS::HTTP.new(args)
  @version = @http.version
  @parent  = self
  @url     = @http.uri
  @info    = {}
end

Instance Attribute Details

#versionInteger (readonly)

Returns the PowerDNS API version in use.

Returns:

  • (Integer)

    the PowerDNS API version in use.


30
31
32
# File 'lib/pdns_api/client.rb', line 30

def version
  @version
end

Instance Method Details

#changeObject

Disabled common methods


34
# File 'lib/pdns_api/client.rb', line 34

undef_method :change, :create, :delete

#servers(id = nil) ⇒ Hash, Server Also known as: server

Returns existing or creates a Server object.

Parameters:

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

    ID of a Server.

Returns:

  • (Hash, Server)

    Hash of Server objects or a single Server object.

    • If id is not set the current servers are returned in a hash containing Server objects.

    • If id is set a Server object with the provided ID is returned.


61
62
63
64
65
66
67
# File 'lib/pdns_api/client.rb', line 61

def servers(id = nil)
  return Server.new(@http, self, id) unless id.nil?

  # Return a hash of server objects
  servers = @http.get "#{@url}/servers"
  servers.map! { |s| [s[:id], Server.new(@http, self, s[:id], s)] }.to_h
end