Created
April 17, 2020 17:56
-
-
Save kyanny/cb8e386dbfea031617229bdf80b67ab4 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
# https://getpocket.com/developer/docs/authentication | |
require 'net/http' | |
require 'uri' | |
def usage | |
puts <<USAGE | |
Usage: | |
$ ruby #{$0} <consumer_key> | |
USAGE | |
end | |
consumer_key = ARGV.first | |
unless consumer_key | |
usage | |
exit! | |
end | |
uri = URI.parse('https://getpocket.com/v3/oauth/request') | |
params = { | |
'consumer_key' => consumer_key, | |
'redirect_uri' => 'http://example.com/', | |
} | |
res = Net::HTTP.post_form(uri, params) | |
if res.code != '200' | |
puts res.body | |
exit! | |
end | |
query = Hash[URI.decode_www_form(res.body)] | |
code = query['code'] | |
url = "https://getpocket.com/auth/authorize?request_token=#{code}&redirect_uri=http://example.com/" | |
system("open #{url}") | |
puts "Press any key if you have authenticated: " | |
STDIN.gets | |
uri = URI.parse('https://getpocket.com/v3/oauth/authorize') | |
params = { | |
'consumer_key' => consumer_key, | |
'code' => code, | |
} | |
res = Net::HTTP.post_form(uri, params) | |
pp Hash[URI.decode_www_form(res.body)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment