module Picturelife
Constants
- API_ENDPOINT
- OAUTH_ENDPOINT
- RULER_ENDPOINT
- VERSION
Attributes
access_token[RW]
client_id[RW]
client_secret[RW]
redirect_uri[R]
refresh_token[RW]
token_expires[R]
user_id[R]
Public Class Methods
access_token_from_code=(code)
click to toggle source
# File lib/picturelife/oauth.rb, line 19 def access_token_from_code=(code) needs_configuration! uri = [ OAUTH_ENDPOINT, "access_token?", "client_id=#{@client_id}", "&client_secret=#{@client_secret}", "&code=#{code}", "&client_uuid=#{client_uuid}" ].join res = api_oauth_get(uri) if res['status'] != 200 raise OAuthError.new(res['status'], res['error'], res) else @refresh_token = res['refresh_token'] @user_id = res['user_id'] @token_expires = Time.at(res['expires']) @access_token = res['access_token'] end end
authenticated?()
click to toggle source
# File lib/picturelife/base.rb, line 21 def authenticated? !! @access_token end
configured?()
click to toggle source
# File lib/picturelife/base.rb, line 15 def configured? @client_id && @client_secret && @redirect_uri end
const_missing(name)
click to toggle source
# File lib/picturelife/stub.rb, line 3 def self.const_missing(name) Stub.new(underscore(name.to_s)) end
redirect_uri=(uri)
click to toggle source
# File lib/picturelife/base.rb, line 11 def redirect_uri=(uri) @redirect_uri = escape_uri(uri) end
reset_authentication!()
click to toggle source
# File lib/picturelife/base.rb, line 32 def reset_authentication! @access_token = nil @refresh_token = nil @token_expires = nil @user_id = nil end
reset_configuration!()
click to toggle source
# File lib/picturelife/base.rb, line 25 def reset_configuration! @client_id = nil @client_secret = nil @redirect_uri = nil reset_authentication! end
Private Class Methods
api_oauth_get(uri)
click to toggle source
# File lib/picturelife/oauth.rb, line 45 def api_oauth_get(uri) uri = URI(URI.encode(uri)) response = Net::HTTP.get(uri) response = JSON.parse(hashrocket_to_json(response)) raise OAuthError.new(response["error"]) if response["status"] != 200 response end