Class: Matomo::VisitedPage

Inherits:
Object
  • Object
show all
Defined in:
lib/matomo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hitsObject

Returns the value of attribute hits.



38
39
40
# File 'lib/matomo.rb', line 38

def hits
  @hits
end

#labelObject

Returns the value of attribute label.



38
39
40
# File 'lib/matomo.rb', line 38

def label
  @label
end

#visitsObject

Returns the value of attribute visits.



38
39
40
# File 'lib/matomo.rb', line 38

def visits
  @visits
end

Class Method Details

.get_subtablesObject



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

#pathObject



47
48
49
# File 'lib/matomo.rb', line 47

def path
  "/#{@base_path}/#{@label}"
end