Twittex v0.2.0 Twittex.Client.Base
A behaviour module for implementing your own Twitter client.
It implements the GenServer
behaviour, and keeps the authentication state
during the entire process livetime.
Example
To create a client, create a new module and use Twittex.Client.Base
as follow:
defmodule TwitterBot do
use Twittex.Client.Base
def search(term, options \ []) do
get "/search/tweets.json?" <> URI.encode_query(Dict.merge(%{q: term}, options))
end
end
This client works as a singleton and can be added to a supervisor tree:
worker(TwitterBot, [])
And this is how you may use it:
iex> TwitterBot.search "#myelixirstatus", count: 3
{:ok, %{}}
Summary
Functions
Issues a GET request to the given url
Same as get/4
but raises HTTPoison.Error
if an error occurs during the
request
Issues a POST request to the given url
Same as post/5
but raises HTTPoison.Error
if an error occurs during the
request
Streams data from the given url
Same as stage/6
but raises HTTPoison.Error
if an error occurs during the
request
Starts the process linked to the current process
Functions
Specs
get(pid, String.t, Twittex.API.headers, Keyword.t) ::
{:ok, %{}} |
{:error, HTTPoison.Error.t}
Issues a GET request to the given url.
Returns {:ok, response}
if the request is successful, {:error, reason}
otherwise.
See Twittex.API.request/5
for more detailed information.
Specs
get!(pid, String.t, Twittex.API.headers, Keyword.t) :: %{}
Same as get/4
but raises HTTPoison.Error
if an error occurs during the
request.
Specs
post(pid, String.t, binary, Twittex.API.headers, Keyword.t) ::
{:ok, %{}} |
{:error, HTTPoison.Error.t}
Issues a POST request to the given url.
Returns {:ok, response}
if the request is successful, {:error, reason}
otherwise.
See Twittex.API.request/5
for more detailed information.
Specs
post!(pid, String.t, binary, Twittex.API.headers, Keyword.t) :: %{}
Same as post/5
but raises HTTPoison.Error
if an error occurs during the
request.
Specs
stage(pid, Atom.t, String.t, binary, Twittex.API.headers, Keyword.t) ::
{:ok, Twittex.Client.Stream.t} |
{:error, HTTPoison.Error.t}
Streams data from the given url.
Returns {:ok, stage}
if the request is successful, {:error, reason}
otherwise.
Specs
stage!(pid, Atom.t, String.t, binary, Twittex.API.headers, Keyword.t) :: Twittex.Client.Stream.t
Same as stage/6
but raises HTTPoison.Error
if an error occurs during the
request.
Specs
start_link(Keyword.t) :: GenServer.on_start
Starts the process linked to the current process.
Options
:username
- Twitter username or email address:password
- Twitter password
Other options are passed to GenServer._start_link/1
.