Created
February 26, 2014 00:38
-
-
Save tbrooke/9221063 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'clio_client' | |
require 'date' | |
def token_file; "ClioToken.txt"; end | |
saved_token = nil | |
client_id = "YOUR-APP-KEY-HERE" | |
client_secret = "YOUR-APP-SECRET-HERE" | |
client = ClioClient::Session.new({client_id: client_id, client_secret: client_secret}) | |
if File.exists?(token_file) | |
file = File.open(token_file, "r") | |
saved_token = file.gets | |
file.close | |
end | |
if saved_token | |
client.access_token = saved_token | |
else | |
puts "Paste following URL in a browser and accept the connection" | |
puts "https://app.goclio.com/oauth/authorize?response_type=code&client_id=#{client_id}&redirect_uri=https%3A%2F%2Fapp.goclio.com%2Foauth%2Fapproval\n" | |
client.authorize_url("https://app.goclio.com/oauth/approval") | |
print "Enter code returned from Clio: " | |
code = gets.chomp | |
client.authorize_with_code "https://app.goclio.com/oauth/approval", code.to_str | |
if client.authorized? | |
saved_token = client.access_token | |
end | |
end | |
if !client.authorized? | |
abort "Unauthorized" | |
end | |
if saved_token and !File.exists?(token_file) | |
file = File.new(token_file, "w") | |
file.write(saved_token) | |
file.close | |
end | |
me = client.users.who_am_i | |
puts "Token saved for #{me[1].first_name} #{me[1].last_name} of #{me[0].name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment