hisui 0.1.5 → 0.1.6

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
2
  SHA256:
3
- metadata.gz: ed5550e23b11889424c0bf4ec332d655989f080ab442e78954e62342b9450a65
4
- data.tar.gz: c4d88b0d28878e96196ba088db6b6610617cbeba5e3c7dd4f2c8c013bef708df
3
+ metadata.gz: 539f07615132804cd99b435af49bfb73380983d58b967a16d9326dde055ca47c
4
+ data.tar.gz: 7cb0f27599b5e2fa28fd947ea0db9aacaa9f669bf6d6b301baba108d7bd892c2
5
5
  SHA512:
6
- metadata.gz: 1ab1c8635dd6023ca3778c47df5940d846e89ee02e701b66cbd2252bc15bb7a0e72cf3d0a2fc5be38985680e36b0798cb81cb2a653b21ae8d12da2ef7444e7bf
7
- data.tar.gz: 8ec50ed5bdc40a0d28f86e90052323532c61ace7c8b71eba99232978066238dad326b1747e032ec78e5451252b16f6b39cd3b13d868f40a22f5a59f29c8972b1
6
+ metadata.gz: dbdf33eeb8906f14d19c7eb14fa3e90f3be7819beca4a9d408d468e4059aa92c1784cf6926dc61f1bfc8e6bdd32518d1b1b735d7fe732397f58b67cb258ed90e
7
+ data.tar.gz: 55ed36f65dff20ea4d59af454638049db05588b9251a717014b1862589dbf3ad03ba693e9cf6b8aa962c38f302460fd9d41af4cb26e12e21ca97ec1d95e4b5c4
data/README.md CHANGED
@@ -54,38 +54,40 @@ response = DailySummary.results(profile: profile, start_date: Date.current - 7.d
54
54
  # Deprecate
55
55
  response.raw_attributes
56
56
 
57
- #=> [#<OpenStruct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
57
+ # [DEPRECATION] `raw_attributes` is deprecated. Please use `primary` instead.
58
+ # => [#<struct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
58
59
  # ...
59
- # #<OpenStruct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
60
+ # #<struct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
60
61
 
61
62
  response.primary
62
63
 
63
- #=> [#<OpenStruct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
64
+ # => [#<struct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
64
65
  # ...
65
- # #<OpenStruct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
66
+ # #<struct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
66
67
 
67
68
  response.comparing
68
69
 
69
- #=> [#<OpenStruct date="20171022", pageviews="130", sessions="69", users="45", newUsers="40", bounceRate="70.09567898751234", pageviewsPerSession="1.884057975234981", avgSessionDuration="85.02349863284283">,
70
+ # => [#<struct date="20171022", pageviews="130", sessions="69", users="45", newUsers="40", bounceRate="70.09567898751234", pageviewsPerSession="1.884057975234981", avgSessionDuration="85.02349863284283">,
70
71
  # ...
71
- # #<OpenStruct date="20171029", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
72
+ # #<struct date="20171029", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
72
73
 
73
74
  # Deprecate
74
75
  response.total_values
75
76
 
76
- #=> #<OpenStruct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
77
+ # [DEPRECATION] `total_values` is deprecated. Please use `primary_total` instead.
78
+ #=> #<struct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
77
79
 
78
80
  response.primary_total
79
81
 
80
- #=> #<OpenStruct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
82
+ # => #<struct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
81
83
 
82
84
  response.comparing_total
83
85
 
84
- #=> #<OpenStruct pageviews="640", sessions="299", users="213", newUsers="138", bounceRate="75.97253924292489", pageviewsPerSession="2.1404682398523578", avgSessionDuration="60.814845134904329">
86
+ # => #<struct pageviews="640", sessions="299", users="213", newUsers="138", bounceRate="75.97253924292489", pageviewsPerSession="2.1404682398523578", avgSessionDuration="60.814845134904329">
85
87
 
86
88
  response.data?
87
89
 
88
- #=> true
90
+ # => true
89
91
  ```
90
92
 
91
93
  #### Filtering
@@ -4,6 +4,7 @@ require 'hisui/user'
4
4
  require 'hisui/model'
5
5
  require 'hisui/request'
6
6
  require 'hisui/response'
7
+ require 'hisui/response/ga_data'
7
8
  require 'hisui/filters_expression'
8
9
 
9
10
  require 'hisui/management/base'
@@ -2,7 +2,7 @@ module Hisui
2
2
  module Model
3
3
  # Adds metrics to the class for retrieval from GA
4
4
  #
5
- # @param fields [Symbol] the names of the fields to retrieve
5
+ # @param field [Symbol] the names of the fields to retrieve
6
6
  # @return [ListParameter] the set of all metrics
7
7
  def metrics(*field)
8
8
  @metrics ||= Set.new([])
@@ -12,7 +12,7 @@ module Hisui
12
12
 
13
13
  # Adds dimensions to the class for retrieval from GA
14
14
  #
15
- # @param fields [Symbol] the names of the fields to retrieve
15
+ # @param field [Symbol] the names of the fields to retrieve
16
16
  # @return [ListParameter] the set of all dimensions
17
17
  def dimensions(*field)
18
18
  @dimensions ||= Set.new([])
@@ -1,9 +1,7 @@
1
1
  module Hisui
2
2
  class Response
3
- attr_reader :response
4
-
5
3
  def initialize(response)
6
- @response = response
4
+ @ga_data = GaData.new(response)
7
5
  end
8
6
 
9
7
  def raw_attributes
@@ -12,74 +10,15 @@ module Hisui
12
10
  end
13
11
 
14
12
  def primary
15
- @primary ||= begin
16
- primary = []
17
-
18
- data.try(:rows).try(:each) do |row|
19
- row_data = []
20
- row.dimensions.each do |dimension|
21
- row_data << dimension
22
- end
23
-
24
- row.metrics.first.values.each do |value|
25
- row_data << value
26
- end
27
-
28
- primary << Hash[fields.zip(row_data)]
29
- end
30
-
31
- primary.map { |attributes| OpenStruct.new(attributes) }
32
- end
13
+ @primary ||= @ga_data.construct(:first)
33
14
  end
34
15
 
35
16
  def comparing
36
- @comparing ||= begin
37
- comparing = []
38
-
39
- data.try(:rows).try(:each) do |row|
40
- row_data = []
41
- row.dimensions.each do |dimension|
42
- row_data << dimension
43
- end
44
-
45
- row.try(:metrics).try(:second).try(:values).try(:each) do |value|
46
- row_data << value
47
- end
48
-
49
- comparing << Hash[fields.zip(row_data)]
50
- end
51
-
52
- comparing.map { |attributes| OpenStruct.new(attributes) }
53
- end
17
+ @comparing ||= @ga_data.construct(:second)
54
18
  end
55
19
 
56
20
  def rows
57
- @rows ||= begin
58
- rows = []
59
-
60
- data.try(:rows).try(:each) do |row|
61
- dimension_values = row.dimensions
62
- primary_data = []
63
- comparing_data = []
64
-
65
- row.metrics.first.values.each do |value|
66
- primary_data << value
67
- end
68
-
69
- if row.metrics.second
70
- row.metrics.second.values.each do |value|
71
- comparing_data << value
72
- end
73
- end
74
-
75
- rows << {
76
- dimensions: OpenStruct.new(Hash[dimensions.zip(dimension_values)]),
77
- primary: OpenStruct.new(Hash[metrics.zip(primary_data)]),
78
- comparing: OpenStruct.new(Hash[metrics.zip(comparing_data)]) }
79
- end
80
-
81
- rows.map { |attributes| OpenStruct.new(attributes) }
82
- end
21
+ @rows ||= @ga_data.rows
83
22
  end
84
23
 
85
24
  def total_values
@@ -88,57 +27,15 @@ module Hisui
88
27
  end
89
28
 
90
29
  def primary_total
91
- @primary_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.first.values)])
30
+ @primary_total ||= @ga_data.sum(:first)
92
31
  end
93
32
 
94
33
  def comparing_total
95
- @comparing_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.try(:second).try(:values) || [])])
34
+ @comparing_total ||= @ga_data.sum(:second)
96
35
  end
97
36
 
98
37
  def data?
99
- data.row_count.to_i > 0
100
- end
101
-
102
- private
103
-
104
- def column_header
105
- @column_header ||= response.reports.first.column_header
106
- end
107
-
108
- def dimensions
109
- @dimensions ||= begin
110
- column_header.dimensions.each_with_object([]) do |dimension, arr|
111
- arr << Hisui.from_ga_string(dimension)
112
- end
113
- end
114
- end
115
-
116
- def metrics
117
- @metrics ||= begin
118
- column_header.metric_header.metric_header_entries.each_with_object([]) do |metric, arr|
119
- arr << Hisui.from_ga_string(metric.name)
120
- end
121
- end
122
- end
123
-
124
- def fields
125
- @fields ||= begin
126
- fields = []
127
-
128
- column_header.dimensions.each do |dimension|
129
- fields << Hisui.from_ga_string(dimension)
130
- end
131
-
132
- column_header.metric_header.metric_header_entries.each do |metric|
133
- fields << Hisui.from_ga_string(metric.name)
134
- end
135
-
136
- fields
137
- end
138
- end
139
-
140
- def data
141
- @data ||= response.reports.first.data
38
+ @ga_data.data?
142
39
  end
143
40
  end
144
41
  end
@@ -0,0 +1,105 @@
1
+ module Hisui
2
+ class Response
3
+ class GaData
4
+ attr_reader :response
5
+
6
+ def initialize(response)
7
+ @response = response
8
+ end
9
+
10
+ def construct(ordinal)
11
+ row_data_struct = Struct.new(*fields)
12
+
13
+ data.try(:rows).try(:each_with_object, []) do |row, arr|
14
+ row_data = []
15
+ row.dimensions.each do |dimension|
16
+ row_data << dimension
17
+ end
18
+
19
+ row.try(:metrics).try(ordinal.to_sym).try(:values).try(:each) do |value|
20
+ row_data << value
21
+ end
22
+
23
+ arr << row_data_struct.new(*row_data)
24
+ end
25
+ end
26
+
27
+ def sum(ordinal)
28
+ total_struct = Struct.new(*metrics)
29
+ total_struct.new(*data.totals.try(ordinal).try(:values))
30
+ end
31
+
32
+ def rows
33
+ @rows ||= begin
34
+ data.try(:rows).try(:each_with_object, []) do |row, arr|
35
+ dimension_values = row.dimensions
36
+ primary_data = []
37
+ comparing_data = []
38
+
39
+ row.metrics.first.values.each do |value|
40
+ primary_data << value
41
+ end
42
+
43
+ if row.metrics.second
44
+ row.metrics.second.values.each do |value|
45
+ comparing_data << value
46
+ end
47
+ end
48
+
49
+ rows_struct = Struct.new(:dimensions, :primary, :comparing)
50
+ dimension_struct = Struct.new(*dimensions)
51
+ metric_struct = Struct.new(*metrics)
52
+
53
+ arr << rows_struct.new(dimension_struct.new(*dimension_values), metric_struct.new(*primary_data), metric_struct.new(*comparing_data))
54
+ end
55
+ end
56
+ end
57
+
58
+ def data?
59
+ data.row_count.to_i > 0
60
+ end
61
+
62
+ private
63
+
64
+ def column_header
65
+ @column_header ||= response.reports.first.column_header
66
+ end
67
+
68
+ def dimensions
69
+ @dimensions ||= begin
70
+ column_header.dimensions.each_with_object([]) do |dimension, arr|
71
+ arr << Hisui.from_ga_string(dimension).to_sym
72
+ end
73
+ end
74
+ end
75
+
76
+ def metrics
77
+ @metrics ||= begin
78
+ column_header.metric_header.metric_header_entries.each_with_object([]) do |metric, arr|
79
+ arr << Hisui.from_ga_string(metric.name).to_sym
80
+ end
81
+ end
82
+ end
83
+
84
+ def fields
85
+ @fields ||= begin
86
+ fields = []
87
+
88
+ column_header.dimensions.each do |dimension|
89
+ fields << Hisui.from_ga_string(dimension).to_sym
90
+ end
91
+
92
+ column_header.metric_header.metric_header_entries.each do |metric|
93
+ fields << Hisui.from_ga_string(metric.name).to_sym
94
+ end
95
+
96
+ fields
97
+ end
98
+ end
99
+
100
+ def data
101
+ @data ||= response.reports.first.data
102
+ end
103
+ end
104
+ end
105
+ end
@@ -1,3 +1,3 @@
1
1
  module Hisui
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ikepon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-03 00:00:00.000000000 Z
11
+ date: 2018-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -172,6 +172,7 @@ files:
172
172
  - lib/hisui/model.rb
173
173
  - lib/hisui/request.rb
174
174
  - lib/hisui/response.rb
175
+ - lib/hisui/response/ga_data.rb
175
176
  - lib/hisui/user.rb
176
177
  - lib/hisui/version.rb
177
178
  homepage: https://github.com/ikepon/hisui