Sha256: 44a65a77ace1c6f66afa11794fea5f7443c8c520176ddd11006ea324eb894c99

Contents?: true

Size: 989 Bytes

Versions: 1

Compression:

Stored size: 989 Bytes

Contents

module SmartId::Api
  module Authentication
    class ConfirmationPoller
      BASE_URI = "session/"

      def self.confirm(session_id:, authentication_hash:, poll: true)
        new(session_id, authentication_hash, poll).call

      end

      def initialize(session_id, authentication_hash, poll)
        @session_id = session_id
        @authentication_hash = authentication_hash
        @poll = poll
      end

      def call
        params = { timeoutMs: SmartId.poller_timeout_seconds * 1000 }
        uri = BASE_URI + @session_id

        raw_response = SmartId::Api::Request.execute(method: :get, uri: uri, params: params)
        
        response = SmartId::Api::ConfirmationResponse.new(
          JSON.parse(raw_response.body),
          @authentication_hash.hash_data
        )

        # repeat request if confirmation is still running
        if response.confirmation_running? && @poll
          call
        else
          response
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smart_id-0.1.0 lib/smart_id/api/authentication/confirmation_poller.rb