Class: GoSquared::Trends

Inherits:
Object
  • Object
show all
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

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_xmlObject



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

#xmlObject



56
57
58
# File 'lib/go_squared/trends.rb', line 56

def xml
  fetch
end