Class: GoSquared::Trends
- Inherits:
-
Object
- Object
- GoSquared::Trends
- Defined in:
- lib/go_squared/trends.rb
Constant Summary collapse
- METRICS =
%w(pageviews topcontent ppv browsers platforms referrers locations languages screens capabilities queries keywords nvr sources toplanding topexit)
Instance Method Summary collapse
- #from(time) ⇒ Object
- #from_xml ⇒ Object
- #group_by(group) ⇒ Object
-
#initialize(api_key, site_id) ⇒ Trends
constructor
A new instance of Trends.
- #limit(value) ⇒ Object
- #on(metric) ⇒ Object
- #period(value) ⇒ Object
- #timezone(value) ⇒ Object
- #to(time) ⇒ Object
- #xml ⇒ Object
Constructor Details
#initialize(api_key, site_id) ⇒ Trends
Returns a new instance of Trends.
5 6 7 8 9 10 11 12 13 |
# File 'lib/go_squared/trends.rb', line 5 def initialize api_key, site_id @api_key = api_key @site_id = site_id @start = 1.month.ago.to_i @end = Time.now.to_i @metric = :pageviews @group = :day end |
Instance Method Details
#from(time) ⇒ Object
26 27 28 29 |
# File 'lib/go_squared/trends.rb', line 26 def from time @start = time.to_i self end |
#from_xml ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/go_squared/trends.rb', line 60 def from_xml hash = Hash.from_xml(xml) hash.recursive_symbolize_keys! hash[:data][@group].blank? ? hash[:data] : hash[:data][@group] end |
#group_by(group) ⇒ Object
41 42 43 44 |
# File 'lib/go_squared/trends.rb', line 41 def group_by group @group = group.to_sym self end |
#limit(value) ⇒ Object
46 47 48 49 |
# File 'lib/go_squared/trends.rb', line 46 def limit value @limit = value self end |
#on(metric) ⇒ Object
21 22 23 24 |
# File 'lib/go_squared/trends.rb', line 21 def on metric @metric = metric.to_sym self end |
#period(value) ⇒ Object
51 52 53 54 |
# File 'lib/go_squared/trends.rb', line 51 def period value @period = value self end |
#timezone(value) ⇒ Object
36 37 38 39 |
# File 'lib/go_squared/trends.rb', line 36 def timezone value @timezone = value self end |
#to(time) ⇒ Object
31 32 33 34 |
# File 'lib/go_squared/trends.rb', line 31 def to time @end = time.to_i self end |
#xml ⇒ Object
56 57 58 |
# File 'lib/go_squared/trends.rb', line 56 def xml fetch end |