class Infoblox::Connection

Attributes

adapter[RW]
adapter_block[RW]
connection[RW]
host[RW]
logger[RW]
password[RW]
ssl_opts[RW]
username[RW]

Public Class Methods

new(opts={}) click to toggle source
# File lib/infoblox/connection.rb, line 45
def initialize(opts={})
  self.username = opts[:username]
  self.password = opts[:password]
  self.host     = opts[:host]
  self.logger   = opts[:logger]
  self.ssl_opts = opts[:ssl_opts] || {}
end

Public Instance Methods

delete(href) click to toggle source
# File lib/infoblox/connection.rb, line 39
def delete(href)
  wrap do
    connection.delete(href)
  end
end
get(href, params={}) click to toggle source
# File lib/infoblox/connection.rb, line 15
def get(href, params={})
  wrap do
    connection.get(href, params)
  end
end
host=(new_host) click to toggle source

The host variable is expected to be a protocol with a host name. If the host has no protocol, https:// is added before it.

# File lib/infoblox/connection.rb, line 66
def host=(new_host)
  unless new_host =~ /^http(s)?:\/\//
    new_host = "https://#{new_host}"
  end
  @host = new_host
end
inspect() click to toggle source

Don't display the username/password in logging, etc.

# File lib/infoblox/connection.rb, line 80
def inspect
  "#<#{self.class}:#{object_id} @host=\"#{@host}\">"
end
post(href, body) click to toggle source
# File lib/infoblox/connection.rb, line 21
def post(href, body)
  wrap do
    connection.post do |req|
      req.url href
      req.body = body.to_json
    end
  end
end
put(href, body) click to toggle source
# File lib/infoblox/connection.rb, line 30
def put(href, body)
  wrap do
    connection.put do |req|
      req.url href
      req.body = body.to_json
    end
  end
end

Private Instance Methods

wrap() { || ... } click to toggle source
# File lib/infoblox/connection.rb, line 86
def wrap
  yield.tap do |response|
    unless response.status < 300
      raise Infoblox::Error.new("Error: #{response.status} #{response.body}")
    end
  end