Class: StudioApi::Connection

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

Overview

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

Constant Summary collapse

SSL_ATTRIBUTES =

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

[ :key, :cert, :ca_file, :ca_path, :verify_mode, :verify_callback, :verify_depth, :cert_store ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, password, uri, options = {}) ⇒ Connection

Creates new object

Examples:

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"}

Parameters:

  • user (String)

    login to studio API

  • password (String)

    API key for studio

  • uri (String, URI)

    pointing to studio site including path to api

  • options (Hash) (defaults to: {})

    hash of additional options. Represents other attributes.

Options Hash (options):

  • :proxy (URI, String) — default: nil

    see proxy attribute

  • :timeout (String, Fixnum) — default: 45

    see timeout attribute. Specified in seconds

  • :ssl (Hash) — default: {:verify_mode = OpenSSL::SSL::VERIFY_NONE}

    see ssl attribute



61
62
63
64
65
66
67
68
# File 'lib/studio_api/connection.rb', line 61

def initialize(user, password, uri, options={})
  @user = user
  @password = password
  self.uri = uri
  self.proxy = options[:proxy] #nil as default is OK
  @timeout = (options[:timeout] || 45).to_i
  @ssl = options[:ssl] || { :verify_mode => OpenSSL::SSL::VERIFY_NONE } # don't verify as default
end

Instance Attribute Details

#passwordObject (readonly)

Represents API key for studio API



33
34
35
# File 'lib/studio_api/connection.rb', line 33

def password
  @password
end

#proxyObject

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



40
41
42
# File 'lib/studio_api/connection.rb', line 40

def proxy
  @proxy
end

#sslObject (readonly)

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



45
46
47
# File 'lib/studio_api/connection.rb', line 45

def ssl
  @ssl
end

#timeoutObject (readonly)

Represents timeout for connection in seconds.



42
43
44
# File 'lib/studio_api/connection.rb', line 42

def timeout
  @timeout
end

#uriObject

Represents URI pointing to studio site including path to API

Examples:

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


37
38
39
# File 'lib/studio_api/connection.rb', line 37

def uri
  @uri
end

#userObject (readonly)

Represents login name for studio API



31
32
33
# File 'lib/studio_api/connection.rb', line 31

def user
  @user
end

Instance Method Details

#api_versionObject



70
71
72
# File 'lib/studio_api/connection.rb', line 70

def api_version
  @version ||= version_detect
end