YahooFinanceEx.Session (YahooFinanceEx v0.1.0)

Copy Markdown View Source

Holds Yahoo Finance auth state (cookie + CSRF crumb) for the running app.

Yahoo's public API gates calls behind a per-session cookie and a crumb token that must be present on every request. This GenServer owns both, refreshes them when needed, and exposes a lookup function callers use before each HTTP call.

Two strategies for obtaining a valid (cookie, crumb) pair are tried in order before giving up. Both rely on Req and are stubbable in tests via Req.Test.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns {:ok, %Credentials{}} with a fresh-enough session, refreshing if the cached credentials are missing or expired.

Marks the session as invalid so the next credentials/0 call re-authenticates. Called after a 401 or auth-error response.

Starts the session GenServer. Started under the package's supervisor at app boot; not typically called directly.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

credentials(server \\ __MODULE__)

@spec credentials(GenServer.server()) ::
  {:ok, YahooFinanceEx.Session.Credentials.t()} | {:error, term()}

Returns {:ok, %Credentials{}} with a fresh-enough session, refreshing if the cached credentials are missing or expired.

invalidate(server \\ __MODULE__)

Marks the session as invalid so the next credentials/0 call re-authenticates. Called after a 401 or auth-error response.

start_link(opts \\ [])

Starts the session GenServer. Started under the package's supervisor at app boot; not typically called directly.