Class: GAAPI::Report

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

Overview

A single report from a query to Google Analytics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, report) ⇒ Report

Returns a new instance of Report.



22
23
24
25
# File 'lib/gaapi/report.rb', line 22

def initialize(response, report)
  @response = response
  @report = report
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



26
27
28
# File 'lib/gaapi/report.rb', line 26

def report
  @report
end

Instance Method Details

#dimensionsObject

An array of the dimensions, in the order that they appear in the response.



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

def dimensions
  report["columnHeader"]["dimensions"] || []
end

#dimensions?Boolean

Returns True if dimensions were returned.

Returns:

  • (Boolean)

    True if dimensions were returned.



12
13
14
# File 'lib/gaapi/report.rb', line 12

def dimensions?
  !report["columnHeader"]["dimensions"].nil?
end

#headersObject

An array of the dimensions first and then the metrics, in the order that they appear in the response.



18
19
20
# File 'lib/gaapi/report.rb', line 18

def headers
  dimensions + metrics
end

#metric_type(i) ⇒ Object

An array of the metric names, in the order that they appear in the response.



29
30
31
# File 'lib/gaapi/report.rb', line 29

def metric_type(i)
  report["columnHeader"]["metricHeader"]["metricHeaderEntries"][i]["type"]
end

#metricsObject

An array of the metric names, in the order that they appear in the response.



34
35
36
# File 'lib/gaapi/report.rb', line 34

def metrics
  report["columnHeader"]["metricHeader"]["metricHeaderEntries"].map { |metric| metric["name"] }
end

#rowsObject

The data rows in the report.



39
40
41
# File 'lib/gaapi/report.rb', line 39

def rows
  report["data"]["rows"].map { |row| Row.new(self, row) }
end

#totalsObject

The totals, if there were any.



44
45
46
# File 'lib/gaapi/report.rb', line 44

def totals
  Array.new(dimensions.size) + report["data"]["totals"][0]["values"]
end

#totals?Boolean

Returns True if there totals were returned from the query.

Returns:

  • (Boolean)

    True if there totals were returned from the query.



49
50
51
# File 'lib/gaapi/report.rb', line 49

def totals?
  report["data"]["totals"]
end