Skip to content

Commit

Permalink
Updated Justin.tv api requests to use OAuth authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
dy-dx committed Jun 9, 2012
1 parent 29b073a commit 5976f28
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -52,6 +52,6 @@ gem 'prototype_legacy_helper', '0.0.0', :git => 'git://github.com/rails/prototyp


# Omniauth OpenID for Steam Integration # Omniauth OpenID for Steam Integration
gem "omniauth-openid", "~> 1.0.1" gem "omniauth-openid", "~> 1.0.1"

gem "oauth", "~> 0.3.6"
gem "steam-condenser" gem "steam-condenser"
gem "httparty", "~> 0.8.1" gem "httparty", "~> 0.8.1"
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -99,6 +99,8 @@ GEM
multi_json (1.3.6) multi_json (1.3.6)
multi_xml (0.5.1) multi_xml (0.5.1)
netrc (0.7.2) netrc (0.7.2)
oauth (0.3.6)
ruby-hmac (>= 0.3.1)
omniauth (1.1.0) omniauth (1.1.0)
hashie (~> 1.2) hashie (~> 1.2)
rack rack
Expand Down Expand Up @@ -151,6 +153,7 @@ GEM
json (~> 1.4) json (~> 1.4)
rest-client (1.6.7) rest-client (1.6.7)
mime-types (>= 1.16) mime-types (>= 1.16)
ruby-hmac (0.4.0)
ruby-openid (2.1.8) ruby-openid (2.1.8)
rubyzip (0.9.8) rubyzip (0.9.8)
sass (3.1.19) sass (3.1.19)
Expand Down Expand Up @@ -200,6 +203,7 @@ DEPENDENCIES
machinist (>= 2.0.0.beta2) machinist (>= 2.0.0.beta2)
meta_search (~> 1.1.1) meta_search (~> 1.1.1)
mocha (~> 0.9.12) mocha (~> 0.9.12)
oauth (~> 0.3.6)
omniauth-openid (~> 1.0.1) omniauth-openid (~> 1.0.1)
paperclip (~> 2.4.0) paperclip (~> 2.4.0)
pg pg
Expand Down
18 changes: 15 additions & 3 deletions app/models/stream.rb
Expand Up @@ -13,12 +13,24 @@ def perform
current_status = nil current_status = nil
is_live = false is_live = false


jtv_key = Settings.justintv_consumer_key
jtv_secret = Settings.justintv_secret_key
jtv_consumer = OAuth::Consumer.new(jtv_key, jtv_secret,
:site => "http://api.justin.tv",
:http_method => :get)

# make the access token from your consumer
jtv_access_token = OAuth::AccessToken.new jtv_consumer


if self.provider == "justintv" if self.provider == "justintv"
response = HTTParty.get("http://api.justin.tv/api/stream/list.xml?channel=#{identifier}")
# make a signed request!
response = ActiveSupport::JSON.decode(jtv_access_token.get("/api/stream/list.json?channel=#{identifier}").body)


begin begin
current_viewers = response["streams"]["stream"]["channel_count"] current_viewers = response[0]["channel_count"]
current_status = response["streams"]["stream"]["channel"]["status"] current_status = response[0]["channel"]["status"]
rescue Exception => e rescue Exception => e
logger.error e logger.error e
ensure ensure
Expand Down
4 changes: 3 additions & 1 deletion config/settings/development.example.yml
@@ -1,4 +1,6 @@
session_key: eldorado_development session_key: eldorado_development
session_secret: ESl6X3oKM1i1RRrD2QLwUUzz9jr1zxNO session_secret: ESl6X3oKM1i1RRrD2QLwUUzz9jr1zxNO
domain: http://example.com domain: http://example.com
steam_api_key: steam_api_key:
justintv_consumer_key:
justintv_secret_key:
4 changes: 4 additions & 0 deletions config/settings/production.example.yml
Expand Up @@ -41,3 +41,7 @@ disabled_tabs: # list tabs that want to hide from users (e.g. "blog events heade


# STEAM # STEAM
steam_api_key: steam_api_key:

# Justin.tv
justintv_consumer_key:
justintv_secret_key:
4 changes: 3 additions & 1 deletion config/settings/test.example.yml
@@ -1,4 +1,6 @@
session_key: eldorado_test session_key: eldorado_test
session_secret: vrwPpJTvwnMVLP1wTSgqigSl7PMI7QcE session_secret: vrwPpJTvwnMVLP1wTSgqigSl7PMI7QcE
domain: http://example.com domain: http://example.com
steam_api_key: steam_api_key:
justintv_consumer_key:
justintv_secret_key:

0 comments on commit 5976f28

Please sign in to comment.