Class: StudioApi::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/studio_api/util.rb

Overview

Utility class for handling whole stack of Studio Api

Class Method Summary (collapse)

Class Method Details

+ (Object) add_options(request_str, options, first = true)



31
32
33
34
35
36
37
38
39
40
# File 'lib/studio_api/util.rb', line 31

def self.add_options request_str,options,first=true
			unless options.empty?
options.each do |k,v|
	separator = first ? "?" : "&"
	first = false
	request_str << "#{separator}#{CGI.escape k.to_s}=#{CGI.escape v.to_s}"
end
			end
  request_str
end

+ (Array<Class>) configure_studio_connection(connection)

Set connection for all StudioApi class, so then you can use it without explicit settings It is useful when program use only one studio credentials

Examples:

connection = StudioApi::Connection.new ( "user", "password", "http://localhost/api")
StudioApi::Util.configure_studio_connection connection
appliances = StudioApi::Appliance.find :all


13
14
15
16
# File 'lib/studio_api/util.rb', line 13

def self.configure_studio_connection connection
  classes = get_all_usable_class StudioApi
  classes.each {|c| c.studio_connection = connection}
end

+ (String) join_relative_url(*args)

joins relative url for unix servers as URI.join require at least one absolute adress. Especially take care about only one slash otherwise studio returns 404.



23
24
25
26
27
28
29
# File 'lib/studio_api/util.rb', line 23

def self.join_relative_url(*args)
  args.reduce do |base, append|
    base= base[0..-2] if base.end_with? "/" #remove ending slash in base
    append = append[1..-1] if append.start_with? "/" #remove leading slash in append
    "#{base}/#{append}"
  end
end