lib/panoptes/client.rb in panoptes-client-0.3.8 vs lib/panoptes/client.rb in panoptes-client-0.4.0

- old
+ new

@@ -1,8 +1,9 @@ require 'panoptes/endpoints/json_api_endpoint' require 'panoptes/endpoints/json_endpoint' +require 'panoptes/client/authentication' require 'panoptes/client/cellect' require 'panoptes/client/classifications' require 'panoptes/client/collections' require 'panoptes/client/comments' require 'panoptes/client/discussions' @@ -19,10 +20,11 @@ module Panoptes class Client include Panoptes::Client::Me # Panoptes + include Panoptes::Client::Authentication include Panoptes::Client::Classifications include Panoptes::Client::Collections include Panoptes::Client::Projects include Panoptes::Client::ProjectPreferences include Panoptes::Client::Subjects @@ -41,10 +43,11 @@ class GenericError < StandardError; end class ConnectionFailed < GenericError; end class ResourceNotFound < GenericError; end class ServerError < GenericError; end class NotLoggedIn < GenericError; end + class AuthenticationExpired < GenericError; end attr_reader :env, :auth, :panoptes, :talk, :cellect def initialize(env: :production, auth: {}, public_key_path: nil, params: {}) @env = env @@ -57,31 +60,9 @@ auth: auth, url: talk_url, params: params ) @cellect = Panoptes::Endpoints::JsonEndpoint.new( url: panoptes_url, prefix: '/cellect' ) - end - - def current_user - raise NotLoggedIn unless @auth[:token] - - payload, = JWT.decode @auth[:token], jwt_signing_public_key, algorithm: 'RS512' - payload.fetch('data') - end - - def jwt_signing_public_key - @jwt_signing_public_key ||= OpenSSL::PKey::RSA.new(File.read(@public_key_path)) - end - - def public_key_for_env(env) - case env.to_s - when "staging" - File.expand_path(File.join("..", "..", "..", "data", "doorkeeper-jwt-staging.pub"), __FILE__) - when "production" - File.expand_path(File.join("..", "..", "..", "data", "doorkeeper-jwt-production.pub"), __FILE__) - else - nil - end end def panoptes_url case env when :production, 'production'.freeze