Module: Yt::Associations::Authentications

Defined in:
lib/yt/associations/authentications.rb

Overview

Provides the ‘has_one :access_token` method to YouTube resources, which allows to access to content detail set-specific methods like `access_token`. YouTube resources with access tokens are: accounts.

Instance Method Summary collapse

Instance Method Details

#authenticationObject



12
13
14
15
# File 'lib/yt/associations/authentications.rb', line 12

def authentication
  @authentication = current_authentication
  @authentication ||= new_authentication || refreshed_authentication!
end

#authentication_urlObject



17
18
19
20
21
22
# File 'lib/yt/associations/authentications.rb', line 17

def authentication_url
  host = 'accounts.google.com'
  path = '/o/oauth2/auth'
  query = authentication_url_params.to_param
  URI::HTTPS.build(host: host, path: path, query: query).to_s
end

#refreshObject

Obtains a new access token. Returns true if the new access token is different from the previous one



26
27
28
29
30
# File 'lib/yt/associations/authentications.rb', line 26

def refresh
  old_access_token = authentication.access_token
  @authentication = @access_token = @refreshed_authentications = nil
  old_access_token != authentication.access_token
end