class NeonRAW::Objects::Access

The access object @!attribute [r] access_token

@return [String] Returns the access token used for oAuth2.

@!attribute [r] token_type

@return [String] Returns the type of the token (bearer)

@!attribute [r] refresh_token

@return [String, nil] Returns the refresh token or nil if there is none.

@!attribute [r] scope

@return [String] Returns the scope where the token is valid.

@!attribute [r] expires_in

@return [Time] Returns how long until the token expires.

@!attribute [r] expires_at

@return [Time] Returns when the token expires.

Attributes

refresh_token[R]

Public Class Methods

new(data) click to toggle source
# File lib/NeonRAW/objects/access.rb, line 18
def initialize(data)
  @refresh_token = nil
  data.each do |key, value|
    instance_variable_set(:"@#{key}", value)
    next if key == :refresh_token
    self.class.send(:attr_reader, key)
  end
  # I have it expire 10 seconds early to give a small buffer
  # for requests to avoid getting those icky 401 errors.
  @expires_at = Time.now + 3590
end

Public Instance Methods

expired?() click to toggle source

@!method expired? @return [Boolean] Returns whether or not the token is expired.

# File lib/NeonRAW/objects/access.rb, line 32
def expired?
  Time.now > @expires_at
end
refresh!(data) click to toggle source

Refresh the access token. @!method refresh!(data) @param data [Hash] The new data.

# File lib/NeonRAW/objects/access.rb, line 39
def refresh!(data)
  data.each { |key, value| instance_variable_set(:"@#{key}", value) }
end