class Makeleaps::Response::TokenStore

Attributes

body[R]
response[R]

Public Class Methods

new(response) click to toggle source
# File lib/makeleaps/response/access_token.rb, line 6
def initialize(response)
  @response      = response
  @body = JSON.parse(response.body)
rescue JSON::JSONError
  @body = nil
end

Public Instance Methods

access_token() click to toggle source
# File lib/makeleaps/response/access_token.rb, line 13
def access_token
  @access_token ||= body['access_token']
end
valid?() click to toggle source
# File lib/makeleaps/response/access_token.rb, line 17
def valid?
  response && response.status == 200 && !expired?
end

Private Instance Methods

expiration_period() click to toggle source
# File lib/makeleaps/response/access_token.rb, line 31
def expiration_period
  body['expires_in']
end
expired?() click to toggle source
# File lib/makeleaps/response/access_token.rb, line 23
def expired?
  Time.now >= requested_at + expiration_period
end
requested_at() click to toggle source
# File lib/makeleaps/response/access_token.rb, line 27
def requested_at
  Time.parse response.headers['date']
end