g_ruby 0.0.7 → 0.0.8

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/g_ruby/analytics.rb +62 -59
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d4c66b33befa89ea4aa6b22cbae4d35cd82ed60
4
- data.tar.gz: c451c48de3905e79524348668721aa9831d515ea
3
+ metadata.gz: bf7759a53575d6479d1b10778938fb30390e9c2d
4
+ data.tar.gz: e850aabc50186eb77aa6b7a0963dc6d9fa75e204
5
5
  SHA512:
6
- metadata.gz: d7e884830ee87f0629bae61f619465170cc7026e9ed1098dd464f732944d949c77cde05b9d5419bb1dd87f595f4e7c1bf297368fbe1a34feeca0a3e2ee6bf855
7
- data.tar.gz: f47a1947f327aeac4f81155170eb3f93fe7d158a41701cea7182d3db96f3671cc49a5e55521617e8dab1c9b64658389c40406fc25a92df29946df0d4ffa32194
6
+ metadata.gz: 3724e6611ee774b899eb0612703d5683ceec520cd2c622d4b55249df5822d5f7be83d3e38b6d505c197edb104dfc9b6b545150c818c74f64bff3e8bd74636b3d
7
+ data.tar.gz: 4f6a0340cbc7287a3e8b6b930d4042043e431d6514cb5acd15fc2acd94515506aca012286b6d8ea7b9de43f4fbe3a505b6b67769a9f30e0a9d6923d995738159
@@ -96,75 +96,78 @@ class GRuby::Analytics
96
96
  #GRuby::Analytics.get_with_delta(access_token, start_date, end_date, profile_id, metrics, dimensions, sort, max_results)
97
97
  def self.get_with_delta(access_token, start_date, end_date, profile_id, metrics, dimensions=nil, sort=nil, limit=nil, refresh=nil)
98
98
  #begin
99
+
100
+ response_obj = []
101
+
99
102
  d30_days_ago = (Date.today - 30).to_time.strftime("%Y-%m-%d").to_s
100
103
  d60_days_ago = (Date.today - 60).to_time.strftime("%Y-%m-%d").to_s
101
104
  date_today = Time.now.strftime("%Y-%m-%d")
102
105
 
103
106
  a0 = GRuby::Analytics.get(access_token, start_date, end_date, profile_id, metrics, dimensions, sort, limit)
104
- a30 = GRuby::Analytics.get(access_token, d30_days_ago, date_today, profile_id, metrics, dimensions, sort, nil)
105
- a60 = GRuby::Analytics.get(access_token, d60_days_ago, d30_days_ago, profile_id, metrics, dimensions, sort, nil)
106
-
107
- if a0.class.to_s != "Array"
108
- return a0 if a0[:status] == "failed"
109
- elsif a30.class.to_s != "Array"
110
- return a30 if a0[:status] == "failed"
111
- elsif a60.class.to_s != "Array"
112
- return a60 if a0[:status] == "failed"
113
- end
114
-
115
- response_obj = []
107
+ if a0.blank?
108
+ a30 = GRuby::Analytics.get(access_token, d30_days_ago, date_today, profile_id, metrics, dimensions, sort, nil)
109
+ a60 = GRuby::Analytics.get(access_token, d60_days_ago, d30_days_ago, profile_id, metrics, dimensions, sort, nil)
116
110
 
117
- if dimensions.blank?
118
- metrics.split(",").each do |metric|
119
- d_this = a30[metric].to_i
120
- d_last = a60[metric].to_i
121
- dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
122
- if d_last == 0
123
- response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: 0, delta_explaination: dd}
124
- else
125
- response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: ((d_this - d_last) * 100 / d_last), delta_explaination: dd}
126
- end
111
+ if a0.class.to_s != "Array"
112
+ return a0 if a0[:status] == "failed"
113
+ elsif a30.class.to_s != "Array"
114
+ return a30 if a0[:status] == "failed"
115
+ elsif a60.class.to_s != "Array"
116
+ return a60 if a0[:status] == "failed"
127
117
  end
