Sha256: eea0c6e1dc73b75d18f325b94e634f80e3bdaa2f8517b598d3386d9df449eb33

Contents?: true

Size: 759 Bytes

Versions: 3

Compression:

Stored size: 759 Bytes

Contents

class Visa::Request
  delegate :tokenable, to: :token

  def initialize(environment)
    @environment = environment
  end

  def invalidate
    token.touch :voided_at
  end

  def touch
    token.touch :last_requested_at
  end

  def valid?
    token.present? && token.voided_at.nil? && not_too_old?
  end

  private

  attr_reader :environment

  def credentials
    string = request.params['access_token'] ||
      environment[Visa.request_header] || ''

    [string[0..15], string[16..57]]
  end

  def not_too_old?
    time = token.last_requested_at || token.created_at
    time > Visa.timeout.ago
  end

  def request
    @request ||= Rack::Request.new environment
  end

  def token
    @token ||= Visa::Token.find_by_credentials *credentials
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
visa-0.1.0 lib/visa/request.rb
visa-0.0.3 lib/visa/request.rb
visa-0.0.2 lib/visa/request.rb