Permalink
Browse files

shamelessly swipe styles from play

  • Loading branch information...
1 parent 4591c92 commit d4152d0e83d0270aeaf6a0a797fa8742262f0ea1 @jnewland committed Jun 28, 2012
Showing with 430 additions and 69 deletions.
  1. +1 −1 Procfile
  2. +94 −68 lib/nowplaying.rb
  3. +266 −0 lib/static/base.css
  4. BIN lib/static/images/bg-gray-noise.png
  5. +49 −0 lib/static/reset.css
  6. +20 −0 lib/static/style.css
View
@@ -1 +1 @@
-web: bundle exec ruby lib/nowplaying.rb
+web: bundle exec ruby lib/nowplaying.rb -p $PORT
View
@@ -24,81 +24,107 @@
$LOAD_PATH << './lib'
require 'rdio'
-RDIO_CONSUMER_KEY = ENV['RDIO_CONSUMER_KEY']
+RDIO_CONSUMER_KEY = ENV['RDIO_CONSUMER_KEY']
RDIO_CONSUMER_SECRET = ENV['RDIO_CONSUMER_SECRET']
+POLL_INTERVAL = ENV['POLL_INTERVAL']
-class App < Sinatra::Base
- enable :sessions
- get '/' do
- access_token = session[:at]
- access_token_secret = session[:ats]
- if access_token and access_token_secret
- rdio = Rdio.new([RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET],
- [access_token, access_token_secret])
-
- user_key = rdio.call('currentUser')['result']['key']
- play_data = rdio.call('get', { :keys => user_key, :extras => 'lastSongPlayed,lastSongPlayTime'})['result'][user_key]
-
- play_time = play_data['lastSongPlayTime']
- song_key = play_data['lastSongPlayed']['key']
-
- song = rdio.call('get', { :keys => song_key, :extras => 'bigIcon'})['result'][song_key]
-
- response = "
- <html><head><title>Now Playing</title></head><body>
- <img src='%s' />
- <h1>%s</h1>
- <h2>%s</h2>
- <h3>%s</h3>
- " % [song['bigIcon'], song['name'], song['album'], song['artist']]
- response += '</body></html>'
- return response
- else
- redirect to('/login')
- end
- end
- get '/login' do
- session.clear
- # begin the authentication process
- rdio = Rdio.new([RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET])
- callback_url = (URI.join request.url, '/callback').to_s
- url = rdio.begin_authentication(callback_url)
- # save our request token in the session
- session[:rt] = rdio.token[0]
- session[:rts] = rdio.token[1]
- # go to Rdio to authenticate the app
- redirect url
- end
+enable :sessions
+
+set :public_folder, File.dirname(__FILE__) + '/static'
+
+get '/' do
+ access_token = session[:at]
+ access_token_secret = session[:ats]
+ if access_token and access_token_secret
+ rdio = Rdio.new([RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET],
+ [access_token, access_token_secret])
+
+ user_key = rdio.call('currentUser')['result']['key']
+ play_data = rdio.call('get', { :keys => user_key, :extras => 'lastSongPlayed,lastSongPlayTime'})['result'][user_key]
+
+ play_time = play_data['lastSongPlayTime']
+ song_key = play_data['lastSongPlayed']['key']
+
+ song = rdio.call('get', { :keys => song_key, :extras => 'bigIcon'})['result'][song_key]
+
+ response = "
+<!DOCTYPE html>
+
+<head>
- get '/callback' do
- # get the state from cookies and the query string
- request_token = session[:rt]
- request_token_secret = session[:rts]
- verifier = params[:oauth_verifier]
- # make sure we have everything we need
- if request_token and request_token_secret and verifier
- # exchange the verifier and request token for an access token
- rdio = Rdio.new([RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET],
- [request_token, request_token_secret])
- rdio.complete_authentication(verifier)
- # save the access token in cookies (and discard the request token)
- session[:at] = rdio.token[0]
- session[:ats] = rdio.token[1]
- session.delete(:rt)
- session.delete(:rts)
- # go to the home page
- redirect to('/')
- else
- # we're missing something important
- redirect to('/logout')
- end
+<meta charset='utf-8'>
+<meta name='apple-mobile-web-app-capable' content='yes'>
+<meta http-equiv='refresh' content='%s' />
+
+<link rel='stylesheet' href='/reset.css'>
+<link rel='stylesheet' href='/base.css'>
+<link rel='stylesheet' href='/style.css'>
+
+<link href='//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,700,600' rel='stylesheet' type='text/css'>
+<link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
+
+
+<title>Now Playing</title>
+
+</head>
+
+<body>
+<section id='now-playing' class='row'>
+<ul>
+ <li class='name'>%s</li>
+ <li class='artist'><em>by</em> %s</li>
+ <li class='album'><em>from</em> %s</li>
+</ul>
+<img src='%s' class='album-art' />
+</section>
+<body>
+ " % [POLL_INTERVAL, song['name'], song['artist'], song['album'], song['bigIcon']]
+ response += '</body></html>'
+ return response
+ else
+ redirect to('/login')
end
+end
+
+get '/login' do
+ session.clear
+ # begin the authentication process
+ rdio = Rdio.new([RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET])
+ callback_url = (URI.join request.url, '/callback').to_s
+ url = rdio.begin_authentication(callback_url)
+ # save our request token in the session
+ session[:rt] = rdio.token[0]
+ session[:rts] = rdio.token[1]
+ # go to Rdio to authenticate the app
+ redirect url
+end
- get '/logout' do
- session.clear
+get '/callback' do
+ # get the state from cookies and the query string
+ request_token = session[:rt]
+ request_token_secret = session[:rts]
+ verifier = params[:oauth_verifier]
+ # make sure we have everything we need
+ if request_token and request_token_secret and verifier
+ # exchange the verifier and request token for an access token
+ rdio = Rdio.new([RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET],
+ [request_token, request_token_secret])
+ rdio.complete_authentication(verifier)
+ # save the access token in cookies (and discard the request token)
+ session[:at] = rdio.token[0]
+ session[:ats] = rdio.token[1]
+ session.delete(:rt)
+ session.delete(:rts)
+ # go to the home page
redirect to('/')
+ else
+ # we're missing something important
+ redirect to('/logout')
end
end
-App.run! :host => 'localhost', :port => ENV['PORT']
+get '/logout' do
+ session.clear
+ redirect to('/')
+end
Oops, something went wrong. Retry.

0 comments on commit d4152d0

Please sign in to comment.