Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pdarche/3194679 to your computer and use it in GitHub Desktop.
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
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