Class: Pickpocket::Authentication::Oauth
- Inherits:
-
Object
- Object
- Pickpocket::Authentication::Oauth
- Defined in:
- lib/pickpocket/authentication/oauth.rb
Instance Attribute Summary collapse
-
#token_handler ⇒ Object
readonly
Returns the value of attribute token_handler.
Instance Method Summary collapse
- #authorize ⇒ Object
-
#initialize ⇒ Oauth
constructor
A new instance of Oauth.
- #request_authorization ⇒ Object
Constructor Details
#initialize ⇒ Oauth
Returns a new instance of Oauth.
10 11 12 |
# File 'lib/pickpocket/authentication/oauth.rb', line 10 def initialize @token_handler = TokenHandler.new end |
Instance Attribute Details
#token_handler ⇒ Object (readonly)
Returns the value of attribute token_handler.
8 9 10 |
# File 'lib/pickpocket/authentication/oauth.rb', line 8 def token_handler @token_handler end |
Instance Method Details
#authorize ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pickpocket/authentication/oauth.rb', line 29 def response_token = token_handler.read_oauth uri = URI(Pickpocket.config.) 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 ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pickpocket/authentication/oauth.rb', line 14 def 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.) 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 |