Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fc73c38eab
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (49 sloc) 1.309 kb
require "sinatra"
require 'json'
require 'net/http'
require 'cgi'
require "./soundcloud"
require "./facebook"
require "./user"
require "./helpers"
enable :sessions
# Redirect to HTTPS if necessary
before do
if settings.environment == :production && request.scheme != 'https'
redirect "https://#{request.env['HTTP_HOST']}"
end
end
# Shows a list of recent plays on SoundCloud
get "/" do
begin
if user
# Logged in users have a Facebook connection
@actions = user.facebook.get('/me/soundcloud:listen')['data']
end
# rendering html template
erb :index
# Access Token is expired, so we reauth the user on Facebook
rescue Facebook::OAuthException
redirect auth_url
end
end
# Redirect posts from Facebook Canvas Page
post "/" do
redirect "/"
end
# Callback endpoint for server side flow
# Takes a OAuth code parameter and creates a user if necessary
get "/auth" do
client = Facebook.exchange_code(params[:code], url('/auth'))
user = User.from_facebook(client)
session[:user] = user.uid
redirect '/'
end
# Login endpoint for client side flow
# Takes a token paremeter and creates a user if necessary
post "/auth" do
client = Facebook.exchange_token(params[:token])
user = User.from_facebook(client)
session[:user] = user.uid
redirect '/'
end
Jump to Line
Something went wrong with that request. Please try again.