class Occi::Api::Client::ClientBase

Attributes

auth_options[R]

a few attributes which should be visible outside the client

connected[R]
endpoint[R]

a few attributes which should be visible outside the client

last_response[R]
logger[R]
media_type[R]

a few attributes which should be visible outside the client

model[R]
options[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/occi/api/client/client_base.rb, line 13
def initialize(options = {})
  # define defaults and convert options to Hashie::Mash if necessary
  defaults = Hashie::Mash.new({
    :endpoint => "http://localhost:3000/",
    :auth => {:type => "none"},
    :log => {:out => STDERR, :level => Occi::Api::Log::WARN, :logger => nil},
    :auto_connect => true,
    :media_type => nil
  })

  options = options.marshal_dump if options.is_a?(OpenStruct)
  options = Hashie::Mash.new(options)

  @options = defaults.merge(options)

  # set Occi::Api::Log
  @logger = get_logger(@options[:log])

  # check the validity and canonize the endpoint URI
  @endpoint = get_endpoint_uri(@options[:endpoint])

  # set global connection options, such as timeout
  configure_connection(@options)

  # pass auth options
  @auth_options = get_auth(@options[:auth])

  # verify authN before attempting actual
  # message exchange with the server; this
  # is necessary because of OCCI-OS and its
  # redirect to OS Keystone
  preauthenticate

  # set accepted media types
  @media_type = get_media_type(@options[:media_type])

  @connected = false
end

Public Instance Methods

connect(force = false) click to toggle source

Issues necessary connecting operations on connection-oriented clients. Stateless clients (such as ClientHttp) should use the auto_connect option during instantiation.

@example

client.connect # => true

@param force [Boolean] force re-connect on already connected client @return [Boolean] true on successful connect

# File lib/occi/api/client/client_base.rb, line 61
def connect(force = false)
  raise "Client already connected!" if @connected && !force
  @connected = true
end