Class: Yt::Collections::Reports

Inherits:
Base
  • Object
show all
Defined in:
lib/yt/collections/reports.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, of, #where

Methods included from Actions::List

#first!

Constructor Details

This class inherits a constructor from Yt::Collections::Base

Instance Attribute Details

#metric=(value) ⇒ Object (writeonly)

Sets the attribute metric

Parameters:

  • value

    the value to set the attribute metric to.



6
7
8
# File 'lib/yt/collections/reports.rb', line 6

def metric=(value)
  @metric = value
end

Instance Method Details

#within(days_range, try_again = true) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/yt/collections/reports.rb', line 8

def within(days_range, try_again = true)
  @days_range = days_range
  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, false) : raise
end