Class: YTAnalytics::YTAuth::Authentication

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/yt_analytics/request/authentication.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(*params) ⇒ Authentication

Returns a new instance of Authentication.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yt_analytics/request/authentication.rb', line 11

def initialize *params
  if params.first.is_a?(Hash)
    hash_options = params.first
    @user                          = hash_options[:username]
    @password                      = hash_options[:password]
    @dev_key                       = hash_options[:dev_key]
    @access_token                  = hash_options[:access_token]
    @authsub_token                 = hash_options[:authsub_token]
    @client_id                     = hash_options[:client_id] || "youtube_it"
    @config_token                  = hash_options[:config_token]
  else
    puts "* warning: the method YTAnalytics::Auth::Authentication.new(username, password, dev_key) is deprecated, use YouTubeIt::Upload::VideoUpload.new(:username => 'user', :password => 'passwd', :dev_key => 'dev_key')"
    @user                          = params.shift
    @password                      = params.shift
    @dev_key                       = params.shift
    @access_token                  = params.shift
    @authsub_token                 = params.shift
    @client_id                     = params.shift || "youtube_it"
    @config_token                  = params.shift
  end
end

Instance Method Details

#enable_http_debuggingObject



34
35
36
# File 'lib/yt_analytics/request/authentication.rb', line 34

def enable_http_debugging
  @http_debugging = true
end

#get_analytics(opts) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/yt_analytics/request/authentication.rb', line 47

def get_analytics(opts)
  # max_results = opts[:per_page] || 50
  # start_index = ((opts[:page] || 1) -1) * max_results +1
  get_url     = "/youtube/analytics/v1/reports?"
  get_url     << opts.collect { |k,p| [k,p].join '=' }.join('&')
  response    = yt_session('https://www.googleapis.com').get(get_url)

  return YTAnalytics::Parser::AnalyticsParser.new(response.body).parse
end

#get_current_userObject



40
41
42
43
44
45
# File 'lib/yt_analytics/request/authentication.rb', line 40

def get_current_user
  current_user_url = "/feeds/api/users/default"
  response         = yt_session.get(current_user_url)

  return Nokogiri::XML(response.body).at("entry/author/name").text
end

#temporal_totals(dimension, start_date, end_date, user_id) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/yt_analytics/request/authentication.rb', line 57

def temporal_totals(dimension, start_date, end_date, user_id)
  #dimension is either day, 7DayTotals, 30DayTotals, or month
  opts = {'end-date'=>end_date.strftime("%Y-%m-%d"),'ids' => "channel==#{user_id}", 'metrics' => 'views,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,subscribersGained,subscribersLost,uniques','start-date' => start_date.strftime("%Y-%m-%d"),'dimensions' => dimension}
  get_url     = "/youtube/analytics/v1/reports?"
  get_url     << opts.collect { |k,p| [k,p].join '=' }.join('&')
  response    = yt_session('https://www.googleapis.com').get(get_url)
  content = JSON.parse(response.body)
  return YTAnalytics::Parser::TemporalParser.new(content).parse
end