Tw

CI

Docs

Twitter API Client for elixir.

Installation

The package can be installed by adding tw to your list of dependencies in mix.exs:

def deps do
  [
    {:jason, "~> 1.2"},   # only if you choose jason
    {:hackney, "~> 1.0"}, # only if you choose hackney
    {:tw, "~> 0.1.2"}
  ]
end

Examples

Twitter API v1.1

alias Tw.OAuth.
alias Tw.V1_1.Client
alias Tw.V1_1.Tweet

credentials = OAuth.V1_0a.Credentials.new(
  consumer_key: "xxx",
  consumer_secret: "xxx",
  access_token: "xxx",
  access_token_secret: "xxx",
)
client = Client.new(
  credentials: credentials,
)
{:ok, [%Tweet{} | _]} = Tweet.home_timeline(client, %{count: 10})

There are functions which wrap API endpoints. They provide functionality below.

If the corresponding function is not implemented for your desired endpoint, or if the above is unnecessary/problematic, the Client can be used as is.

alias Tw.V1_1.Client
{:ok, result_map} = Client.request(client, :get, "/foo/bar.json", %{param_1: 2})

HTTP Client is replacable

You can use whichever HTTP client you want as long as it implements Tw.HTTP.Client (inspired by the greate Goth redesign article).

JSON encoder/decoder is replacable

You can also switch JSON encode/decoder to another one as long as it implements Tw.JSON.Serializer.

Development

Generate base code from Twitter v1.1 documentation

$ elixir bin/codegen.exs endpoint 'GET statuses/home_timeline' home_timeline

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/tw.