Class: Yt::Collections::Reports
- Defined in:
- lib/yt/collections/reports.rb
Constant Summary collapse
- DIMENSIONS =
Hash.new({name: 'day', parse: ->(day) {Date.iso8601 day} }).tap do |hash| hash[:traffic_source] = {name: 'insightTrafficSourceType', parse: ->(type) {TRAFFIC_SOURCES.key type} } hash[:playback_location] = {name: 'insightPlaybackLocationType', parse: ->(type) {PLAYBACK_LOCATIONS.key type} } hash[:embedded_player_location] = {name: 'insightPlaybackLocationDetail', parse: ->(url) {url} } hash[:related_video] = {name: 'insightTrafficSourceDetail', parse: ->(video_id) { Yt::Video.new id: video_id, auth: @auth } } hash[:video] = {name: 'video', parse: ->(video_id) { Yt::Video.new id: video_id, auth: @auth } } hash[:playlist] = {name: 'playlist', parse: ->(playlist_id) { Yt::Playlist.new id: playlist_id, auth: @auth } } hash[:device_type] = {name: 'deviceType', parse: ->(type) { type.downcase.to_sym } } end
- TRAFFIC_SOURCES =
Note:
EXT_APP is also returned but it’s not in the documentation above!
{ advertising: 'ADVERTISING', annotation: 'ANNOTATION', external_app: 'EXT_APP', external_url: 'EXT_URL', embedded: 'NO_LINK_EMBEDDED', other: 'NO_LINK_OTHER', playlist: 'PLAYLIST', promoted: 'PROMOTED', related_video: 'RELATED_VIDEO', subscriber: 'SUBSCRIBER', channel: 'YT_CHANNEL', other_page: 'YT_OTHER_PAGE', search: 'YT_SEARCH', }
- PLAYBACK_LOCATIONS =
{ channel: 'CHANNEL', watch: 'WATCH', embedded: 'EMBEDDED', other: 'YT_OTHER', external_app: 'EXTERNAL_APP', mobile: 'MOBILE' # only present for data < September 10, 2013 }
Instance Attribute Summary collapse
-
#metric ⇒ Object
writeonly
Sets the attribute metric.
Instance Method Summary collapse
Methods inherited from Base
#includes, #initialize, of, #where
Methods included from Actions::List
Constructor Details
This class inherits a constructor from Yt::Collections::Base
Instance Attribute Details
#metric=(value) ⇒ Object (writeonly)
Sets the attribute metric
44 45 46 |
# File 'lib/yt/collections/reports.rb', line 44 def metric=(value) @metric = value end |
Instance Method Details
#within(days_range, dimension, try_again = true) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yt/collections/reports.rb', line 46 def within(days_range, dimension, try_again = true) @days_range = days_range @dimension = dimension Hash[*flat_map{|daily_value| daily_value}] # NOTE: Once in a while, YouTube responds with 400 Error and the message # "Invalid query. Query did not conform to the expectations."; in this # case running the same query after one second fixes the issue. This is # not documented by YouTube and hardly testable, but trying again the # same query is a workaround that works and can hardly cause any damage. # Similarly, once in while YouTube responds with a random 503 error. rescue Yt::Error => e try_again && rescue?(e) ? sleep(3) && within(days_range, dimension, false) : raise end |