class StudioApi::Util

Utility class for handling whole stack of Studio Api

Public Class Methods

add_options(request_str,options,first=true) click to toggle source
   # File lib/studio_api/util.rb
31 def self.add_options request_str,options,first=true
32                     unless options.empty?
33                             options.each do |k,v|
34                                     separator = first ? "?" : "&"
35                                     first = false
36                                     request_str << "#{separator}#{CGI.escape k.to_s}=#{CGI.escape v.to_s}"
37                             end
38                     end
39   request_str
40 end
configure_studio_connection(connection) click to toggle source

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 @example

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

@param [StudioApi::Connection] connection which is used for communication with studio @return [Array<Class>] return set of classes which is set

   # File lib/studio_api/util.rb
13 def self.configure_studio_connection connection
14   classes = get_all_usable_class StudioApi
15   classes.each {|c| c.studio_connection = connection}
16 end
join_relative_url(*args) click to toggle source

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. @param (Array<String>) args list of Strings to join @return (String) joined String

   # File lib/studio_api/util.rb
23 def self.join_relative_url(*args)
24   args.reduce do |base, append|
25     base= base[0..-2] if base.end_with? "/" #remove ending slash in base
26     append = append[1..-1] if append.start_with? "/" #remove leading slash in append
27     "#{base}/#{append}"
28   end
29 end

Private Class Methods

get_all_usable_class(modul) click to toggle source
   # File lib/studio_api/util.rb
42 def self.get_all_usable_class (modul)
43   classes = modul.constants.collect{ |c| modul.const_get(c) }
44   classes = classes.select { |c| c.class == Class && c.respond_to?(:studio_connection=) }
45   inner_classes = classes.collect { |c| get_all_usable_class(c) }.flatten
46   classes + inner_classes
47 end