Sha256: 63640e891515ab758086757241d6e48d711aae4f0df0ce910999432e5e76228b

Contents?: true

Size: 959 Bytes

Versions: 10

Compression:

Stored size: 959 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

10 entries across 10 versions & 1 rubygems

Version Path
finapps-5.0.17 lib/finapps/rest/sessions.rb
finapps-5.0.16 lib/finapps/rest/sessions.rb
finapps-5.0.15 lib/finapps/rest/sessions.rb
finapps-5.0.14 lib/finapps/rest/sessions.rb
finapps-5.0.13 lib/finapps/rest/sessions.rb
finapps-5.0.12 lib/finapps/rest/sessions.rb
finapps-5.0.11 lib/finapps/rest/sessions.rb
finapps-5.0.10 lib/finapps/rest/sessions.rb
finapps-5.0.9 lib/finapps/rest/sessions.rb
finapps-5.0.8 lib/finapps/rest/sessions.rb