Class: Birst_Command::Session

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

Overview

Public: Session class used to interact with Birst Web Services

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ Session

Public: Initialize Session class

wsdl - URL of soap WSDL (default: Settings.session.wsdl) endpoint - URL of soap endpoint (default: Settings.session.endpoint) soap_log - Boolean switch indicating whether logging should be performed (default: Settings.session.soap_log) soap_logger - Logger instance used to write log messages (default: Settings.session.soap_logger) soap_log_level - Logging level (default: Settings.session.soap_log_level) username - Username to use to login to Birst Web Services (default: Settings.session.username) password - Encrypted password for username (default: Settings.session.password) auth_cookie - Use a previously generated authorization cookie

Returns nothing



18
19
20
21
22
23
24
25
26
# File 'lib/birst_command/session.rb', line 18

def initialize(opts = {}, &block)
  @login_token = nil
  @options = set_options(opts)
  @client = new_client

  if block_given?
    (&block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(command_name, *args) ⇒ Object

Public: Method missing used to send commands to Birst Web Services.

command_name - Symbol representing the name of the Birst command (snake_case) *args - Optional arguments that are passed to the Birst command.

Returns - The soap result as a hash



56
57
58
# File 'lib/birst_command/session.rb', line 56

def method_missing(command_name, *args)
  command command_name, *args
end

Instance Attribute Details

Returns the value of attribute auth_cookie.



29
30
31
# File 'lib/birst_command/session.rb', line 29

def auth_cookie
  @auth_cookie
end

#login_tokenObject (readonly)

Returns the value of attribute login_token.



28
29
30
# File 'lib/birst_command/session.rb', line 28

def 
  @login_token
end

Instance Method Details

#command(command_name, *args) ⇒ Object

Public: Runs the command that is obtained from the method_missing call.

command_name - Name of Birst command (snake_case). *args - Optional arguments that are passed to the Birst command.

Returns - The soap result as a hash



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/birst_command/session.rb', line 66

def command(command_name, *args)
  response_key = "#{command_name}_response".to_sym
  result_key = "#{command_name}_result".to_sym

  message = args.last.is_a?(Hash) ? args.pop : {}
  result = @client.call command_name,
                        cookies: @auth_cookie,
                        message: { :token => @login_token }.merge(message)

  result.hash[:envelope][:body][response_key][result_key]
end

#loginObject

Public: Login to Birst using the username and password. After login, the auth cookie and login token are captured and stored as an instance variable.

Returns the Savon response.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/birst_command/session.rb', line 37

def 
  response = @client.call(:login,
    cookies: @auth_cookie,
    message: {
      username: @username, 
      password: decrypt(@password)
    })

  @auth_cookie = response.http.cookies if @auth_cookie.nil?
  @login_token = response.hash[:envelope][:body][:login_response][:login_result]
  response
end