Skip to content

Instantly share code, notes, and snippets.

@YenTheFirst
Created February 1, 2011 04:02
Show Gist options
  • Save YenTheFirst/805395 to your computer and use it in GitHub Desktop.
Save YenTheFirst/805395 to your computer and use it in GitHub Desktop.
a simple rack app, that wraps 'status' rss calls to twitter with the necessary oauth
require 'simple_oauth'
require 'net/http'
require 'rack'
class GetTwitterRSS
@@consumer_secrets={:consumer_key=>"<<YOUR_KEY>>",:consumer_secret=>"<<YOUR_SECRET>>}
@@user_secrets={"username
1"=>{:token_secret=>"<<TOKEN_SECRET>>",:token=>"<<ACCESS_TOKEN>>"}}
@@base="api.twitter.com"
def call(env)
return [500,{"content-type"=>"text/plain"},"format: /user/action.format"] unless mch=env["PATH_INFO"].match(/\/(\w+)\/(\w+)\.(\w+)/)
user,action,format=mch[1,3]
return [404,{"content-type"=>"text/plain"},"user #{user.downcase} not in system"] unless @@user_secrets[user]
path="/1/statuses/#{action}.#{format}"
h=SimpleOAuth::Header.new("get","http://#{@@base}#{path}",{},@@consumer_secrets.merge(@@user_secrets[user.downcase]))
Net::HTTP.start(@@base) do |http|
res=http.get(path,{"Authorization"=>h.to_s})
headers=res.to_hash
headers.delete("status")
headers.merge!(headers) {|k,v| v*","}
[res.code.to_i,headers,[res.body]]
end
end
end
require 'rack'
require 'get_twitter_rss.rb'
run GetTwitterRSS.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment