Class: Tracer

Inherits:
RestfulModel show all
Defined in:
lib/tracer.rb

Defined Under Namespace

Classes: CodeCannotBeModified

Instance Attribute Summary collapse

Attributes inherited from RestfulModel

#_id, #created_at

Instance Method Summary collapse

Methods inherited from RestfulModel

#==, #as_json, collection_name, #inflate, #initialize, #path, #save!, #update

Constructor Details

This class inherits a constructor from RestfulModel

Instance Attribute Details

#analyticsObject

Returns the value of attribute analytics.



11
12
13
# File 'lib/tracer.rb', line 11

def analytics
  @analytics
end

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/tracer.rb', line 8

def code
  @code
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/tracer.rb', line 7

def name
  @name
end

#notify_on_openObject

Returns the value of attribute notify_on_open.



9
10
11
# File 'lib/tracer.rb', line 9

def notify_on_open
  @notify_on_open
end

#notify_webhookObject

Returns the value of attribute notify_webhook.



10
11
12
# File 'lib/tracer.rb', line 10

def notify_webhook
  @notify_webhook
end

Instance Method Details

#clicksObject



17
18
19
# File 'lib/tracer.rb', line 17

def clicks
  return analytics["clicks"].to_i
end

#clicks_for_asset(asset_or_id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tracer.rb', line 36

def clicks_for_asset(asset_or_id)
  return 0 unless analytics["assets"]
  asset_id = asset_or_id.is_a?(Asset) ? asset_or_id._id : asset_or_id

  for region, assets in analytics["assets"]
    for key, asset in assets
      return asset["clicks"].to_i if key == asset_id
    end
  end
  return 0
end


31
32
33
34
# File 'lib/tracer.rb', line 31

def clicks_for_link(link)
  return 0 unless analytics["links"] && analytics["links"][link]
  return analytics["links"][link]["clicks"].to_i
end

#clicks_for_region(region_id) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/tracer.rb', line 21

def clicks_for_region(region_id)
  return 0 unless analytics["assets"] && analytics["assets"][region_id]

  clicks = 0
  for key, asset in analytics["assets"][region_id]
    clicks += asset["clicks"].to_i
  end
  clicks
end

#enable_webhook(url) ⇒ Object



53
54
55
56
# File 'lib/tracer.rb', line 53

def enable_webhook(url)
  self.notify_on_open = true
  self.notify_webhook = url
end

#viewsObject



13
14
15
# File 'lib/tracer.rb', line 13

def views
  return analytics["views"].to_i
end