Class: Tracer
- Inherits:
-
RestfulModel
- Object
- RestfulModel
- Tracer
- Defined in:
- lib/tracer.rb
Defined Under Namespace
Classes: CodeCannotBeModified
Instance Attribute Summary collapse
-
#analytics ⇒ Object
Returns the value of attribute analytics.
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notify_on_open ⇒ Object
Returns the value of attribute notify_on_open.
-
#notify_webhook ⇒ Object
Returns the value of attribute notify_webhook.
Attributes inherited from RestfulModel
Instance Method Summary collapse
- #clicks ⇒ Object
- #clicks_for_asset(asset_or_id) ⇒ Object
- #clicks_for_link(link) ⇒ Object
- #clicks_for_region(region_id) ⇒ Object
- #enable_webhook(url) ⇒ Object
- #views ⇒ Object
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
#analytics ⇒ Object
Returns the value of attribute analytics.
11 12 13 |
# File 'lib/tracer.rb', line 11 def analytics @analytics end |
#code ⇒ Object
Returns the value of attribute code.
8 9 10 |
# File 'lib/tracer.rb', line 8 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/tracer.rb', line 7 def name @name end |
#notify_on_open ⇒ Object
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_webhook ⇒ Object
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
#clicks ⇒ Object
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 |
#clicks_for_link(link) ⇒ Object
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 |
#views ⇒ Object
13 14 15 |
# File 'lib/tracer.rb', line 13 def views return analytics["views"].to_i end |