View Source PorscheConnEx.Session (porsche_conn_ex v0.1.0)

Handles configuration and authentication of an API session.

Starting a session will acquire an access token from the Porsche Connect API at startup, and then acquire a new token whenever the current token is nearing expiry. It also serves as stateful storage of the PorscheConnEx.Config structure used to configure the session.

All PorscheConnEx.Client calls require both HTTP authentication headers and the PorscheConnEx.Config structure, which are bundled together into a PorscheConnEx.Session.RequestData structure.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns a session's configuration and authentication details.

Starts a session and authenticates with the API.

Types

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

request_data(pid_or_rdata)

View Source

Returns a session's configuration and authentication details.

Arguments

  • pid_or_rdata can be either

Return value

Returns a PorscheConnEx.Session.RequestData structure containing the starting configuration and current authentication details associated with the session.

If given an existing RequestData structure, then that structure will be returned verbatim. This means that PorscheConnEx.Client calls can all effectively also receive a RequestData structure as their first argument, in lieu of a running session. (This is used in e.g. PorscheConnEx.Client.wait/2 to avoid unnecessary requests.)

Beware that authentication tokens do expire, and you should not use a given RequestData structure for more than a few minutes before fetching another.

@spec start_link(Keyword.t()) :: GenServer.on_start()

Starts a session and authenticates with the API.

Options

  • credentials (required) - a keyword list or map containing
    • username (required) - your Porsche Connect username
    • password (required) - your Porsche Connect password
  • config (optional) - a keyword list, a map, or a PorscheConnEx.Config structure
    • see that module for fields and other details

This function also accepts all the options accepted by GenServer.start_link/3.

Return values

Same as GenServer.start_link/3. Note that this function will block until the initial API authentication is complete.