class Pickpocket::Authentication::Oauth

Attributes

token_handler[R]

Public Class Methods

new() click to toggle source
# File lib/pickpocket/authentication/oauth.rb, line 10
def initialize
  @token_handler = TokenHandler.new
end

Public Instance Methods

authorize() click to toggle source
# File lib/pickpocket/authentication/oauth.rb, line 29
def authorize
  response_token = token_handler.read_oauth
  uri            = URI(Pickpocket.config.pocket_oauth_authorize_url)

  response = Net::HTTP.post_form(uri, {
      consumer_key: Pickpocket.config.consumer_key,
      code:         response_token
  })

  response_token = CGI::parse(response.body)['access_token'][0]
  token_handler.save_auth(response_token)
end
request_authorization() click to toggle source
# File lib/pickpocket/authentication/oauth.rb, line 14
def request_authorization
  uri      = URI(Pickpocket.config.pocket_oauth_request_url)
  response = Net::HTTP.post_form(uri, {
      consumer_key: Pickpocket.config.consumer_key,
      redirect_uri: Pickpocket.config.pocket_homepage
  })

  response_token = CGI::parse(response.body)['code'][0]
  auth_url       = URI(Pickpocket.config.pocket_user_authorize_url)
  auth_url.query = "request_token=#{response_token}&redirect_uri=#{Pickpocket.config.pocket_homepage}"

  Launchy.open(auth_url.to_s)
  token_handler.save_oauth(response_token)
end