Module: Yt::Associations::Authenticable

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

Instance Method Summary collapse

Instance Method Details

#authObject



34
35
36
# File 'lib/yt/associations/has_authentication.rb', line 34

def auth
  self
end

#authenticationObject



38
39
40
41
42
43
44
# File 'lib/yt/associations/has_authentication.rb', line 38

def authentication
  @authentication = current_authentication
  @authentication ||= use_refresh_token! if @refresh_token
  @authentication ||= use_authorization_code! if @authorization_code
  @authentication ||= use_device_code! if @device_code
  @authentication ||= raise_missing_authentication!
end

#authentication_urlObject



46
47
48
49
50
51
# File 'lib/yt/associations/has_authentication.rb', line 46

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



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yt/associations/has_authentication.rb', line 22

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

#refreshed_access_token?Boolean

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

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/yt/associations/has_authentication.rb', line 55

def refreshed_access_token?
  old_access_token = authentication.access_token
  @authentication = @access_token = @refreshed_authentications = nil
  old_access_token != authentication.access_token
end