Sha256: dc3a0e44756826f3b04364bc2b85d3d7f61d1b89ef0aeab32498acb29a3646f9

Contents?: true

Size: 866 Bytes

Versions: 54

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

module SdrClient
  # The namespace for the "login" command
  module Login
    LOGIN_PATH = '/v1/auth/login'
    extend Dry::Monads[:result]

    # @return [Result] the status of the call
    def self.run(url:, login_service: LoginPrompt, credential_store: Credentials)
      request_json = JSON.generate(
        login_service.respond_to?(:run) ? login_service.run : login_service.call
      )
      response = Faraday.post(url + LOGIN_PATH, request_json, 'Content-Type' => 'application/json')
      case response.status
      when 200
        credential_store.write(response.body)
        Success()
      when 400
        Failure('Email address is not a valid email')
      when 401
        Failure('Invalid username or password')
      else
        Failure("Status: #{response.status}\n#{response.body}")
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
sdr-client-2.3.1 lib/sdr_client/login.rb
sdr-client-2.3.0 lib/sdr_client/login.rb
sdr-client-2.2.0 lib/sdr_client/login.rb
sdr-client-2.1.0 lib/sdr_client/login.rb
sdr-client-2.0.1 lib/sdr_client/login.rb
sdr-client-2.0.0 lib/sdr_client/login.rb
sdr-client-1.0.0 lib/sdr_client/login.rb
sdr-client-0.97.0 lib/sdr_client/login.rb
sdr-client-0.96.0 lib/sdr_client/login.rb
sdr-client-0.95.0 lib/sdr_client/login.rb
sdr-client-0.94.0 lib/sdr_client/login.rb
sdr-client-0.93.0 lib/sdr_client/login.rb
sdr-client-0.92.0 lib/sdr_client/login.rb
sdr-client-0.91.0 lib/sdr_client/login.rb
sdr-client-0.90.0 lib/sdr_client/login.rb
sdr-client-0.89.0 lib/sdr_client/login.rb
sdr-client-0.88.0 lib/sdr_client/login.rb
sdr-client-0.87.0 lib/sdr_client/login.rb
sdr-client-0.86.0 lib/sdr_client/login.rb
sdr-client-0.85.0 lib/sdr_client/login.rb