Class: Redd::Models::Access

Inherits:
BasicModel show all
Defined in:
lib/redd/models/access.rb

Overview

Note:

This model also supports an additional key, called `:created_at` which is a UNIX time representing the time the access was created. The default value is the time the object was initialized.

Models access_token and related keys.

Instance Attribute Summary

Attributes inherited from BasicModel

#client

Instance Method Summary collapse

Methods inherited from BasicModel

from_id, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_h

Constructor Details

#initialize(client = nil, attributes = {}) ⇒ Access

Create a non-lazily initialized Access.

Examples:

access = Redd::Models::Access.new(access_token: ...)

17
18
19
20
21
22
23
# File 'lib/redd/models/access.rb', line 17

def initialize(client = nil, attributes = {})
  if client.is_a?(Hash)
    super(nil, client)
  else
    super(client, attributes)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Redd::Models::BasicModel

Instance Method Details

#expired?(grace_period = 60) ⇒ Boolean


25
26
27
28
29
# File 'lib/redd/models/access.rb', line 25

def expired?(grace_period = 60)
  # We're not sure, so we just assume it hasn't expired.
  return false unless @attributes[:expires_in]
  Time.now.to_i > @attributes[:created_at] + (@attributes[:expires_in] - grace_period)
end

#permanent?Boolean


31
32
33
# File 'lib/redd/models/access.rb', line 31

def permanent?
  !@attributes[:refresh_token].nil?
end