gaapi 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 585053bbca2711362dde0579853b07716b1e8b5f60443a0060d49b348cf787f3
4
- data.tar.gz: 4d200b10dda8d3b22314cfc3b8b0edc92990ed1b9c38fd7b2d6cadc231aa2f6e
3
+ metadata.gz: c22fc4035ce9aa902bd074f1781e502b26912a8793716ee02076dbfb0a5f5ae8
4
+ data.tar.gz: e8b76b26a8d77b4a5529db7f4565d4c33073f88f60cd208c2a3d725d74db43bc
5
5
  SHA512:
6
- metadata.gz: 0f3262f52f469928c1d233742179b894531fa005e4bf7c19ae51ce0c6f55c9313486d00865935a52282300a469a4dad2c4523d86d0acd6e566c2833582f448e0
7
- data.tar.gz: d1f7b1722c569713746245719e521d803021860c641c77f0b7746d929b4dc27d006aedecf957bee0c274873054fec4d7a954ffa0a9e3e6db7953e4f04ad1a41b
6
+ metadata.gz: 26335da752592ddedc4483b91a9da1a0bb8e7217971659513fb5eb5bb61f170639359232650f9a203bc3e57d165bb5371050a0f967e7569dd744990c1b4c92d3
7
+ data.tar.gz: 137a10c00dcf6fe42ecda4ae13dec4625fe484e7f155d4327b5653b756700f45377028b992bb749c170ad4552e8cfb80ac16bb8544f6a28ef249279dee41397e
@@ -1,4 +1,4 @@
1
- ## [Pending Release][0.5.0]
1
+ ## [Pending Release][0.6.0]
2
2
 
3
3
  ### Breaking changes
4
4
 
@@ -12,6 +12,17 @@
12
12
 
13
13
  * Your contribution here!
14
14
 
15
+ ## [0.5.0][](2018-12-07)
16
+
17
+ ### Breaking changes
18
+
19
+ * Removed an unused parameter from Report.new.
20
+
21
+ ### New features
22
+
23
+ * Added `is_data_golden` and `next_page_token` methods to `Row` and `Report`.
24
+ * Improved the Yard documentation.
25
+
15
26
  ## [0.4.3][](2018-11-28)
16
27
 
17
28
  ### Bugfixes
@@ -85,6 +96,7 @@
85
96
  * N/A.
86
97
 
87
98
  [Pending Release]: https://github.com/weenhanceit/gaapi/compare/v0.4.3...HEAD
99
+ [0.5.0]: https://github.com/weenhanceit/gaapi/compare/v0.4.3...v0.5.0
88
100
  [0.4.3]: https://github.com/weenhanceit/gaapi/compare/v0.4.2...v0.4.3
89
101
  [0.4.2]: https://github.com/weenhanceit/gaapi/compare/v0.4.1...v0.4.2
90
102
  [0.4.1]: https://github.com/weenhanceit/gaapi/compare/v0.4.0...v0.4.1
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GAAPI
4
- # A single report from a query to Google Analytics
4
+ # A single report from a query to Google Analytics, with convenient methods
5
+ # to access the dimensions and metrics returned.
5
6
  class Report
6
- # An array of the dimensions, in the order that they appear in the response.
7
+ # An array of the dimensions, in the order that they appear in the report.
7
8
  def dimensions
8
9
  report["columnHeader"]["dimensions"] || []
9
10
  end
@@ -14,33 +15,56 @@ module GAAPI
14
15
  end
15
16
 
16
17
  # An array of the dimensions first and then the metrics, in the order that
17
- # they appear in the response.
18
+ # they appear in the report.
18
19
  def headers
19
20
  dimensions + metrics
20
21
  end
21
22
 
22
- def initialize(response, report)
23
- @response = response
24
- @report = report
23
+ # Initialize a new Report.
24
+ # @param report [JSON source, Hash] If a Hash, assume it's a valid report
25
+ # from a Google Analytics query, and use it as the report.
26
+ # Otherwise, attempt to parse it with `JSON.parse`.
27
+ # No checking is done on the input to ensure that it's a valid response
28
+ # from a Google Analytics query, so subsequent calls to the methods on the
29
+ # object returned from `Report.new` may fail in spectacular ways.
30
+ def initialize(report)
31
+ @report = report.is_a?(Hash) ? report : JSON.parse(report)
25
32
  end
33
+ # The report as a Ruby Hash, with String keys. It's typically much more
34
+ # convenient to use the `#rows` method, and the methods on `Row` on each
35
+ # instance of the a Row.
26
36
  attr_reader :report
27
37
 
28
- # An array of the metric names, in the order that they appear in the response.
38
+ # Return if the data is golden, meaning it won't change if the query is re-run
39
+ # at a later time. The is a lag between the end of a date period and when
40
+ # Google Analytics has completely consolidated all the tracking data.
41
+ def is_data_golden
42
+ report["data"]["isDataGolden"]
43
+ end
44
+
45
+ # The metric type of the i'th metric in the report.
29
46
  def metric_type(i)
