Class: PolyAnalyst6API::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/polyanalyst6api/session.rb

Overview

This class maintains sessions in PolyAnalyst 6.x

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: 'localhost', port: 5043, v: '1.0', uname: 'administrator', pwd: '') ⇒ Session

Log in to a PolyAnslyst Server

Parameters:

  • :host (String)

    The host to login to

  • :port (Integer)

    The prot

  • :v (String)

    API version to use (ex. '1.0', '2.3' etc.)

  • :uname (String)

    The user name to login with

  • :pwd (String)

    The password for specified user name

Raises:

  • (StandardError)

    an exception with corresponding login error


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/polyanalyst6api/session.rb', line 16

def initialize(host: 'localhost', port: 5043, v: '1.0', uname: 'administrator', pwd: '')
  @base_url = "https://#{host}:#{port}/polyanalyst/api/v#{v}"
   = @base_url + "/login?uname=#{uname}&pwd=#{pwd}"
  params = {
    method: :post,
    url: ,
    verify_ssl: false
  }
  begin
    resp = RestClient::Request.execute params
  rescue RestClient::InternalServerError => e
    raise JSON.parse(e.response.body)[1]
  end
  @sid = resp.cookies['sid']
  raise 'Login failed!' unless @sid
end

Instance Attribute Details

#sidString (readonly)

The SID of current sessoin

Returns:

  • (String)

    the current value of sid


6
7
8
# File 'lib/polyanalyst6api/session.rb', line 6

def sid
  @sid
end

Instance Method Details

#project(uuid) ⇒ Project

Creates an instance of Project (A Project.new alias)

Returns:


41
42
43
# File 'lib/polyanalyst6api/session.rb', line 41

def project(uuid)
  Project.new(self, uuid)
end

#request(url: '', method: :get, params: {}) ⇒ Request

Creates a Request instance (A Request.new alias)

Returns:


35
36
37
# File 'lib/polyanalyst6api/session.rb', line 35

def request(url: '', method: :get, params: {})
  Request.new(@base_url, @sid, url, method, params)
end