hisui 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: af55565557423055909d226c7e42fa826269a5e5
4
- data.tar.gz: 164cc444aa1143b0b5c60e07a1582a49054bd409
2
+ SHA256:
3
+ metadata.gz: 2f63cc587035f036777979c56d4d39fed2e9f512e126d3809b3a85a7487ff675
4
+ data.tar.gz: '08e8bea765cb07fae43410ce041ab2ff38bf4ea51c997240f4fac1b05aed0b83'
5
5
  SHA512:
6
- metadata.gz: 1fdc7389ce7da297b307d14036fd5b5bc83228151fc428c6d24efe758fbf78f7b208df954ed10623b8993835bda3c86d86c01d13f2722881c5f55596f65e40f5
7
- data.tar.gz: 957b5861d9ff9e41016cd4b73ccfd20b989e5ed98ce17f1adcf62f8c5cd04502a8c31562cad78e4d51e1e60da186b0d95efad4d859f9a52f11ef0e14b4d24ed3
6
+ metadata.gz: 4196498ee4b4985e30cbac8391115c78b3a43de0e8cb06273f89b12eaa4cfe27fd64c5357d0c5794a56d2ff0a1be5590aa6067a238c14c54a2890474ef178a6d
7
+ data.tar.gz: d69cf054f142c53fee1692253c6d9b4c6b5d8479fbe5aa80b90b10f5c6f669b280585d76645586a5e3ae0ac138795ccdd44ec76ba743b7131875c5af8beef4dd
data/README.md CHANGED
@@ -44,22 +44,45 @@ end
44
44
 
45
45
  3. Get Google Analytics API response with `results` methods.
46
46
  Set `start_date` and `end_date` if you need.(defult period is past one month)
47
+ Set `compare_start_date` and `compare_end_date` if you need.
47
48
  ```ruby
48
- response = DailySummary.results(profile: profile, start_date: Date.current - 7.days, end_date: Date.current)
49
+ response = DailySummary.results(profile: profile, start_date: Date.current - 7.days, end_date: Date.current, compare_start_date: Date.current - 7.days - 1.month, compare_end_date: Date.current - 1.month)
49
50
  ```
50
51
 
51
52
  4. Use data.
