Sha256: 322a2112b7e4caa80dbd5772d47fd4b83a69aae69e0cecd0097771a5039bce05

Contents?: true

Size: 1.1 KB

Versions: 19

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module PriceHubble
  # The PriceHubble ecosystem is built around the authentication on each
  # request. This entity provides a simple to use interface for it.
  #
  # @see https://docs.pricehubble.com/#introduction-authentication
  class Authentication < BaseEntity
    # The expiration leeway to substract to guarantee
    # acceptance on remote application calls
    EXPIRATION_LEEWAY = 5.minutes

    # Mapped and tracked attributes
    tracked_attr :access_token, :expires_in

    # Add some runtime attributes
    attr_reader :created_at, :expires_at

    # Register the time of initializing as base for the expiration
    after_initialize do
      @created_at = Time.current
      @expires_at = created_at + (expires_in || 1.hour.to_i) - EXPIRATION_LEEWAY
    end

    # Allow to query whenever the current authentication instance is expired or
    # not. This includes also a small leeway to ensure the acceptance is
    # guaranteed.
    #
    # @return [Boolean] whenever the authentication instance is expired or not
    def expired?
      Time.current >= expires_at
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pricehubble-1.6.0 lib/price_hubble/entity/authentication.rb
pricehubble-1.5.1 lib/price_hubble/entity/authentication.rb
pricehubble-1.5.0 lib/price_hubble/entity/authentication.rb
pricehubble-1.4.0 lib/price_hubble/entity/authentication.rb
pricehubble-1.3.0 lib/price_hubble/entity/authentication.rb
pricehubble-1.2.5 lib/price_hubble/entity/authentication.rb
pricehubble-1.2.4 lib/price_hubble/entity/authentication.rb
pricehubble-1.2.3 lib/price_hubble/entity/authentication.rb
pricehubble-1.2.2 lib/price_hubble/entity/authentication.rb
pricehubble-1.2.1 lib/price_hubble/entity/authentication.rb
pricehubble-1.2.0 lib/price_hubble/entity/authentication.rb
pricehubble-1.1.0 lib/pricehubble/entity/authentication.rb
pricehubble-1.0.0 lib/pricehubble/entity/authentication.rb
pricehubble-0.4.2 lib/pricehubble/entity/authentication.rb
pricehubble-0.4.1 lib/pricehubble/entity/authentication.rb
pricehubble-0.4.0 lib/pricehubble/entity/authentication.rb
pricehubble-0.3.0 lib/pricehubble/entity/authentication.rb
pricehubble-0.2.0 lib/pricehubble/entity/authentication.rb
pricehubble-0.1.0 lib/pricehubble/entity/authentication.rb