Skip to content

Instantly share code, notes, and snippets.

@alanzhao
Created September 27, 2012 01:45
Show Gist options
  • Save alanzhao/3791706 to your computer and use it in GitHub Desktop.
Save alanzhao/3791706 to your computer and use it in GitHub Desktop.
subscription service
require 'sinatra'
require 'youtube_it'
get '/ytsubscription' do
uid = params[:uid] # e.g. [email protected]
provider = params[:provider] # e.g. google_oauth2
channels = params[:channels].split(',')
callback = params[:callback]
failure_url = params[:failure_url]
account = get_cassandra_row(uid, provider)
access_token = account['access_token']
refresh_token = account['refresh_token']
expiration = account['valid_thru']
client = YouTubeIt::OAuth2Client.new(
client_access_token: access_token,
client_refresh_token: refresh_token,
client_id: "client_id",
client_secret: "client_secret",
dev_key: "dev_key",
expires_at: expiration
)
begin
channels.each do |channel|
client.subscribe_channel(channel)
end
rescue Exception => ex
redirect_to failure_url
end
redirect_to callback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment