Module: Googl::OAuth2::Utils

Included in:
Native, Server
Defined in:
lib/googl/oauth2/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token


6
7
8
# File 'lib/googl/oauth2/utils.rb', line 6

def access_token
  @access_token
end

#client_idObject

Returns the value of attribute client_id


6
7
8
# File 'lib/googl/oauth2/utils.rb', line 6

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret


6
7
8
# File 'lib/googl/oauth2/utils.rb', line 6

def client_secret
  @client_secret
end

#expires_atObject

Returns the value of attribute expires_at


6
7
8
# File 'lib/googl/oauth2/utils.rb', line 6

def expires_at
  @expires_at
end

#expires_inObject

Returns the value of attribute expires_in


6
7
8
# File 'lib/googl/oauth2/utils.rb', line 6

def expires_in
  @expires_in
end

#itemsObject

Returns the value of attribute items


7
8
9
# File 'lib/googl/oauth2/utils.rb', line 7

def items
  @items
end

#refresh_tokenObject

Returns the value of attribute refresh_token


6
7
8
# File 'lib/googl/oauth2/utils.rb', line 6

def refresh_token
  @refresh_token
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/googl/oauth2/utils.rb', line 13

def authorized?
  !access_token.nil? && !refresh_token.nil? && !expires_in.nil? && !expires_at.nil?
end

#expires?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'lib/googl/oauth2/utils.rb', line 9

def expires?
  expires_at < Time.now
end

#history(options = {}) ⇒ Object

Gets a user's history of shortened URLs.


19
20
21
22
23
24
25
26
27
28
# File 'lib/googl/oauth2/utils.rb', line 19

def history(options={})
  return unless authorized?
  resp = (options.nil? || options.empty?) ? get(Googl::Utils::API_HISTORY_URL) : get(Googl::Utils::API_HISTORY_URL, :query => options)
  case resp.code
  when 200
    self.items = resp.parsed_response.to_openstruct
  else
    raise exception("#{resp.code} #{resp.parsed_response}")
  end
end