Class: Matomo::VisitedPage
- Inherits:
-
Object
- Object
- Matomo::VisitedPage
- Defined in:
- lib/matomo.rb
Instance Attribute Summary collapse
-
#hits ⇒ Object
Returns the value of attribute hits.
-
#label ⇒ Object
Returns the value of attribute label.
-
#visits ⇒ Object
Returns the value of attribute visits.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base_path, params) ⇒ VisitedPage
constructor
A new instance of VisitedPage.
- #path ⇒ Object
Constructor Details
#initialize(base_path, params) ⇒ VisitedPage
Returns a new instance of VisitedPage.
40 41 42 43 44 45 |
# File 'lib/matomo.rb', line 40 def initialize(base_path, params) @base_path = base_path @label = params["label"].sub!(/^\//, "") if params["label"] @hits = params["nb_hits"] @visits = params["nb_visits"] end |
Instance Attribute Details
#hits ⇒ Object
Returns the value of attribute hits.
38 39 40 |
# File 'lib/matomo.rb', line 38 def hits @hits end |
#label ⇒ Object
Returns the value of attribute label.
38 39 40 |
# File 'lib/matomo.rb', line 38 def label @label end |
#visits ⇒ Object
Returns the value of attribute visits.
38 39 40 |
# File 'lib/matomo.rb', line 38 def visits @visits end |
Class Method Details
.get_subtables ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/matomo.rb', line 65 def self.get_subtables # Get a mapping from resource paths to Matomo page view subtable ids resp = Matomo.get({ method: "Actions.getPageUrls", filter_limit: 50, }) if resp.response.code == "200" @subtables = resp.map{|x| [x["label"], x["idsubdatatable"]]}.to_h else @subtables = {} end end |
.where(**args) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/matomo.rb', line 51 def self.where(**args) get_subtables unless @subtables # Remove leading and trailing slashes to match Matomo label format. base_path = args[:base_path].gsub(/^\/|\/$/, "") return [] unless @subtables[base_path] resp = Matomo.get({ method: "Actions.getPageUrls", idSubtable: @subtables[base_path], }) return [] if resp.response.code != "200" resp.map{ |x| new(base_path, x) } end |
Instance Method Details
#path ⇒ Object
47 48 49 |
# File 'lib/matomo.rb', line 47 def path "/#{@base_path}/#{@label}" end |