Sha256: d7b97153edbff0cc5a313e69eba1fe702301e8856927d692e5b7c97ccc725b62

Contents?: true

Size: 865 Bytes

Versions: 5

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module SdrClient
  class RedesignedClient
    # Fetch a token from the SDR API using user credentials
    class Authenticator
      def self.token
        new.token
      end

      # Request an access_token
      def token
        response = connection.post(path, request_body, content_type: 'application/json')

        UnexpectedResponse.call(response) unless response.success?

        JSON.parse(response.body)['token']
      end

      private

      def request_body
        JSON.generate(
          {
            email: SdrClient::RedesignedClient.config.email,
            password: SdrClient::RedesignedClient.config.password
          }
        )
      end

      def path
        '/v1/auth/login'
      end

      def connection
        Faraday.new(url: SdrClient::RedesignedClient.config.url)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sdr-client-2.18.0 lib/sdr_client/redesigned_client/authenticator.rb
sdr-client-2.17.0 lib/sdr_client/redesigned_client/authenticator.rb
sdr-client-2.16.0 lib/sdr_client/redesigned_client/authenticator.rb
sdr-client-2.13.2 lib/sdr_client/redesigned_client/authenticator.rb
sdr-client-2.13.1 lib/sdr_client/redesigned_client/authenticator.rb