Module: Yt::Associations::Authenticable

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

Instance Method Summary collapse

Instance Method Details

#authObject



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

def auth
  self
end

#authenticationObject



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

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



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

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
# 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]
end

#refreshObject

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



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

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