128
- elsif dimensions.split(",").count == 1 and metrics.split(",").count == 1
129
- a0.each do |i|
130
- d_this = nil
131
- d_last = nil
132
- a30.each do |j|
133
- d_this = j[1].to_i if j[0] == i[0]
134
- end
135
- a60.each do |k|
136
- d_last = k[1].to_i if k[0] == i[0]
137
- end
138
- dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
139
- if d_last == 0
140
- del = 0
141
- else
142
- del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
143
- end
144
- response_obj << {tag: metrics.gsub("ga:", ""), val: i[1], dimension: i[0], delta: del, delta_explaination: dd}
145
- end
146
- elsif dimensions.split(",").count > 1 and metrics.split(",").count == 1
147
- a0.each do |i|
148
- d_this = nil
149
- d_last = nil
150
- if dimensions == "ga:source,ga:medium"
151
- k3 = i[1]=='referral' ? 'OtherSources' : (i[1]=='(none)' and i[0]=="(direct)") ? 'DirectSource' : 'searchEngine'
152
- elsif dimensions == "ga:keyword,ga:medium"
153
- k3 = i[1] == 'organic' ? 'OrganicKeywords' : 'PaidKeywords'
154
- end
155
- a30.each do |j|
156
- d_this = j[2] if (j[0] == i[0] and j[1] == i[1])
118
+
119
+ if dimensions.blank?
120
+ metrics.split(",").each do |metric|
121
+ d_this = a30[metric].to_i
122
+ d_last = a60[metric].to_i
123
+ dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
124
+ if d_last == 0
125
+ response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: 0, delta_explaination: dd}
126
+ else
127
+ response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: ((d_this - d_last) * 100 / d_last), delta_explaination: dd}
128
+ end
157
129
  end
158
- a60.each do |k|
159
- d_last = k[2] if (k[0] == i[0] and k[1] == i[1])
130
+ elsif dimensions.split(",").count == 1 and metrics.split(",").count == 1
131
+ a0.each do |i|
132
+ d_this = nil
133
+ d_last = nil
134
+ a30.each do |j|
135
+ d_this = j[1].to_i if j[0] == i[0]
136
+ end
137
+ a60.each do |k|
138
+ d_last = k[1].to_i if k[0] == i[0]
139
+ end
140
+ dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
141
+ if d_last == 0
142
+ del = 0
143
+ else
144
+ del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
145
+ end
146
+ response_obj << {tag: metrics.gsub("ga:", ""), val: i[1], dimension: i[0], delta: del, delta_explaination: dd}
160
147
  end
161
- dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
162
- if d_last.to_f == 0
163
- del = 0
164
- else
165
- del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
148
+ elsif dimensions.split(",").count > 1 and metrics.split(",").count == 1
149
+ a0.each do |i|
150
+ d_this = nil
151
+ d_last = nil
152
+ if dimensions == "ga:source,ga:medium"
153
+ k3 = i[1]=='referral' ? 'OtherSources' : (i[1]=='(none)' and i[0]=="(direct)") ? 'DirectSource' : 'searchEngine'
154
+ elsif dimensions == "ga:keyword,ga:medium"
155
+ k3 = i[1] == 'organic' ? 'OrganicKeywords' : 'PaidKeywords'
156
+ end
157
+ a30.each do |j|
158
+ d_this = j[2] if (j[0] == i[0] and j[1] == i[1])
159
+ end
160
+ a60.each do |k|
161
+ d_last = k[2] if (k[0] == i[0] and k[1] == i[1])
162
+ end
163
+ dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
164
+ if d_last.to_f == 0
165
+ del = 0
166
+ else
167
+ del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
168
+ end
169
+ response_obj << {tag: i[0], val: i[2], dimension: k3, delta: del, delta_explaination: dd}
166
170
  end
167
- response_obj << {tag: i[0], val: i[2], dimension: k3, delta: del, delta_explaination: dd}
168
171
  end
169
172
  end
170
173
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pykih Software