yt_analytics 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/lib/yt_analytics/client.rb
CHANGED
@@ -29,39 +29,24 @@ class YTAnalytics
|
|
29
29
|
client.get_current_user
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
client.get_my_video(video_id)
|
32
|
+
def analytics(options = {})
|
33
|
+
client.get_analytics(options)
|
35
34
|
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
client.get_my_videos(opts)
|
36
|
+
def seven_day_totals(options = {})
|
37
|
+
client.temporal_totals('7DayTotals',self.user_id, options)
|
40
38
|
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
client.get_watch_history
|
40
|
+
def thirty_day_totals(options = {})
|
41
|
+
client.temporal_totals('30DayTotals',self.user_id, options)
|
45
42
|
end
|
46
43
|
|
47
|
-
def
|
48
|
-
client.
|
44
|
+
def day_totals(options = {})
|
45
|
+
client.temporal_totals('day',self.user_id, options)
|
49
46
|
end
|
50
47
|
|
51
|
-
def
|
52
|
-
client.temporal_totals('
|
53
|
-
end
|
54
|
-
|
55
|
-
def thirty_day_totals(start_date = 2.day.ago, end_date = 2.day.ago)
|
56
|
-
client.temporal_totals('30DayTotals',start_date, end_date, self.user_id)
|
57
|
-
end
|
58
|
-
|
59
|
-
def day_totals(start_date = 2.day.ago, end_date = 2.day.ago)
|
60
|
-
client.temporal_totals('day',start_date, end_date, self.user_id)
|
61
|
-
end
|
62
|
-
|
63
|
-
def month_totals(start_date = 2.day.ago, end_date = 2.day.ago)
|
64
|
-
client.temporal_totals('month',start_date, end_date, self.user_id)
|
48
|
+
def month_totals(options = {})
|
49
|
+
client.temporal_totals('month',self.user_id, options)
|
65
50
|
end
|
66
51
|
|
67
52
|
private
|
@@ -5,19 +5,18 @@ class YTAnalytics
|
|
5
5
|
include YTAnalytics::Logging
|
6
6
|
attr_accessor :end_date, :views, :comments, :favorites_added, :favorites_removed, :likes, :dislikes, :shares, :subscribers_gained, :subscribers_lost, :uniques
|
7
7
|
|
8
|
-
|
9
8
|
def initialize params
|
10
|
-
@end_date = params[:endDate]
|
11
|
-
@views = params[:views]
|
12
|
-
@comments = params[:comments]
|
13
|
-
@favorites_added = params[:favoritesAdded]
|
14
|
-
@favorites_removed = params[:favoritesRemoved]
|
15
|
-
@likes = params[:likes]
|
16
|
-
@dislikes = params[:dislikes]
|
17
|
-
@shares = params[:shares]
|
18
|
-
@subscribers_gained = params[:subscribersGained]
|
19
|
-
@subscribers_lost = params[:subscribersLost]
|
20
|
-
@uniques = params[:uniques]
|
9
|
+
@end_date = params[:endDate] if params[:endDate]
|
10
|
+
@views = params[:views] if params[:views]
|
11
|
+
@comments = params[:comments] if params[:comments]
|
12
|
+
@favorites_added = params[:favoritesAdded] if params[:favoritesAdded]
|
13
|
+
@favorites_removed = params[:favoritesRemoved] if params[:favoritesRemoved]
|
14
|
+
@likes = params[:likes] if params[:likes]
|
15
|
+
@dislikes = params[:dislikes] if params[:dislikes]
|
16
|
+
@shares = params[:shares] if params[:shares]
|
17
|
+
@subscribers_gained = params[:subscribersGained] if params[:subscribersGained]
|
18
|
+
@subscribers_lost = params[:subscribersLost] if params[:subscribersLost]
|
19
|
+
@uniques = params[:uniques] if params[:uniques]
|
21
20
|
end
|
22
21
|
|
23
22
|
end
|
@@ -54,9 +54,20 @@ class YTAnalytics
|
|
54
54
|
return YTAnalytics::Parser::AnalyticsParser.new(response.body).parse
|
55
55
|
end
|
56
56
|
|
57
|
-
def temporal_totals(dimension,
|
57
|
+
def temporal_totals(dimension, user_id, options)
|
58
58
|
#dimension is either day, 7DayTotals, 30DayTotals, or month
|
59
|
-
|
59
|
+
|
60
|
+
opts = {'ids' => "channel==#{user_id}", 'dimensions' => dimension}
|
61
|
+
opts['start-date'] = (options['start-date'].strftime("%Y-%m-%d") if options['start-date']) || 1.day.ago.strftime("%Y-%m-%d")
|
62
|
+
opts['end-date'] = (options['end-date'].strftime("%Y-%m-%d") if options['end-date']) || 1.day.ago.strftime("%Y-%m-%d")
|
63
|
+
if options['metrics'].class == Array
|
64
|
+
opts['metrics'] = options['metrics'].join(",")
|
65
|
+
elsif options['metrics'].class == String
|
66
|
+
opts['metrics'] = options['metrics'].delete(" ")
|
67
|
+
else
|
68
|
+
opts['metrics'] = 'views,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,subscribersGained,subscribersLost,uniques'
|
69
|
+
end
|
70
|
+
|
60
71
|
get_url = "/youtube/analytics/v1/reports?"
|
61
72
|
get_url << opts.collect { |k,p| [k,p].join '=' }.join('&')
|
62
73
|
response = yt_session('https://www.googleapis.com').get(get_url)
|
data/lib/yt_analytics/version.rb
CHANGED