Skip to content

Commit

Permalink
Merge pull request #19 from christopherjkim/steamlogins
Browse files Browse the repository at this point in the history
Stream update task now logs exceptions.
  • Loading branch information
Luke Curley committed Mar 6, 2012
2 parents 69ad6cc + 6e05a90 commit 04f48a3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions app/models/stream.rb
Expand Up @@ -9,16 +9,29 @@ class Stream < ActiveRecord::Base
validates_inclusion_of :provider, :in => PROVIDERS.values

def update_status
current_viewers = nil
current_status = nil
is_live = false
if self.provider == "justintv"
response = HTTParty.get("http://api.justin.tv/api/stream/list.xml?channel=#{identifier}")
current_viewers = response["streams"]["stream"]["channel_count"] rescue nil
current_status = response["streams"]["stream"]["channel"]["status"] rescue nil
self.update_attributes(:viewers => current_viewers, :live => !!current_viewers, :status => current_status)
begin
current_viewers = response["streams"]["stream"]["channel_count"]
current_status = response["streams"]["stream"]["channel"]["status"]
rescue Exception => e
logger.error e
ensure
self.update_attributes(:viewers => current_viewers, :live => !!current_viewers, :status => current_status)
end
elsif self.provider == "own3dtv"
response = HTTParty.get("http://api.own3d.tv/liveCheck.php?live_id=#{identifier}")
current_viewers = response["own3dReply"]["liveEvent"]["liveViewers"] rescue nil
is_live = response["own3dReply"]["liveEvent"]["isLive"] rescue false
self.update_attributes(:viewers => current_viewers, :live => is_live)
begin
current_viewers = response["own3dReply"]["liveEvent"]["liveViewers"]
is_live = response["own3dReply"]["liveEvent"]["isLive"]
rescue Exception => e
logger.error e
ensure
self.update_attributes(:viewers => current_viewers, :live => is_live)
end
end
end

Expand Down

0 comments on commit 04f48a3

Please sign in to comment.