GSS.Client (elixir_google_spreadsheets v0.4.0)

Model of Client abstraction This process is a Producer for this GenStage pipeline.

Summary

Functions

Read config settings scoped for GSS client.

Divide request into to partitions :read and :write

Adds an event to the queue

Gives events for the next stage to process when requested

Callback implementation for GenStage.init/1.

Issues an HTTP request with the given method to the given URL using Finch.

Starts a task with request that must be awaited on.

Types

event()

@type event() :: {:request, GenStage.from(), GSS.Client.RequestParams.t()}

partition()

@type partition() :: :write | :read

Functions

config(key, default \\ nil)

@spec config(atom(), any()) :: any()

Read config settings scoped for GSS client.

dispatcher_hash(event)

@spec dispatcher_hash(event()) :: {event(), partition()}

Divide request into to partitions :read and :write

handle_call(arg, from, queue)

Adds an event to the queue

handle_demand(demand, queue)

Gives events for the next stage to process when requested

init(atom)

Callback implementation for GenStage.init/1.

request(method, url, body \\ "", headers \\ [], options \\ [])

@spec request(
  atom(),
  binary(),
  binary() | iodata(),
  [{binary(), binary()}],
  Keyword.t()
) ::
  {:ok, Finch.Response.t()} | {:error, Exception.t()}

Issues an HTTP request with the given method to the given URL using Finch.

This function is usually used indirectly by helper functions such as get/3, post/4, put/4, etc.

Arguments

  • method: HTTP method as an atom (e.g., :get, :head, :post, :put, :delete, etc.).
  • url: Target URL as a binary string.
  • body: Request body, which can be a binary, char list, or iodata. Special forms include:
    • {:form, [{K, V}, ...]} – to send a form URL-encoded payload.
    • {:file, "/path/to/file"} – to send a file.
    • {:stream, enumerable} – to lazily send a stream of binaries/char lists.
  • headers: HTTP headers as a list of two-element tuples (e.g., [{"Accept", "application/json"}]).
  • options: A keyword list of Finch options. Supported options include:
    • :timeout – Timeout (in milliseconds) for establishing a connection (default is 8000).
    • :recv_timeout – Timeout (in milliseconds) for receiving data (default is 5000).
    • :proxy – A proxy for the request; either a URL or a {host, port} tuple.
    • :proxy_auth – Proxy authentication credentials as {user, password}.
    • :ssl – SSL options as supported by Erlang’s ssl module.
    • :follow_redirect – Boolean to indicate if redirects should be followed.
    • :max_redirect – Maximum number of redirects to follow.
    • :params – Enumerable of two-item tuples to be appended to the URL as query string parameters.
    • Any other Finch-supported options can also be provided.

Timeout values can be specified as an integer or as :infinity.

Returns

  • On success, returns {:ok, %Finch.Response{}}.
  • On failure, returns {:error, reason} where reason is an exception.

Examples

request(:post, "https://my.website.com", "{"foo": 3}", [{"Accept", "application/json"}])

request_async(method, url, body \\ "", headers \\ [], options \\ [])

@spec request_async(
  atom(),
  binary(),
  binary() | iodata(),
  [{binary(), binary()}],
  Keyword.t()
) ::
  Task.t()

Starts a task with request that must be awaited on.

start_link(args \\ [])

@spec start_link(any()) :: GenServer.on_start()