52
53
  ```ruby
54
+ # Deprecate
53
55
  response.raw_attributes
54
56
 
55
57
  #=> [#<OpenStruct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
56
58
  # ...
57
59
  # #<OpenStruct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
58
60
 
61
+ response.primary
62
+
63
+ #=> [#<OpenStruct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
64
+ # ...
65
+ # #<OpenStruct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
66
+
67
+ response.comparing
68
+
69
+ #=> [#<OpenStruct date="20171022", pageviews="130", sessions="69", users="45", newUsers="40", bounceRate="70.09567898751234", pageviewsPerSession="1.884057975234981", avgSessionDuration="85.02349863284283">,
70
+ # ...
71
+ # #<OpenStruct date="20171029", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
72
+
73
+ # Deprecate
59
74
  response.total_values
60
75
 
61
76
  #=> #<OpenStruct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
62
77
 
78
+ response.primary_total
79
+
80
+ #=> #<OpenStruct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
81
+
82
+ response.comparing_total
83
+
84
+ #=> #<OpenStruct pageviews="640", sessions="299", users="213", newUsers="138", bounceRate="75.97253924292489", pageviewsPerSession="2.1404682398523578", avgSessionDuration="60.814845134904329">
85
+
63
86
  response.data?
64
87
 
65
88
  #=> true
@@ -2,9 +2,9 @@ require 'google/apis/analyticsreporting_v4'
2
2
 
3
3
  module Hisui
4
4
  class Request
5
- BASIC_OPTION_KEYS = [:start_date, :end_date, :limit]
5
+ BASIC_OPTION_KEYS = [:start_date, :end_date, :compare_start_date, :compare_end_date, :limit]
6
6
 
7
- attr_accessor :profile, :model, :start_date, :end_date, :limit
7
+ attr_accessor :profile, :model, :start_date, :end_date, :compare_start_date, :compare_end_date, :limit
8
8
 
9
9
  def initialize(profile:, model:, **options)
10
10
  @profile = profile
@@ -21,14 +21,19 @@ module Hisui
21
21
  reporting_service = Google::Apis::AnalyticsreportingV4::AnalyticsReportingService.new
22
22
  reporting_service.authorization = profile.user.access_token.token
23
23
 
24
- date_range = Google::Apis::AnalyticsreportingV4::DateRange.new(start_date: start_date.to_s, end_date: end_date.to_s)
24
+ date_ranges = []
25
+ date_ranges << Google::Apis::AnalyticsreportingV4::DateRange.new(start_date: start_date.to_s, end_date: end_date.to_s)
26
+
27
+ if compare_start_date && compare_end_date
28
+ date_ranges << Google::Apis::AnalyticsreportingV4::DateRange.new(start_date: compare_start_date.to_s, end_date: compare_end_date.to_s)
29
+ end
25
30
 
26
31
  request = Google::Apis::AnalyticsreportingV4::GetReportsRequest.new(
27
32
  report_requests: [Google::Apis::AnalyticsreportingV4::ReportRequest.new(
28
33
  view_id: profile.id,
29
34
  metrics: model.metrics,
30
35
  dimensions: model.dimensions,
31
- date_ranges: [date_range],
36
+ date_ranges: date_ranges,
32
37
  order_bys: model.order_bys,
33
38
  page_size: limit
34
39
  )]
@@ -7,8 +7,13 @@ module Hisui
7
7
  end
8
8
 
9
9
  def raw_attributes
10
- @raw_attributes ||= begin
11
- raw_attributes = []
10
+ warn "[DEPRECATION] `raw_attributes` is deprecated. Please use `primary` instead."
11
+ primary
12
+ end
13
+
14
+ def primary
15
+ @primary ||= begin
16
+ primary = []
12
17
 
13
18
  data.rows.each do |row|
14
19
  row_data = []
@@ -20,15 +25,47 @@ module Hisui
20
25
  row_data << value
21
26
  end
22
27
 
23
- raw_attributes << Hash[fields.zip(row_data)]
28
+ primary << Hash[fields.zip(row_data)]
29
+ end
30
+
31
+ primary.map { |attributes| OpenStruct.new(attributes) }
32
+ end
33
+ end
34
+
35
+ def comparing
36
+ @comparing ||= begin
37
+ comparing = []
38
+
39
+ data.rows.each do |row|
40
+ row_data = []
41
+ row.dimensions.each do |dimension|
42
+ row_data << dimension
43
+ end
44
+
45
+ if row.metrics.second
46
+ row.metrics.second.values.each do |value|
47
+ row_data << value
48
+ end
49
+ end
50
+
51
+ comparing << Hash[fields.zip(row_data)]
24
52
  end
25
53
 
26
- raw_attributes.map { |attributes| OpenStruct.new(attributes) }
54
+ comparing.map { |attributes| OpenStruct.new(attributes) }
27
55
  end
28
56
  end
29
57
 
30
58
  def total_values
31
- @total_values ||= OpenStruct.new(Hash[metrics.zip(data.totals.first.values)])
59
+ warn "[DEPRECATION] `total_values` is deprecated. Please use `primary_total` instead."
60
+ primary_total
61
+ end
62
+
63
+ def primary_total
64
+ @primary_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.first.values)])
65
+ end
66
+
67
+ def comparing_total
68
+ @comparing_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.try(:second).try(:values) || [])])
32
69
  end
33
70
 
34
71
  def data?
@@ -38,7 +75,7 @@ module Hisui
38
75
  private
39
76
 
40
77
  def column_header
41
- @column_header = response.reports.first.column_header
78
+ @column_header ||= response.reports.first.column_header
42
79
  end
43
80
 
44
81
  def metrics
@@ -66,7 +103,7 @@ module Hisui
66
103
  end
67
104
 
68
105
  def data
69
- @data = response.reports.first.data
106
+ @data ||= response.reports.first.data
70
107
  end
71
108
  end
72
109
  end
@@ -1,3 +1,3 @@
1
1
  module Hisui
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hisui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ikepon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-24 00:00:00.000000000 Z
11
+ date: 2018-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.6.11
196
+ rubygems_version: 2.7.6
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Access the Google Analytics Reporting API v4 On Rails