Sha256: 03767fb7a7f2226787ca76399d1693c4b7b48eaddf4de95097e2bf4a77f9166f

Contents?: true

Size: 759 Bytes

Versions: 27

Compression:

Stored size: 759 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)
      request_json = JSON.generate(login_service.run)
      response = Faraday.post(url + LOGIN_PATH, request_json, 'Content-Type' => 'application/json')
      case response.status
      when 200
        Credentials.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

27 entries across 27 versions & 1 rubygems

Version Path
sdr-client-0.19.0 lib/sdr_client/login.rb
sdr-client-0.18.0 lib/sdr_client/login.rb
sdr-client-0.17.2 lib/sdr_client/login.rb
sdr-client-0.17.1 lib/sdr_client/login.rb
sdr-client-0.17.0 lib/sdr_client/login.rb
sdr-client-0.16.1 lib/sdr_client/login.rb
sdr-client-0.16.0 lib/sdr_client/login.rb
sdr-client-0.15.2 lib/sdr_client/login.rb
sdr-client-0.15.1 lib/sdr_client/login.rb
sdr-client-0.15.0 lib/sdr_client/login.rb
sdr-client-0.14.0 lib/sdr_client/login.rb
sdr-client-0.13.2 lib/sdr_client/login.rb
sdr-client-0.13.1 lib/sdr_client/login.rb
sdr-client-0.13.0 lib/sdr_client/login.rb
sdr-client-0.12.0 lib/sdr_client/login.rb
sdr-client-0.11.0 lib/sdr_client/login.rb
sdr-client-0.10.0 lib/sdr_client/login.rb
sdr-client-0.9.0 lib/sdr_client/login.rb
sdr-client-0.8.1 lib/sdr_client/login.rb
sdr-client-0.8.0 lib/sdr_client/login.rb