30
47
  report["columnHeader"]["metricHeader"]["metricHeaderEntries"][i]["type"]
31
48
  end
32
49
 
33
- # An array of the metric names, in the order that they appear in the response.
50
+ # An array of the metric names, in the order that they appear in the report.
34
51
  def metrics
35
52
  report["columnHeader"]["metricHeader"]["metricHeaderEntries"].map { |metric| metric["name"] }
36
53
  end
37
54
 
55
+ # Return the nextPageToken, if any, indicating that the query exceeded
56
+ # the maximum number of rows allowed in a single response, and that the client
57
+ # has to ask for the rest of the data.
58
+ def next_page_token
59
+ report["nextPageToken"]
60
+ end
61
+
38
62
  # The data rows in the report.
39
63
  def rows
40
64
  report["data"]["rows"].map { |row| Row.new(self, row) }
41
65
  end
42
66
 
43
- # The totals, if there were any.
67
+ # The totals in the report, if there were any.
44
68
  def totals
45
69
  Array.new(dimensions.size) + report["data"]["totals"][0]["values"]
46
70
  end
@@ -49,9 +73,5 @@ module GAAPI
49
73
  def totals?
50
74
  report["data"]["totals"]
51
75
  end
52
-
53
- private
54
-
55
- attr_reader :response
56
76
  end
57
77
  end
@@ -57,7 +57,7 @@ module GAAPI
57
57
  def reports
58
58
  @reports ||= if success?
59
59
  to_json["reports"].map do |report|
60
- Report.new(self, report)
60
+ Report.new(report)
61
61
  end
62
62
  else
63
63
  []
@@ -1,7 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GAAPI
4
- # A single row from a query to Google Analytics
4
+ # A single row from a report from a query to Google Analytics.
5
+ #
6
+ # In addition to the methods listed, `Row` provides methods to access the
7
+ # value of a dimension or metric by the name of the dimension or metric.
8
+ # @!macro [new] method_missing
9
+ # The name is the snake case version of the Google Analytics dimension or
10
+ # metric name, minus the `ga:` prefix. For example, you can access the metric
11
+ # `ga:sessionDuration` by writing `row.session_duration`.
12
+ #
13
+ # In the case of the metrics, the value returned is the appropriate Ruby type
14
+ # for the metric. For example, an INTEGER metric is returned as a Ruby integer.
5
15
  class Row
6
16
  # An array of the dimension values, in the order that they appear in the
7
17
  # dimension headers.
@@ -14,7 +24,16 @@ module GAAPI
14
24
  @row = row
15
25
  end
16
26
 
17
- # Define and call methods for the columns in the report.
27
+ # Return if the data is golden, meaning it won't change if the query is re-run
28
+ # at a later time. The is a lag between the end of a date period and when
29
+ # Google Analytics has completely consolidated all the tracking data.
30
+ def is_data_golden
31
+ report.is_data_golden
32
+ end
33
+
34
+ # Define and call methods to return the value of the dimensions and metrics
35
+ # in the report.
36
+ # @!macro method_missing
18
37
  def method_missing(method, *args)
19
38
  if (i = dimension_method_names.find_index(method))
20
39
  define_singleton_method(method) do
@@ -32,21 +51,30 @@ module GAAPI
32
51
  end
33
52
 
34
53
  # An array of the metric values, in the order that they appear in the
35
- # metric headers.
54
+ # metric headers. These are the raw values as returned by the Google Analytics
55
+ # query, in other words, they're strings.
36
56
  def metrics
37
- # NOTE: There is one entry in the `row["metrics"]` array for each data range.
57
+ # NOTE: There is one entry in the `row["metrics"]` array for each date range.
38
58
  # Since currently we only support one date range, this following index is
39
59
  # always 0.
40
60
  row["metrics"][0]["values"]
41
61
  end
42
62
 
63
+ # Return the nextPageToken, if any, indicating that the query exceeded
64
+ # the maximum number of rows allowed in a single response, and that the client
65
+ # has to ask for the rest of the data.
66
+ def next_page_token
67
+ # puts "Next Page Token report: #{report.report}"
68
+ report.next_page_token
69
+ end
70
+
43
71
  def respond_to_missing?
44
72
  true
45
73
  end
46
74
 
47
75
  # Return the data from the row as an Array, ordered by:
48
- # Headers first, in the order that they appear in the Report#headers array.
49
- # Metrics next, in the order that they appear in the Rport#metrics array.
76
+ # - Headers first, in the order that they appear in the Report#headers array.
77
+ # - Metrics next, in the order that they appear in the Report#metrics array.
50
78
  def to_a
51
79
  dimensions + metrics
52
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GAAPI
4
- VERSION = "0.4.3"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Reid
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-28 00:00:00.000000000 Z
12
+ date: 2018-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chandler