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-0.84.0 lib/sdr_client/login.rb
sdr-client-0.83.0 lib/sdr_client/login.rb
sdr-client-0.82.0 lib/sdr_client/login.rb
sdr-client-0.81.0 lib/sdr_client/login.rb
sdr-client-0.80.0 lib/sdr_client/login.rb
sdr-client-0.79.0 lib/sdr_client/login.rb
sdr-client-0.78.0 lib/sdr_client/login.rb
sdr-client-0.77.1 lib/sdr_client/login.rb
sdr-client-0.77.0 lib/sdr_client/login.rb
sdr-client-0.76.0 lib/sdr_client/login.rb
sdr-client-0.75.0 lib/sdr_client/login.rb
sdr-client-0.74.0 lib/sdr_client/login.rb
sdr-client-0.73.0 lib/sdr_client/login.rb
sdr-client-0.72.0 lib/sdr_client/login.rb