Module: Yt::Modules::Authentication

Included in:
Yt::Models::Account
Defined in:
lib/yt/modules/authentication.rb

Overview

Provides authentication methods to YouTube resources, which allows to access to content detail set-specific methods like ‘access_token`.

YouTube resources with authentication are: accounts.

Instance Method Summary collapse

Instance Method Details

#authObject



24
25
26
# File 'lib/yt/modules/authentication.rb', line 24

def auth
  self
end

#authenticationObject



28
29
30
31
# File 'lib/yt/modules/authentication.rb', line 28

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

#authentication_urlObject



33
34
35
36
37
38
# File 'lib/yt/modules/authentication.rb', line 33

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

#initialize(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/yt/modules/authentication.rb', line 15

def initialize(options = {})
  @access_token = options[:access_token]
  @refresh_token = options[:refresh_token]
  @expires_at = options[:expires_at]
  @authorization_code = options[:authorization_code]
  @redirect_uri = options[:redirect_uri]
  @scopes = options[:scopes]
end

#refreshObject

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



42
43
44
45
46
# File 'lib/yt/modules/authentication.rb', line 42

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