yt_analytics 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,39 +29,24 @@ class YTAnalytics
29
29
  client.get_current_user
30
30
  end
31
31
 
32
- # Gets the authenticated users video with the given ID. It may be private.
33
- def my_video(video_id)
34
- client.get_my_video(video_id)
32
+ def analytics(options = {})
33
+ client.get_analytics(options)
35
34
  end
36
35
 
37
- # Gets all videos
38
- def my_videos(opts = {})
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
- # Gets the user's watch history
43
- def watch_history
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 analytics(opts = {})
48
- client.get_analytics(opts)
44
+ def day_totals(options = {})
45
+ client.temporal_totals('day',self.user_id, options)
49
46
  end
50
47
 
51
- def seven_day_totals(start_date = 2.day.ago, end_date = 2.day.ago)
52
- client.temporal_totals('7DayTotals',start_date, end_date, self.user_id)
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, start_date, end_date, user_id)
57
+ def temporal_totals(dimension, user_id, options)
58
58
  #dimension is either day, 7DayTotals, 30DayTotals, or month
59
- 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}
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)
@@ -1,4 +1,4 @@
1
1
  class YTAnalytics
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: