QlikElixir.QIX.Session (qlik_elixir v0.3.5)

View Source

WebSocket session management for Qlik Engine API (QIX).

Provides GenServer-based connection management for real-time communication with Qlik Engine via JSON-RPC over WebSocket.

Usage

# Connect to an app
{:ok, session} = QlikElixir.QIX.Session.connect("app-id", config: config)

# Make requests
{:ok, result} = QlikElixir.QIX.Session.request(session, "Doc.GetAllSheets", app_handle, [])

# Disconnect
:ok = QlikElixir.QIX.Session.disconnect(session)

Architecture

Each session is a GenServer that:

  • Maintains a gun WebSocket connection
  • Correlates requests with responses via JSON-RPC IDs
  • Manages object handles for the connected app

Summary

Functions

Builds the WebSocket URL for connecting to an app.

Returns a specification to start this module under a supervisor.

Connects to a Qlik app via WebSocket.

Disconnects the session.

Gets the app handle for the connected session.

Parses a WebSocket URL into components for gun.

Makes a JSON-RPC request to the Qlik Engine.

Types

t()

@type t() :: %QlikElixir.QIX.Session{
  app_handle: non_neg_integer() | nil,
  app_id: String.t(),
  config: QlikElixir.Config.t(),
  conn_pid: pid() | nil,
  handles: map(),
  pending_requests: map(),
  request_id: pos_integer(),
  stream_ref: reference() | nil
}

Functions

build_websocket_url(app_id, config)

@spec build_websocket_url(String.t(), QlikElixir.Config.t()) :: String.t()

Builds the WebSocket URL for connecting to an app.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

connect(app_id, opts \\ [])

@spec connect(
  String.t() | nil,
  keyword()
) :: {:ok, pid()} | {:error, QlikElixir.Error.t()}

Connects to a Qlik app via WebSocket.

Options

  • :config - Required. QlikElixir.Config struct with tenant_url and api_key.
  • :timeout - Connection timeout in ms (default: 10000).

Returns

  • {:ok, pid} - Session process PID
  • {:error, Error.t()} - Connection failed

disconnect(session)

@spec disconnect(pid()) :: :ok

Disconnects the session.

get_app_handle(session)

@spec get_app_handle(pid()) ::
  {:ok, non_neg_integer()} | {:error, QlikElixir.Error.t()}

Gets the app handle for the connected session.

parse_websocket_url(url)

@spec parse_websocket_url(String.t()) ::
  {:ok, charlist(), non_neg_integer(), String.t()} | {:error, any()}

Parses a WebSocket URL into components for gun.

request(session, method, handle, params, opts \\ [])

@spec request(pid(), String.t(), non_neg_integer(), list(), keyword()) ::
  {:ok, any()} | {:error, QlikElixir.Error.t()}

Makes a JSON-RPC request to the Qlik Engine.

Parameters

  • session - Session PID
  • method - Method name (e.g., "Doc.GetAllSheets")
  • handle - Object handle (0 for Global, app_handle for Doc methods)
  • params - Method parameters as a list

Options

  • :timeout - Request timeout in ms (default: 30000)