Class: Yt::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/yt/models/account.rb

Overview

Provides methods to access a YouTube account.

Instance Method Summary collapse

Methods included from Associations

#has_many

Methods included from Yt::Actions::Update

#do_update, #update_params

Constructor Details

#initialize(options = {}) ⇒ Account

Returns a new instance of Account.



12
13
14
15
16
17
18
# File 'lib/yt/models/account.rb', line 12

def initialize(options = {})
  # By default is someone passes a refresh_token but not a scope, we can assume it's a youtube one
  @scope = options.fetch :scope, 'https://www.googleapis.com/auth/youtube'
  @access_token = options[:access_token]
  @refresh_token = options[:refresh_token]
  @redirect_url = options[:redirect_url]
end

Instance Method Details

#access_token_for(scope) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/yt/models/account.rb', line 20

def access_token_for(scope)
  # TODO incremental scope

  # HERE manage the fact that we must change some scope on device,
  # like 'https://www.googleapis.com/auth/youtube.readonly' is not accepted
  if Yt.configuration.scenario == :device_app && scope == 'https://www.googleapis.com/auth/youtube.readonly'
    scope = 'https://www.googleapis.com/auth/youtube'
  end

  # TODO !! include? is not enough, because (for instance) 'youtube' also includes 'youtube.readonly'

  # unless (@scope == scope) || (scope == 'https://www.googleapis.com/auth/youtube.readonly' && @scope =='https://www.googleapis.com/auth/youtube')
  #   @scope = scope
  #   @access_token = @refresh_token = nil
  # end
  @access_token ||= refresh_access_token || get_access_token
end

#authObject



38
39
40
# File 'lib/yt/models/account.rb', line 38

def auth
  self
end