Module: Yt::Associations::Authenticable

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

Instance Method Summary collapse

Instance Method Details

#authObject



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

def auth
  self
end

#authenticationObject



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

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



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

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
# 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]
  @scopes = options[:scopes]
  @authentication = options[:authentication]
end

#refreshObject

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



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

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