Class: ICWS::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/icws/connection.rb,
lib/icws/feature.rb

Overview

Representation of a connectio nto a CIC server.

Defined Under Namespace

Classes: Feature

Instance Method Summary collapse

Constructor Details

#initialize(application_name, server) ⇒ Connection

Creates a new connection



12
13
14
15
# File 'lib/icws/connection.rb', line 12

def initialize(application_name, server)
    @application_name = application_name
    @server = server
end

Instance Method Details

#application_nameString

Gets the name of the application.



46
47
48
# File 'lib/icws/connection.rb', line 46

def application_name
    @application_name
end

#base_uriString

Returns the base uri to the server, including the session id



90
91
92
# File 'lib/icws/connection.rb', line 90

def base_uri
    @server+'/icws/' + @session_id
end

#connect(user, password, extraParam = nil, extraValue = nil) ⇒ Object

Connects to the server



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/icws/connection.rb', line 20

def connect(user, password, extraParam=nil, extraValue=nil)
    if extraParam == nil || extraParam == ''
        extraParam = "x-icws"
    end

    connectResponse = RestClient.post @server +'/icws/connection',
    {
        '__type' => "urn:inin.com:connection:icAuthConnectionRequestSettings",
        :applicationName => @application_name,
        :userID => user,
        :password => password,
        extraParam => extraValue
    }.to_json,
    :content_type => :json,
    :accept => :json,
    'Accept-Language' => 'en-us'

    response = JSON.parse(connectResponse);
    @cookie = connectResponse.headers[:set_cookie][0]
    @csrf_token = response['csrfToken']
    @session_id = response['sessionId']

end

Gets the connection cookie.



58
59
60
# File 'lib/icws/connection.rb', line 58

def cookie
    @cookie
end

#featuresArray[ICWS::Connection::Features]

Gets the features of the server.



76
77
78
79
# File 'lib/icws/connection.rb', line 76

def features
    data = JSON.parse RestClient.get @server+'/icws/connection/features'
    features = data["featureInfoList"].map { |rd| ICWS::Connection::Feature.new(rd["featureId"], rd["version"]) }
end

#generate_uri(path) ⇒ String

Generates a full uri given the resource path.



84
85
86
# File 'lib/icws/connection.rb', line 84

def generate_uri(path)
    base_uri + path
end

#serverString

Gets the url of the server



64
65
66
# File 'lib/icws/connection.rb', line 64

def server
    @server
end

#tokenString

Gets the connection token.



52
53
54
# File 'lib/icws/connection.rb', line 52

def token
    @csrf_token
end

#versionObject

Gets the version of the server.



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

def version
    JSON.parse RestClient.get @server+'/icws/connection/version'
end