Coder Social home page Coder Social logo

rackatweet's Introduction

Rackatweet - Tweets as JSON via a rack app

A very simple rack app to provide a twitter timeline as JSON.

Install

Rails

In Gemfile

gem 'rackatweet'

In routes.rb

<AppName>::Application.routes.draw do
  match "/tweets.json", :to => Rackatweet::App.new
end

OAuth

Create a twitter application at: https://dev.twitter.com/apps

Make a note of your consumer_key, consumer_secret, oauth_token, and oauth_token_secret

If you are using Rails, then create an initializer like:

if defined?(Rackatweet)
  Rackatweet::Config.consumer_key = ENV['CONSUMER_KEY']
  Rackatweet::Config.consumer_secret = ENV['CONSUMER_SECRET']
  Rackatweet::Config.oauth_token = ENV['OAUTH_TOKEN']
  Rackatweet::Config.oauth_token_secret = ENV['OAUTH_TOKEN_SECRET']
  Rackatweet::Config.timeout = ENV['TIMEOUT'] # optional - default is 10s
  Rackatweet::Config.cache_expires_in = ENV['CACHE_EXPIRES_IN'] # optional - default is 900s (15 minutes)
end

Start the rails server in development:

CONSUMER_KEY=XXX CONSUMER_SECRET=XXX OAUTH_TOKEN=XXX OAUTH_TOKEN_SECRET=XXX rails server

Or on heroku add the following config variables:

CONSUMER_KEY
CONSUMER_SECRET
OAUTH_TOKEN
OAUTH_TOKEN_SECRET

The OAUTH token should never expire. The rack app will make the access token request only once. So if you restart the server it will happen again.

Optionally set the TIMEOUT variable

TIMEOUT=10 sets the timeout to 10s when accessing the twitter API, the default is 10 (accepts float or integer value)

Optionally set the CACHE_EXPIRES_IN variable

CACHE_EXPIRES_IN=3600 sets the cache of tweets to expire in 1 hour. After 1 hour, the Twitter API will be hit again

Twitter API Params

You can use any of the twitter API params in the URL like:

GET '/tweets.json?count=2&screen_name=kev_the_dev

See: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

Valid params:

count
user_id
screen_name
since_id
max_id
trim_user
exclude_replies
contributor_details
include_rts

Responses:

Successful response:

{
  "tweets": []
}

Error:

{
  "errors": ["message": "Error message", "code": statusCode]
}

Errors returned by the twitter API are handled as above.

There are two additional errors, SocketError & TimeoutError both with a statusCode of 500

Thanks!

To Beef the benefactors of this project.

& Jordan Elver for the idea

rackatweet's People

Contributors

kevthedev avatar

Stargazers

Eric Skogen avatar Anatoly Chernov avatar Craig Coles avatar

Watchers

 avatar Anatoly Chernov avatar

Forkers

beef

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.