Module: Googol::Authenticable

Includes:
ClientTokens, Requestable
Included in:
GoogleAccount, YoutubeAccount
Defined in:
lib/googol/authenticable.rb

Overview

Provides methods to authenticate as an account (either Google or Youtube).

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Requestable

#request!, #symbolize

Methods included from ClientTokens

#client_id, client_id=, #client_secret, client_secret=

Instance Method Details

#credentialsHash

Return the authorization credentials of an account for this app.

Returns:

  • (Hash)
    • :client_id [String] …

    • :client_secret [String] …

See Also:

  • ...


40
41
42
43
44
# File 'lib/googol/authenticable.rb', line 40

def credentials
  @credentials ||= request! method: :post,
    host: 'https://accounts.google.com', path: '/o/oauth2/token',
    body: credentials_params
end

#initialize(attrs = {}) ⇒ Object

Note:

The refresh token never expires but the access token expires after 1 hour. If the access token has expired, initialize the object again with the refresh token.

Initialize an object with either an authorization code or a refresh token

Parameters:

  • attrs (Hash) (defaults to: {})

    Authentication credentials to access the account

Options Hash (attrs):

  • :code (String)

    The OAuth2 authorization code

  • :redirect_url (String)

    The page to redirect after the OAuth2 page

  • :access_token (String)

    The authorization token for immediate access

  • :refresh_token (String)

    The refresh token for offline access

See Also:



25
26
27
28
29
30
# File 'lib/googol/authenticable.rb', line 25

def initialize(attrs = {})
  @code = attrs[:code]
  @refresh_token = attrs[:refresh_token]
  @credentials = {access_token: attrs[:access_token]} if attrs[:access_token]
  @redirect_url = attrs.fetch :redirect_url, 'http://example.com/'
end