Last active
December 25, 2015 05:48
-
-
Save adorr/6926662 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'oauth' | |
# KEY and SECRET are available in Desk.com Admin -> Settings -> API -> | |
# My Applications -> Key and Secret fields | |
KEY = "YOUR_OAUTH_KEY" | |
SECRET = "YOUR_OAUTH_SECRET" | |
SITE = "https://yoursite.desk.com" | |
# start the process by requesting a token | |
callback_url = "https://example.com/oauth/callback" | |
consumer = OAuth::Consumer.new(KEY, SECRET, site: SITE) | |
request_token = consumer.get_request_token(oauth_callback: callback_url) | |
# for demonstration purposes, visit this URL in your web browser and authorize | |
# the request. for a live application, redirect your user user to this URL | |
puts request_token.authorize_url(oauth_callback: callback_url) | |
# after the application is authorized, Desk.com will send a request to your | |
# callback_url with two parameters, oauth_token and oauth_verifier | |
oauth_token = "oauth_token_param" | |
oauth_verifier = "oauth_verifier_param" | |
# retrieve the access token | |
access_token = request_token.get_access_token(oauth_token: oauth_token, | |
oauth_verifier: oauth_verifier) | |
# send a GET request to Desk.com | |
access_token.get("/api/v2/cases") | |
# from here you can store the credentials to make requests in the future |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment