gaapi 0.2.1 → 0.3.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 +4 -4
- data/lib/gaapi/query.rb +19 -3
- data/lib/gaapi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab86e8204d003348a950268a6ae436f4a8864b05ee265e9bf86e6ee97537792d
|
4
|
+
data.tar.gz: 9946f8a7d7677b48db6df4757a8a72989695559c98369965aeb0d79779d74bd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd642771496a8728d814240b65ab52e8f07cae029b77bed5fea4cff6cbe4f5c95c7b8ad842e86b248d18e771d706b720a06c3c5615ac8ababf374421303d4be9
|
7
|
+
data.tar.gz: edf4b83b5f60e1b48557b3c6506bb8cf5a758599bc691ba4d7663616c6aa0534e1893297d20fac812f0a4c25070dddc4aa9d10d225a827d08c4cd2e6e0f62b70
|
data/lib/gaapi/query.rb
CHANGED
@@ -9,20 +9,21 @@ module GAAPI
|
|
9
9
|
# @param access_token [String] A valid access token with which to make a request to
|
10
10
|
# the specified View ID.
|
11
11
|
# @param end_date [Date, String] The end date for the report.
|
12
|
-
# @param query_string [String] The query in JSON format.
|
12
|
+
# @param query_string [String, Hash, JSON] The query in JSON format.
|
13
13
|
# @param start_date [Date, String] The start date for the report.
|
14
14
|
# @param view_id [String] The view ID of the property for which to submit the
|
15
15
|
# query.
|
16
16
|
def initialize(query_string, view_id, access_token, start_date, end_date)
|
17
17
|
@access_token = access_token.to_s
|
18
18
|
query_string = JSON.parse(query_string) unless query_string.is_a?(Hash)
|
19
|
-
@query =
|
20
|
-
@query["reportRequests"] =
|
19
|
+
@query = stringify_keys(query_string)
|
20
|
+
@query["reportRequests"] = @query["reportRequests"].map do |report_request|
|
21
21
|
report_request["viewId"] = view_id
|
22
22
|
report_request["dateRanges"] = [
|
23
23
|
"startDate": start_date.to_s,
|
24
24
|
"endDate": end_date.to_s
|
25
25
|
]
|
26
|
+
report_request["pageSize"] ||= 10_000
|
26
27
|
report_request
|
27
28
|
end
|
28
29
|
# puts "query: #{JSON.pretty_generate(query)}"
|
@@ -45,5 +46,20 @@ module GAAPI
|
|
45
46
|
private
|
46
47
|
|
47
48
|
attr_reader :access_token, :query
|
49
|
+
|
50
|
+
# The keys have to be strings to get converted to a GA query.
|
51
|
+
# Adapted from Rails.
|
52
|
+
def stringify_keys(object)
|
53
|
+
case object
|
54
|
+
when Hash
|
55
|
+
object.each_with_object({}) do |(key, value), result|
|
56
|
+
result[key.to_s] = stringify_keys(value)
|
57
|
+
end
|
58
|
+
when Array
|
59
|
+
object.map { |e| stringify_keys(e) }
|
60
|
+
else
|
61
|
+
object
|
62
|
+
end
|
63
|
+
end
|
48
64
|
end
|
49
65
|
end
|
data/lib/gaapi/version.rb
CHANGED