elixir_google_spreadsheets v0.1.16 GSS.Client
Model of Client abstraction This process is a Producer for this GenStage pipeline.
Link to this section 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
Invoked when the server is started
Issues an HTTP request with the given method to the given url
Starts a task with request that must be awaited on
Link to this section Types
event()
event() :: {:request, GenStage.from(), GSS.Client.RequestParams.t()}
event() :: {:request, GenStage.from(), GSS.Client.RequestParams.t()}
partition()
partition() :: :write | :read
partition() :: :write | :read
Link to this section Functions
config(key, default \\ nil)
Read config settings scoped for GSS client.
dispatcher_hash(event)
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)
Invoked when the server is started.
start_link/3
(or start/3
) will block until this callback returns.
args
is the argument term (second argument) passed to start_link/3
(or start/3
).
In case of successful start, this callback must return a tuple where the first element is the stage type, which is one of:
:producer
:consumer
:producer_consumer
(if the stage is acting as both)
For example:
def init(args) do
{:producer, some_state}
end
The returned tuple may also contain 3 or 4 elements. The third
element may be the :hibernate
atom or a set of options defined
below.
Returning :ignore
will cause start_link/3
to return :ignore
and the process will exit normally without entering the loop or
calling terminate/2
.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without entering the loop or calling terminate/2
.
Options
This callback may return options. Some options are specific to the chosen stage type while others are shared across all types.
:producer
options
:demand
- when:forward
, the demand is always forwarded to thec:handle_demand/2
callback. When:accumulate
, demand is accumulated until its mode is set to:forward
viademand/2
. This is useful as a synchronization mechanism, where the demand is accumulated until all consumers are subscribed. Defaults to:forward
.
:producer
and :producer_consumer
options
:buffer_size
- the size of the buffer to store events without demand. Can be:infinity
to signal no limit on the buffer size. Check the "Buffer events" section of the module documentation. Defaults to10_000
for:producer
,:infinity
for:producer_consumer
.:buffer_keep
- returns whether the:first
or:last
entries should be kept on the buffer in case the buffer size is exceeded. Defaults to:last
.:dispatcher
- the dispatcher responsible for handling demands. Defaults toGenStage.DemandDispatch
. May be either an atom representing a dispatcher module or a two-element tuple with the dispatcher module and the dispatcher options.
:consumer
and :producer_consumer
options
:subscribe_to
- a list of producers to subscribe to. Each element represents either the producer module or a tuple with the producer module and the subscription options (as defined insync_subscribe/2
).
Callback implementation for GenStage.init/1
.
request(method, url, body \\ "", headers \\ [], options \\ [])
request(atom(), binary(), HTTPoison.body(), HTTPoison.headers(), Keyword.t()) ::
{:ok, HTTPoison.Response.t()} | {:error, binary()} | no_return()
request(atom(), binary(), HTTPoison.body(), HTTPoison.headers(), Keyword.t()) :: {:ok, HTTPoison.Response.t()} | {:error, binary()} | no_return()
Issues an HTTP request with the given method to the given url.
This function is usually used indirectly by get/3
, post/4
, put/4
, etc
Args:
method
- HTTP method as an atom (:get
,:head
,:post
,:put
,:delete
, etc.)url
- target url as a binary string or char listbody
- request body. See more belowheaders
- HTTP headers as an orddict (e.g.,[{"Accept", "application/json"}]
)options
- Keyword list of options
Body:
- binary, char list or an iolist
{:form, [{K, V}, ...]}
- send a form url encoded{:file, ~s(/path/to/file)}
- send a file{:stream, enumerable}
- lazily send a stream of binaries/charlists
Options:
:result_timeout
- receive result timeout, in milliseconds. Default is 2 minutes:timeout
- timeout to establish a connection, in milliseconds. Default is 8000:recv_timeout
- timeout used when receiving a connection. Default is 5000:proxy
- a proxy to be used for the request; it can be a regular url or a{Host, Port}
tuple:proxy_auth
- proxy authentication{User, Password}
tuple:ssl
- SSL options supported by thessl
erlang module:follow_redirect
- a boolean that causes redirects to be followed:max_redirect
- an integer denoting the maximum number of redirects to follow:params
- an enumerable consisting of two-item tuples that will be appended to the url as query string parameters
Timeouts can be an integer or :infinity
This function returns {:ok, response}
or {:ok, async_response}
if the
request is successful, {:error, reason}
otherwise.
Examples
request(:post, ~s(https://my.website.com), ~s({\"foo\": 3}), [{"Accept", "application/json"}])
request_async(method, url, body \\ "", headers \\ [], options \\ [])
request_async(
atom(),
binary(),
HTTPoison.body(),
HTTPoison.headers(),
Keyword.t()
) :: Task.t()
request_async( atom(), binary(), HTTPoison.body(), HTTPoison.headers(), Keyword.t() ) :: Task.t()
Starts a task with request that must be awaited on.
start_link()
start_link() :: GenServer.on_start()
start_link() :: GenServer.on_start()