Created
July 28, 2012 20:27
-
-
Save pdarche/3194679 to your computer and use it in GitHub Desktop.
This is a Sinatra route that handles authentication and access to the open paths api using the oauth2 gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/op' do | |
consumer_key = 'key' | |
consumer_secret = 'secret' | |
url = 'https://openpaths.cc/' | |
now = Time.now | |
#instantiate client | |
client = OAuth2::Client.new(consumer_key, consumer_secret, :site => url) | |
#create token | |
token = OAuth2::AccessToken.from_hash(client, :access_token => consumer_secret) | |
#make signed request | |
response = token.get('/api/1', :params => { 'start_time' => now - 24*60*60, 'end_time' => now}) | |
end | |
# oauth AccessToken class: https://github.com/intridea/oauth2/blob/master/lib/oauth2/access_token.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment