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
@type t() :: GenServer.server() | PorscheConnEx.Session.RequestData.t()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec request_data(GenServer.server() | PorscheConnEx.Session.RequestData.t()) :: PorscheConnEx.Session.RequestData.t()
Returns a session's configuration and authentication details.
Arguments
pid_or_rdatacan be either- the PID of a running
Sessionprocess, - the registered name of a running
Sessionprocess, or - an existing
PorscheConnEx.Session.RequestDatastructure.
- the PID of a running
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 containingusername(required) - your Porsche Connect usernamepassword(required) - your Porsche Connect password
config(optional) - a keyword list, a map, or aPorscheConnEx.Configstructure- 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.