Class: Twinkies::Server
- Inherits:
-
Object
- Object
- Twinkies::Server
- Defined in:
- lib/twinkies/server.rb
Instance Method Summary collapse
- #handle_request ⇒ Object
-
#initialize(config) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #setup_db ⇒ Object
- #start_tweet_refresher ⇒ Object
Constructor Details
#initialize(config) ⇒ Server
Returns a new instance of Server.
5 6 7 8 9 |
# File 'lib/twinkies/server.rb', line 5 def initialize(config) @tweet_db = config.tweet_db @username = config.username @password = config.password end |
Instance Method Details
#handle_request ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/twinkies/server.rb', line 33 def handle_request username = @username # builder must instance_eval? get '/feed.xml' do builder do |xml| xml.instruct! xml.rss :version => '2.0' do xml.channel do xml.title "#{username}'s twitter URL feed" xml.description "#{username}'s twitter URL feed" xml.link "http://twitter.com/#{username}" Item.latest.each do |tweet| xml.item do xml.title "#{tweet.user} - #{tweet.text}" xml.link tweet.link xml.pubDate tweet.created_at xml.guid tweet.id, :isPermaLink => false end end end end end end end |
#run ⇒ Object
11 12 13 14 15 |
# File 'lib/twinkies/server.rb', line 11 def run setup_db start_tweet_refresher handle_request end |
#setup_db ⇒ Object
17 18 19 20 |
# File 'lib/twinkies/server.rb', line 17 def setup_db DataMapper.setup(:default, "sqlite3://#{@tweet_db}") DataMapper.auto_upgrade! end |
#start_tweet_refresher ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/twinkies/server.rb', line 22 def start_tweet_refresher Thread.abort_on_exception = true Thread.new do loop do puts "refreshing tweets..." Item.refresh @username, @password sleep 60 end end end |