Sha256: ed7cc5e2b1bc4132ee02064416f594eb2a73ca9c0e7f016125e6bed34013f521

Contents?: true

Size: 971 Bytes

Versions: 40

Compression:

Stored size: 971 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
        fail FinAppsCore::InvalidArgumentsError, 'Invalid argument: params.' unless validates params

        path ||= CONSUMER_LOGIN

        begin
          super params, path
        rescue FinAppsCore::ApiUnauthenticatedError
          login_error(path)
        end
      end

      def destroy
        create nil, LOGOUT
      end

      private

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

      def login_error(path)
        [
          nil,
          [
            "Invalid #{path == CONSUMER_LOGIN ? 'Consumer' : 'Operator'} Identifier or Credentials"
          ]
        ]
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
finapps-6.13.1 lib/finapps/rest/sessions.rb
finapps-6.13.0 lib/finapps/rest/sessions.rb
finapps-6.12.0 lib/finapps/rest/sessions.rb
finapps-6.11.0 lib/finapps/rest/sessions.rb
finapps-6.10.2 lib/finapps/rest/sessions.rb
finapps-6.10.1 lib/finapps/rest/sessions.rb
finapps-6.10.0 lib/finapps/rest/sessions.rb
finapps-6.9.2 lib/finapps/rest/sessions.rb
finapps-6.9.1 lib/finapps/rest/sessions.rb
finapps-6.9.0 lib/finapps/rest/sessions.rb
finapps-6.8.0 lib/finapps/rest/sessions.rb
finapps-6.7.1 lib/finapps/rest/sessions.rb
finapps-6.7.0 lib/finapps/rest/sessions.rb
finapps-6.6.1 lib/finapps/rest/sessions.rb
finapps-6.6.0 lib/finapps/rest/sessions.rb
finapps-6.5.0 lib/finapps/rest/sessions.rb
finapps-6.4.3 lib/finapps/rest/sessions.rb
finapps-6.4.2 lib/finapps/rest/sessions.rb
finapps-6.4.1 lib/finapps/rest/sessions.rb
finapps-6.4.0 lib/finapps/rest/sessions.rb