Last active
March 9, 2018 10:30
-
-
Save alphaKAI/5891205 to your computer and use it in GitHub Desktop.
Pocket API Rapper Written in Ruby.
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 "net/https" | |
require "uri" | |
require "json" | |
require "pp" | |
class PocketRuby | |
def get_code(ck) | |
header={ | |
"Content-Type"=> "application/json; charset=UTF-8", | |
"X-Accept"=> " application/json" | |
} | |
body={ | |
"consumer_key" => ck.to_s, | |
"redirect_uri" => "localhost" | |
} | |
uri=URI.parse("https://getpocket.com/v3/oauth/request") | |
https=Net::HTTP.new(uri.host,uri.port) | |
https.use_ssl = true | |
https.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
res="" | |
https.start{|htp| | |
request = Net::HTTP::Post.new(uri.path) | |
request["X-Accept"]=header["X-Accept"] | |
request.set_form_data(body,"&") | |
res=JSON.parse(htp.request(request).body) | |
pp res | |
} | |
return res | |
end | |
def get_atoken(ck,code) | |
header={ | |
"Content-Type"=> "application/json; charset=UTF-8", | |
"X-Accept"=> " application/json" | |
} | |
body={ | |
"consumer_key" => ck.to_s, | |
"code"=>code.to_s | |
} | |
uri=URI.parse("https://getpocket.com/v3/oauth/authorize") | |
https=Net::HTTP.new(uri.host,uri.port) | |
https.use_ssl = true | |
https.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
res="" | |
https.start{|htp| | |
request = Net::HTTP::Post.new(uri.path) | |
request["X-Accept"]=header["X-Accept"] | |
request.set_form_data(body,"&") | |
#res=JSON.parse( | |
p htp.request(request).body) | |
pp res | |
} | |
return res | |
end | |
end | |
ck="***"#consumer_key | |
res=PocketRuby.new.get_code(ck)["code"] | |
puts res | |
PocketRuby.new.get_atoken(ck,res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment