Skip to content

Commit

Permalink
Make Tfl widget use async HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
pusewicz committed Apr 21, 2010
1 parent da869f5 commit 33c0f65
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/sonia/widgets/tfl.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'yajl'
require 'httparty'
require 'em-http'

module Sonia
module Widgets
class Tfl < Sonia::Widget

def initial_push
fetch_data
EventMachine::add_periodic_timer(150) { fetch_data }
Expand All @@ -22,11 +21,14 @@ def format_lines(line)

private
def fetch_data
lines = Yajl::Parser.parse(HTTParty.get(config[:url]).to_s)["response"]["lines"].map do |line|
format_lines(line)
end
http = EventMachine::HttpRequest.new(config[:url]).get
http.callback {
lines = Yajl::Parser.parse(http.response)["response"]["lines"].map do |line|
format_lines(line)
end

push lines
push lines
}
end
end
end
Expand Down

0 comments on commit 33c0f65

Please sign in to comment.