Class: PDNS::API

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

Overview

Class for interacting with the API

Direct Known Subclasses

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ API

Returns a new instance of API.



9
10
11
12
13
14
15
16
# File 'lib/pdns_api/api.rb', line 9

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

Instance Attribute Details

#classObject (readonly)

Returns the value of attribute class.



7
8
9
# File 'lib/pdns_api/api.rb', line 7

def class
  @class
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/pdns_api/api.rb', line 7

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/pdns_api/api.rb', line 7

def version
  @version
end

Class Method Details

.hash_string_to_sym(hash) ⇒ Object



54
55
56
# File 'lib/pdns_api/api.rb', line 54

def self.hash_string_to_sym(hash)
  hash.map { |string, value| [string.to_sym, value] }.to_h
end

.hash_sym_to_string(hash) ⇒ Object



50
51
52
# File 'lib/pdns_api/api.rb', line 50

def self.hash_sym_to_string(hash)
  hash.map { |symbol, value| [symbol.to_s, value] }.to_h
end

Instance Method Details

#create(info = nil) ⇒ Object

Create this object on the server



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

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

#deleteObject

Delete this object



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

def delete
  @http.delete @url
end

#ensure_array(item) ⇒ Object

Helper methods



45
46
47
48
# File 'lib/pdns_api/api.rb', line 45

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

#getObject

Get information for this object



21
22
23
# File 'lib/pdns_api/api.rb', line 21

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

#info(info = nil) ⇒ Object

Get/set info



37
38
39
40
41
# File 'lib/pdns_api/api.rb', line 37

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

  @info.merge!(info)
end