class StudioApi::Connection

Represents information needed for connection to studio. In common case it is just needed once initialize and then pass it to classes.

Constants

SSL_ATTRIBUTES

SSL attributes which can be set into ssl attributes. For more details see openssl library

Attributes

password[R]

Represents API key for studio API

proxy[R]

Represents proxy object needed for connection to studio API. nil represents that no proxy needed

ssl[R]

Represents settings for SSL verification in case of uri is https. It is Hash with keys from SSL_ATTRIBUTES

timeout[R]

Represents timeout for connection in seconds.

uri[R]

Represents URI pointing to studio site including path to API @example

connection.uri == URI.parse "http://susestudio.com/api/v1/user/"
user[R]

Represents login name for studio API

Public Class Methods

new(user, password, uri, options={}) click to toggle source

Creates new object @example

StudioApi::Connection.new "user","pwd","https://susestudio.com//api/v1/user/",
                          :timeout => 120, :proxy => "http://user:pwd@proxy",
                          :ssl => { :verify_mode => OpenSSL::SSL::VERIFY_PEER,
                                    :ca_path => "/etc/studio.cert"}

@param [String] user login to studio API @param (String) password API key for studio @param (String,URI) uri pointing to studio site including path to api @param (Hash) options hash of additional options. Represents other attributes. @option options [URI,String] :proxy (nil) see proxy attribute @option options [String, Fixnum] :timeout (45) see timeout attribute. Specified in seconds @option options [Hash] :ssl ( {:verify_mode = OpenSSL::SSL::VERIFY_NONE}) see ssl attribute

   # File lib/studio_api/connection.rb
61 def initialize(user, password, uri, options={})
62   @user = user
63   @password = password
64   self.uri = uri
65   self.proxy = options[:proxy] #nil as default is OK
66   @timeout = (options[:timeout] || 45).to_i
67   @ssl = options[:ssl] || { :verify_mode => OpenSSL::SSL::VERIFY_NONE } # don't verify as default
68 end

Public Instance Methods

api_version() click to toggle source
   # File lib/studio_api/connection.rb
70 def api_version
71   @version ||= version_detect
72 end

Protected Instance Methods

proxy=(value) click to toggle source

Overwritte proxy object. @param (String,URI,nil) value new proxy to site. If String is passed then it is parsed by URI.parse, which can throw exception. If nil is passed then it means disable proxy.

   # File lib/studio_api/connection.rb
87 def proxy=(value)
88   if value.is_a? String
89     @proxy = URI.parse value
90   else
91     @proxy = value
92   end
93 end
uri=(value) click to toggle source

Overwritte uri object. @param (String,URI) value new uri to site. If String is passed then it is parsed by URI.parse, which can throw exception

   # File lib/studio_api/connection.rb
77 def uri=(value)
78   if value.is_a? String
79     @uri = URI.parse value
80   else
81     @uri = value
82   end
83 end

Private Instance Methods

version_detect() click to toggle source
    # File lib/studio_api/connection.rb
 96 def version_detect
 97   rq = GenericRequest.new self
 98   response = rq.get "/api_version"
 99   Hash.from_xml(response)["version"]
100 end