module Quandl module Command class Task module Clientable extend ActiveSupport::Concern included do end module ClassMethods def authenticated_users_only! before_execute :authenticated_users_only! end def warn_unauthenticated_users before_execute :warn_unauthenticated_users end def autoload_quandl_client before_execute :autoload_quandl_client end end def current_user @current_user ||= Quandl::Client::User.info end protected def clear_session! @auth_token = nil @current_user = nil autoload_quandl_client end def authenticated_users_only! if auth_token.blank? fatal("You must authenticate to use #{self.class.command_name}! 'quandl login' OR --token xyz923") false end end def warn_unauthenticated_users error("WARN: Authenticate your requests! 'quandl login' OR --token xyz923") if auth_token.blank? end def autoload_quandl_client require 'thread/pool' require 'quandl/format' require 'quandl/command/client_ext' Quandl::Client.use( quandl_url ) Quandl::Client.token = auth_token Quandl::Client.request_source = 'quandl_command' Quandl::Client.request_version = Quandl::Command::VERSION end end end end end