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[:video] = {name: 'video', parse: -> (video_id) { Yt::Video.new id: video_id, auth: @auth } } 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', }
Instance Attribute Summary collapse
-
#metric ⇒ Object
writeonly
Sets the attribute metric.
Instance Method Summary collapse
Methods inherited from Base
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
29 30 31 |
# File 'lib/yt/collections/reports.rb', line 29 def metric=(value) @metric = value end |
Instance Method Details
#within(days_range, dimension, try_again = true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yt/collections/reports.rb', line 31 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 |