Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Created May 3, 2013 01:17
Show Gist options
  • Save jonmarkgo/5506611 to your computer and use it in GitHub Desktop.
Save jonmarkgo/5506611 to your computer and use it in GitHub Desktop.
get "/oauth2authorize" do
redirect @client.authorization.authorization_uri.to_s, 303
end
get "/oauth2callback" do
@client.authorization.fetch_access_token!
token_pair = if session[:token_id]
TokenPair.get(session[:token_id])
else
TokenPair.new
end
token_pair.update_token!(@client.authorization)
numbers = @twilio.account.available_phone_numbers.get('US').local.list
@twilio.account.incoming_phone_numbers.create(:phone_number => numbers[0].phone_number, :sms_url => "#{@base_url}/receivesms")
token_pair.phone_number = numbers[0].phone_number
token_pair.save
session[:token_id] = token_pair.id
subscription = @glass.subscriptions.insert.request_schema.new({
"collection" => "timeline",
"userToken" => token_pair.id,
"verifyToken" => "monkey",
"callbackUrl" => "#{@base_url}/subcallback",
"operation" => ["INSERT"]})
result = @client.execute(
:api_method => @glass.subscriptions.insert,
:body_object => subscription)
redirect to("/")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment