slack_page_speed 0.0.8 → 0.0.9

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/slack_page_speed.rb +12 -41
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e471a023a7b3da86129fb1778186644208c0174e
4
- data.tar.gz: b8b8233436752ed9bb85d1c2ce27f795ea1e4782
3
+ metadata.gz: a1f2ee944b27870c04b4c53165b2be99bebc37ab
4
+ data.tar.gz: 9044bc0f9b50ba3224915bc1cca55ff906a3c0df
5
5
  SHA512:
6
- metadata.gz: ee04bfebdb8aaa77d94e04c7535a2f4003d77094dc5e62c97743705192520cd86b4dc08b8d27d5c16028d1a4b6afdad355f2545a86dfc54281cab273658e9f11
7
- data.tar.gz: f418d704cb4f9903728705a1b2b3fdfbdf7e6bd89ff3f7855e78c7837c66e0eac4ce8e71835a7eab67644b1d0006b88464ae8c025ee57c5f2dee29b43d614c49
6
+ metadata.gz: 01e423e75ef8941ff47322902900710c4b7bd470fc3c0a54828526c6c95d4e55e469e92d3671a6a0c09ed05a17cc7a2f339ebc56307636092f293db93c0106dd
7
+ data.tar.gz: 7fb328d2e6701dfed3d2041bbab6d2ab98a4bbb9b3171217279c1779e54d6b56b1607a1507b1e10a46de99a85220afc67d1b207423acb4fdafc4df3b7b7c3e96
@@ -22,43 +22,19 @@ class SlackPageSpeed
22
22
  @message = configuration_info['include_timestamp'] ? "Page performance scores for #{Date.today.strftime('%d/%m/%Y')}. \n" : ''
23
23
  @threshold = configuration_info['threshold'].to_i
24
24
  @results = {}
25
- # @page_list = %w(
26
- # credit-cards/
27
- # life-insurance/
28
- # energy/
29
- # home-insurance/
30
- # travel-insurance/
31
- # car-insurance/
32
- # Homepage
33
- # )
34
25
  @page_list = configuration_info['page_list']
26
+ @logging = configuration_info['logging']
35
27
 
36
- # @run_results = [{}, {}, {}]
37
- @run_results = [{}]
28
+ @run_results = [{}, {}, {}]
38
29
  @page_list.each do |page|
39
30
  search_string = page.gsub('-', '+').gsub('/', '')
40
- search_string = search_string + '+switch' if page == 'energy/'
41
- search_string = 'compare+the+market' if page == 'Homepage'
42
31
  @results[page] = { search_string: search_string }
43
32
  @run_results.each do |run_result|
44
33
  run_result[page] = { search_string: search_string }
45
34
  end
46
35
  end
47
36
 
48
- # Gets google page rank
49
- def get_gpr(page, search_string, iteration)
50
- puts page
51
- response = JSON.parse(HTTParty.get("https://www.googleapis.com/customsearch/v1element?key=#{@pagespeed_api_key}&rsz=filtered_cse&num=10&hl=en&prettyPrint=false&source=gcsc&gss=.com&q=#{search_string}&sort=&googlehost=www.google.co.uk&oq=#{search_string}&gs_l=partner.12...31030.31885.0.34635.7.7.0.0.0.0.73.428.7.7.0.gsnos%2Cn%3D13...0.864j151518j7..1ac.1.25.partner..7.0.0.-WiGDitO8Y8&callback=google.search.Search.apiary19818&nocache=1502961217931").body.chomp[49..-3])
52
- begin
53
- @run_results[iteration][page][:rank] = response['results'].index { |result_property| result_property['url'].include? 'comparethemarket.com' } + 1
54
- rescue NoMethodError => e
55
- puts "Not on the front page of Google results for '#{page}'.\nResults were: \n"
56
- response['results'].each { |result| puts result['url'] }
57
- raise e
58
- end
59
- end
60
-
61
- # Gets google pagespeed score for a 'page'
37
+ # Gets google pagespeed score for a 'page'
62
38
  def get_gps_score(page, strategy, iteration)
63
39
  response = HTTParty.get("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=#{@domain + page.gsub('Homepage', '') + '?src=TSTT'}&strategy=#{strategy}&key=#{@pagespeed_api_key}")
64
40
  unless response.response.code == '200' && JSON.parse(response.body)['responseCode'] != '400'
@@ -69,14 +45,14 @@ class SlackPageSpeed
69
45
  @run_results[iteration][page][strategy.to_sym] = score
70
46
  end
71
47
 
72
- # runs a new WebPageTest test based on the url supplied
48
+ # runs a new WebPageTest test based on the url supplied
73
49
  def start_wpt_test(page, iteration)
74
50
  response = HTTParty.get("http://www.webpagetest.org/runtest.php?url=#{@domain + page.gsub('Homepage', '') + '?src=TSTT'}&location=Dulles.3G&f=json&fvonly=1&k=#{@webpagetest_api_key}")
75
51
  raise "Couldn't get WebPageTest score for #{page}" unless response.response.code == '200'
76
52
  @run_results[iteration][page][:results_url] = JSON.parse(response.body)['data']['jsonUrl']
77
53
  end
78
54
 
79
- # waits until the status of the run at 'results_url' is 200 (test finished)
55
+ # waits until the status of the run at 'results_url' is 200 (test finished)
80
56
  def wait_for_wpt_results(page, result_url, iteration)
81
57
  361.times do
82
58
  @response = HTTParty.get(result_url)
@@ -87,7 +63,7 @@ class SlackPageSpeed
87
63
  @run_results[iteration][page][:speed_index] = (JSON.parse(@response.body)['data']['runs']['1']['firstView']['SpeedIndex'].to_f / 1000).round(2)
88
64
  end
89
65
 
90
- # Send a slack message with all the scores
66
+ # Send a slack message with all the scores
91
67
  def slack_notify(message)
92
68
  HTTParty.post(@slack_post_url,
93
69
  body: { 'channel': "##{@slack_channel}", 'icon_emoji': @slack_bot_emoji, 'username': @slack_username, 'text': message }.to_json,
@@ -138,7 +114,6 @@ class SlackPageSpeed
138
114
  @page_list.each do |page|
139
115
  @run_results.length.times do |iteration|
140
116
  start_wpt_test(page, iteration)
141
- # get_gpr(page, @results[page][:search_string], iteration)
142
117
  end
143
118
  end
144
119
 
@@ -156,27 +131,24 @@ class SlackPageSpeed
156
131
  end
157
132
 
158
133
  # Reset the temporary results array
159
- # @results[page][:rank] = []
160
134
  @results[page][:speed_index] = []
161
135
  @results[page][:desktop] = []
162
136
  @results[page][:mobile] = []
163
137
 
164
138
  # Add all results to an array of results for each numerical result type
165
139
  @run_results.each do |result|
166
- # @results[page][:rank].push(result[page][:rank])
167
140
  @results[page][:speed_index].push(result[page][:speed_index])
168
141
  @results[page][:desktop].push(result[page][:desktop])
169
142
  @results[page][:mobile].push(result[page][:mobile])
170
143
  end
171
144
 
172
145
  # Calculate the mean speed, desktop and mobile scores, and the mode search ranking
173
- # @results[page][:rank] = @results[page][:rank].max_by { |i| @results[page][:rank].count(i) }
174
146
  @results[page][:desktop] = @results[page][:desktop].max_by { |i| @results[page][:desktop].count(i) }
175
147
  @results[page][:mobile] = @results[page][:mobile].max_by { |i| @results[page][:mobile].count(i) }
176
148
  @results[page][:speed_index] = (@results[page][:speed_index].inject(:+)/@run_results.length).round(2)
177
149
 
178
150
  # Build the slack message
179
- puts @results if ENV['logging'] == 'true'
151
+ puts @results if @logging
180
152
  @message += "\n*" + page + ':*'
181
153
  @message += "\n desktop score: " + @results[page][:desktop].to_s
182
154
  @message += get_old_score(@results[page][:desktop], page, :desktop)
@@ -184,22 +156,20 @@ class SlackPageSpeed
184
156
  @message += get_old_score(@results[page][:mobile], page, :mobile)
185
157
  @message += "\n SpeedIndex: " + @results[page][:speed_index].to_s
186
158
  @message += get_old_score(@results[page][:speed_index].to_f, page, :speed_index) + "\n"
187
- # @message += "\n Google Search Rank: " + @results[page][:rank].to_s
188
- # @message += get_old_score(@results[page][:rank].to_f, page, :rank) + "\n"
189
159
  end
190
160
 
191
- # Add an '@here' to the slack notification if any score has regressed
161
+ # Add an '@here' to the slack notification if any score has regressed
192
162
  @message += ' <!here> Something is worse than last time!' if @message.include?(@regression_emoji)
193
163
  puts @message
194
164
  slack_notify(@message)
195
- # Create the scores history file if this is the first run
165
+ # Create the scores history file if this is the first run
196
166
  File.new(@history_file, 'w') unless File.exist?(@history_file)
197
167
  write_new_scores
198
168
  end
199
169
 
200
170
  def configure
201
171
  config_file = File.open('configuration.yml', 'w+')
202
- config_file.write("""---
172
+ config_file.write("" "---
203
173
  ##############
204
174
  ## Required ##
205
175
  ##############
@@ -221,6 +191,7 @@ improvement_emoji: ':racehorse:'
221
191
  minimal_change_emoji: ':no_mouth:'
222
192
  regression_emoji: ':no-entry:'
223
193
  include_timestamp: true
224
- threshold: '2'""")
194
+ threshold: '2'
195
+ logging: true" "")
225
196
  end
226
197
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_page_speed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abi Travers, Andy Barnett, Dan Clissold, Tom Dane