Class: PDNS::Client
Overview
Class for interaction with the top level API.
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
The PowerDNS API version in use.
Attributes inherited from API
Instance Method Summary collapse
-
#initialize(args) ⇒ Client
constructor
Creates a client object.
-
#servers(id = nil) ⇒ Object
(also: #server)
Returns existing or creates a
Serverobject.
Methods inherited from API
#create, #delete, #ensure_array, #get, #info
Constructor Details
#initialize(args) ⇒ Client
Creates a client object. args is used to create an HTTP object, which is used by all created objects.
36 37 38 39 40 41 42 43 |
# File 'lib/pdns_api/client.rb', line 36 def initialize(args) @class = :client @http = PDNS::HTTP.new(args) @version = @http.version @parent = self @url = @http.uri @info = {} end |
Instance Attribute Details
#version ⇒ Object (readonly)
The PowerDNS API version in use.
30 31 32 |
# File 'lib/pdns_api/client.rb', line 30 def version @version end |
Instance Method Details
#servers(id = nil) ⇒ Object Also known as: server
Returns existing or creates a 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.
52 53 54 55 56 57 58 |
# File 'lib/pdns_api/client.rb', line 52 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 |