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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c7d609f4d8f0c6c08af4d55afaf5f0b55f29f04ee94cd5d8b3acad4cbcbd8c2
4
- data.tar.gz: d3c177187c100d3eeb148250be4369cfe1bcd93fc757f9549b6e25bc793a304f
3
+ metadata.gz: ab86e8204d003348a950268a6ae436f4a8864b05ee265e9bf86e6ee97537792d
4
+ data.tar.gz: 9946f8a7d7677b48db6df4757a8a72989695559c98369965aeb0d79779d74bd0
5
5
  SHA512:
6
- metadata.gz: e35b82cfa37eccb1381b79c074898311d2510e99afa6a19b57d83ff2a4c3e967eec516ada71c740afe8620113cfd54ee1b05910f921cdbb55cc58d2b6c3c08fd
7
- data.tar.gz: 24806c984d60d18cec432a8f9858f6badf6882ea4ab08679256111abcbf082f83713de296662cf694237f2d8c95742d23366c834a24eacd213ece72ce676df16
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"] = query_string["reportRequests"].map do |report_request|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GAAPI
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Reid