Class: YTAnalytics::Client

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

Direct Known Subclasses

OAuth2Client

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(*params) ⇒ Client

Previously this was a logger instance but we now do it globally



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/yt_analytics/client.rb', line 6

def initialize *params
  if params.first.is_a?(Hash)
    hash_options = params.first
    @user = hash_options[:username]
    @pass = hash_options[:password]
    @dev_key = hash_options[:dev_key]
    @client_id = hash_options[:client_id] || "yt_analytics"
    @legacy_debug_flag = hash_options[:debug]
  elsif params.first
    puts "* warning: the method YTAnalytics::Client.new(user, passwd, dev_key) is deprecated, use YTAnalytics::Client.new(:username => 'user', :password => 'passwd', :dev_key => 'dev_key')"
    @user = params.shift
    @pass = params.shift
    @dev_key = params.shift
    @client_id = params.shift || "youtube_it"
    @legacy_debug_flag = params.shift
  end
end

Instance Method Details

#analytics(opts = {}) ⇒ Object



47
48
49
# File 'lib/yt_analytics/client.rb', line 47

def analytics(opts = {})
  client.get_analytics(opts)
end

#current_userObject



28
29
30
# File 'lib/yt_analytics/client.rb', line 28

def current_user
  client.get_current_user
end

#day_totals(start_date = 2.day.ago, end_date = 2.day.ago) ⇒ Object



59
60
61
# File 'lib/yt_analytics/client.rb', line 59

def day_totals(start_date = 2.day.ago, end_date = 2.day.ago)
  client.temporal_totals('day',start_date, end_date, self.user_id)
end

#enable_http_debuggingObject



24
25
26
# File 'lib/yt_analytics/client.rb', line 24

def enable_http_debugging
  client.enable_http_debugging
end

#month_totals(start_date = 2.day.ago, end_date = 2.day.ago) ⇒ Object



63
64
65
# File 'lib/yt_analytics/client.rb', line 63

def month_totals(start_date = 2.day.ago, end_date = 2.day.ago)
  client.temporal_totals('month',start_date, end_date, self.user_id)
end

#my_video(video_id) ⇒ Object

Gets the authenticated users video with the given ID. It may be private.



33
34
35
# File 'lib/yt_analytics/client.rb', line 33

def my_video(video_id)
  client.get_my_video(video_id)
end

#my_videos(opts = {}) ⇒ Object

Gets all videos



38
39
40
# File 'lib/yt_analytics/client.rb', line 38

def my_videos(opts = {})
  client.get_my_videos(opts)
end

#seven_day_totals(start_date = 2.day.ago, end_date = 2.day.ago) ⇒ Object



51
52
53
# File 'lib/yt_analytics/client.rb', line 51

def seven_day_totals(start_date = 2.day.ago, end_date = 2.day.ago)
  client.temporal_totals('7DayTotals',start_date, end_date, self.user_id)
end

#thirty_day_totals(start_date = 2.day.ago, end_date = 2.day.ago) ⇒ Object



55
56
57
# File 'lib/yt_analytics/client.rb', line 55

def thirty_day_totals(start_date = 2.day.ago, end_date = 2.day.ago)
  client.temporal_totals('30DayTotals',start_date, end_date, self.user_id)
end

#watch_historyObject

Gets the user’s watch history



43
44
45
# File 'lib/yt_analytics/client.rb', line 43

def watch_history
  client.get_watch_history
end