Sha256: e327ba76fac517ba963fe19e1bc747180a2f6b142679bf65bbbc0dd90ac8a08e

Contents?: true

Size: 978 Bytes

Versions: 1

Compression:

Stored size: 978 Bytes

Contents

require 'rest-client'
module Cogitate
  module Client
    # Responsible for converting a ticket into a token by leveraging a remote call to a Cogitate server.
    class TicketToTokenCoercer
      # @api public
      # @param ticket [String] A ticket issued by a Cogitate server
      # @return token [String] An encoded token
      #
      # @see Cogitate::Services::UriSafeTicketForIdentifierCreator
      def self.call(ticket:, **keywords)
        new(ticket: ticket, **keywords).call
      end

      def initialize(ticket:, configuration: default_configuration)
        self.ticket = ticket
        self.configuration = configuration
      end

      def call
        response = RestClient.get(configuration.url_for_claiming_a_ticket, params: { ticket: ticket })
        response.body
      end

      private

      attr_accessor :ticket, :configuration

      def default_configuration
        require 'cogitate'
        Cogitate.configuration
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cogitate-0.0.2 lib/cogitate/client/ticket_to_token_coercer.rb