Sha256: 5890708297649029899209c4d123eb7c21bc19c69913c91fbdbb0c47826f2297

Contents?: true

Size: 850 Bytes

Versions: 14

Compression:

Stored size: 850 Bytes

Contents

# frozen_string_literal: true

module FinApps
  module REST
    class Sessions < FinAppsCore::REST::Resources # :nodoc:
      CONSUMER_LOGIN = 'login'
      LOGOUT = 'logout'

      def create(params, path = nil)
        return super nil, path if path == LOGOUT
        raise FinAppsCore::InvalidArgumentsError, 'Invalid argument: params.' unless validates params

        path ||= CONSUMER_LOGIN

        begin
          super params, path
        rescue FinAppsCore::ApiUnauthenticatedError
          return [nil, ["Invalid #{path == CONSUMER_LOGIN ? 'Consumer' : 'Operator'} Identifier or Credentials"]]
        end
      end

      def destroy
        create nil, LOGOUT
      end

      private

      def validates(params)
        params.key?(:email) && params[:email] && params.key?(:password) && params[:password]
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
finapps-5.0.3 lib/finapps/rest/sessions.rb
finapps-5.0.2 lib/finapps/rest/sessions.rb
finapps-5.0.1 lib/finapps/rest/sessions.rb
finapps-5.0.0 lib/finapps/rest/sessions.rb
finapps-4.0.16 lib/finapps/rest/sessions.rb
finapps-4.0.15 lib/finapps/rest/sessions.rb
finapps-4.0.14 lib/finapps/rest/sessions.rb
finapps-4.0.12 lib/finapps/rest/sessions.rb
finapps-4.0.11 lib/finapps/rest/sessions.rb
finapps-4.0.10 lib/finapps/rest/sessions.rb
finapps-4.0.9 lib/finapps/rest/sessions.rb
finapps-4.0.8 lib/finapps/rest/sessions.rb
finapps-4.0.7 lib/finapps/rest/sessions.rb
finapps-4.0.6 lib/finapps/rest/sessions.rb