Noizu.Google.Client (Noizu Google v0.2.3)

Copy Markdown View Source

Client configuration for Google API calls.

Prefer building a client once and passing it via opts:

client = Noizu.Google.Client.new(access_token: System.fetch_env!("GOOGLE_ACCESS_TOKEN"))
Noizu.Google.Api.SearchConsole.Sites.list(client: client)

When client is omitted, a default client is built from application config (:noizu_google).

Summary

Functions

Default client from application config.

Ensure a usable access token, refreshing when only a refresh_token is set.

Build a client from keyword options merged over application env defaults.

Normalize API base URL (trailing slash).

Return a client with an updated access token.

Ensure the client has an access token.

Types

t()

@type t() :: %Noizu.Google.Client{
  access_token: String.t() | nil,
  adsense_base: String.t(),
  analytics_admin_base: String.t(),
  analytics_data_base: String.t(),
  api_base: String.t(),
  authorize_url: String.t(),
  client_id: String.t() | nil,
  client_secret: String.t() | nil,
  finch: atom(),
  google_ads_base: String.t(),
  oauth_base: String.t(),
  pool_timeout: pos_integer(),
  receive_timeout: pos_integer(),
  refresh_token: String.t() | nil,
  webmasters_base: String.t()
}

Functions

default()

@spec default() :: t()

Default client from application config.

ensure_access_token(client)

@spec ensure_access_token(t()) :: {:ok, t()} | {:error, Noizu.Google.Error.t()}

Ensure a usable access token, refreshing when only a refresh_token is set.

Returns {:ok, client} with access_token populated, or an error.

new(opts \\ [])

@spec new(keyword() | map()) :: t()

Build a client from keyword options merged over application env defaults.

normalize_base(base)

@spec normalize_base(String.t()) :: String.t()

Normalize API base URL (trailing slash).

put_access_token(client, token)

@spec put_access_token(t(), String.t()) :: t()

Return a client with an updated access token.

require_token(client)

@spec require_token(t()) :: {:ok, t()} | {:error, Noizu.Google.Error.t()}

Ensure the client has an access token.

Returns {:ok, client} or {:error, %Noizu.Google.Error{}}.