Giter VIP home page Giter VIP logo

twerl's Introduction

Twerl

Build Status

An Erlang client for the Twitter Streaming API.

Important notice: As is this library isn't currently usable since Twitter deprecated basic auth. OAuth support is WIP, see the oauth branch and issue for further details.

Goals

  • A lightweight client which can consume the Twitter Streaming API.
  • A client manager which allows you to change the search queries without losing any data (WIP).

Usage

You probably want to include it as a depedency in Rebar:

{deps,
  [
    {twerl, ".*", {git, "https://github.com/lucaspiller/twerl.git", "master"}},
  ]
}.

Client

Generate auth headers:

Headers = stream_client_util:generate_auth_headers(TwitterUsername, TwitterPassword).

Generate params:

{ok, Params} = stream_client_util:keywords_to_track(["erlang"]).

Build a callback function:

Callback = fun(Data) ->
  Tweet = proplists:get_value(<<"text">>, Data),
  io:format("Erlang <3: ~s~n", [Tweet])
end.

Start streaming:

stream_client:connect(stream_client_util:filter_url(), Headers, Params, Callback).

Manager

The function stream_client:connect/4 blocks, and only returns once the stream ends. You can use the manager which is a simple gen_server which wraps the functionality and adds some nice additions, such as allowing you to change filter params and the callback.

Start the manager:

stream_client_manager:start_link(awesomeness).

Set auth headers:

Headers = stream_client_util:generate_auth_headers(TwitterUsername, TwitterPassword),
stream_client_manager:set_headers(awesomeness, Headers).

Set params:

{ok, Params} = stream_client_util:keywords_to_track(["erlang"]),
stream_client_manager:set_params(awesomeness, Params).

Start streaming (you can set a callback after, and change it without losing data):

stream_client_manager:start_stream(awesomeness).

Set a callback:

stream_client_manager:set_params(awesomeness, fun(Data) ->
  Tweet = proplists:get_value(<<"text">>, Data),
  io:format("Erlang <3: ~s~n", [Tweet])
end).

Stop streaming:

stream_client_manager:stop_stream(awesomeness).

Stop the manager:

stream_client_manager:stop(awesomeness).

One of the goals is to be able to change the filter params without losing any data. This is still WIP as data could be lost or duplicated.

Development

Start an Erlang shell with reloader support:

make dev

Compile new code:

make compile

Run tests (written in espec):

make test

Contributing

  • Fork the project.
  • Make your feature addition or bug fix.
  • Use the same indentation (4 spaces).
  • Add a line to CHANGELOG.md describing your change.
  • Add tests. Pull requests without tests will be ignored.
  • Send me a pull request. Bonus points for topic branches.

License

MIT License. See LICENSE.md for details.

Copyright

Copyright (c) 2011-2013 Luca Spiller.

twerl's People

Contributors

lucaspiller avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.