Sha256: faaff63225a88e764f2b6105c4215d30562c0c8d19fc4cb6606e6c3ecd128c53

Contents?: true

Size: 795 Bytes

Versions: 66

Compression:

Stored size: 795 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.run)
      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

66 entries across 66 versions & 1 rubygems

Version Path
sdr-client-0.55.0 lib/sdr_client/login.rb
sdr-client-0.54.0 lib/sdr_client/login.rb
sdr-client-0.53.0 lib/sdr_client/login.rb
sdr-client-0.52.0 lib/sdr_client/login.rb
sdr-client-0.51.0 lib/sdr_client/login.rb
sdr-client-0.51.0.beta.1 lib/sdr_client/login.rb
sdr-client-0.50.0 lib/sdr_client/login.rb
sdr-client-0.49.0 lib/sdr_client/login.rb
sdr-client-0.48.0 lib/sdr_client/login.rb
sdr-client-0.47.0 lib/sdr_client/login.rb
sdr-client-0.46.0 lib/sdr_client/login.rb
sdr-client-0.45.0 lib/sdr_client/login.rb
sdr-client-0.44.0 lib/sdr_client/login.rb
sdr-client-0.43.1 lib/sdr_client/login.rb
sdr-client-0.43.0 lib/sdr_client/login.rb
sdr-client-0.42.0 lib/sdr_client/login.rb
sdr-client-0.41.0 lib/sdr_client/login.rb
sdr-client-0.40.1 lib/sdr_client/login.rb
sdr-client-0.40.0 lib/sdr_client/login.rb
sdr-client-0.39.0 lib/sdr_client/login.rb