Twittex v0.2.2 Twittex.Client.Base

A behaviour module for implementing your own Twitter client.

It implements the GenServer behaviour, authenticates when starting and keeps the authentication token in it state during the entire process livetime.

Example

To create your own 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 here’s 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

Same as stage/6 but raises HTTPoison.Error if an error occurs during the request

Starts the process as part of a supervision tree

Functions

get(pid, url, headers \\ [], options \\ [])
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.

get!(pid, url, headers \\ [], options \\ [])
get!(pid, String.t, Twittex.API.headers, Keyword.t) :: %{}

Same as get/4 but raises HTTPoison.Error if an error occurs during the request.

post(pid, url, body \\ [], headers \\ [], options \\ [])
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.

post!(pid, url, body, headers \\ [], options \\ [])
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.

stage(pid, method, url, body \\ [], headers \\ [], options \\ [])

Streams data from the given url.

Returns {:ok, stage} if the request is successful, {:error, reason} otherwise.

stage!(pid, method, url, body \\ [], headers \\ [], options \\ [])

Same as stage/6 but raises HTTPoison.Error if an error occurs during the request.

start_link(options \\ [])
start_link(Keyword.t) :: GenServer.on_start

Starts the process as part of a supervision tree.

Options

  • :username - Twitter username or email address
  • :password - Twitter password

Other options are passed to GenServer._start_link/1.