module Occi::Api::Client::Base::ProtectedHelpers

Public Instance Methods

get_endpoint_uri(endpoint) click to toggle source

Checks whether the given endpoint URI is valid and converts it to a URI instance.

@example

get_endpoint_uri "http://localhost:3300" # => #<URI::*>

@param endpoint [String] endpoint URI in a non-canonical string @return [URI] canonical endpoint URI

# File lib/occi/api/client/base/protected_helpers.rb, line 33
def get_endpoint_uri(endpoint)
  unless endpoint =~ URI::ABS_URI
    raise "Endpoint not a valid absolute URI! #{endpoint.inspect}"
  end

  # normalize URIs, remove trailing slashes
  endpoint = URI(endpoint)
  endpoint.path = endpoint.path.gsub(/\/+/, '/').chomp('/')
  endpoint.query = nil

  endpoint
end
get_logger(log_options) click to toggle source

Sets the logger and log levels. This allows users to pass existing logger instances to the rOCCI client.

@example

get_logger { :out => STDERR, :level => Occi::Api::Log::WARN, :logger => nil }

@param log_options [Hash] logger options @return [Occi::Api::Log] instance of the logger

# File lib/occi/api/client/base/protected_helpers.rb, line 14
def get_logger(log_options)
  unless log_options[:logger].kind_of?(Occi::Api::Log)
    logger = Occi::Api::Log.new(log_options[:out])
    logger.level = log_options[:level]
  else
    logger = log_options[:logger]
  end

  logger
end
get_model(model_collection) click to toggle source

Creates an Occi::Model from data retrieved from the server.

@example

model_collection = get('/-/')
get_model model_collection # => #<Occi::Model>

@param model_collection [Occi::Collection] parsed representation of server's model @return [Occi::Model] Model instance

# File lib/occi/api/client/base/protected_helpers.rb, line 54
def get_model(model_collection)
  # build model
  Occi::Model.new(model_collection)
end
get_os_tpl_mixins_ary() click to toggle source

Returns mixin type identifiers for os_tpl mixins in an array.

@return [Array] array of os_tpl mixin identifiers

# File lib/occi/api/client/base/protected_helpers.rb, line 63
def get_os_tpl_mixins_ary
  mixins = get_os_tpls
  mixins.to_a.collect { |m| m.type_identifier }
end
get_resource_tpl_mixins_ary() click to toggle source

Returns mixin type identifiers for resource_tpl mixins in an array.

@return [Array] array of resource_tpl mixin identifiers

# File lib/occi/api/client/base/protected_helpers.rb, line 72
def get_resource_tpl_mixins_ary
  mixins = get_resource_tpls
  mixins.to_a.collect { |m| m.type_identifier }
end