Module: PagespeedGrabber

Defined in:
lib/pagespeed_grabber.rb

Constant Summary collapse

URL =
'http://www.webpagetest.org'
VERSION =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
DEFAULT_TIMEOUT =
100
TIME_BETWEEN_TRIES =
10
'Raw page data'
HEADERS =
["Load Time (ms)", "Other Responses (Doc)", "Connections", "Minify Savings", "Experimental", "IP Address", "ETag Score", "GZIP Score", "DNS Lookups", "Event Name", "Not Found", "Segments Transmitted", "Keep-Alive Score", "Time", "Not Modified", "Cookie Score", "Measurement Type", "Gzip Savings", "Time to Base Page Complete (ms)", "One CDN Score", "OK Responses", "Error Code", "unused", "Requests", "Other Responses", "Includes Object Data", "Minify Total Bytes", "Flagged Requests", "AFT (ms)", "Packet Loss (out)", "Compression Score", "URL", "OK Responses (Doc)", "Combine Score", "Base Page Result", "Doc Complete Time (ms)", "Redirects (Doc)", "Pagetest Build", "Minify Score", "Time to Start Render (ms)", "Cache Score", "Base Page Redirects", "Bytes Out (Doc)", "Descriptor", "Dialer ID", "Connection Type", "Activity Time(ms)", "Time to First Byte (ms)", "Date", "Not Found (Doc)", "Redirects", "Not Modified (Doc)", "Event GUID", "Event URL", "Requests (Doc)", "Bytes In (Doc)", "Time to DOM Element (ms)", "Static CDN Score", "Optimization Checked", "Image Savings", "Connections (Doc)", "Flagged Connections", "Max Simultaneous Flagged Connections", "Cached", "Gzip Total Bytes", "Bytes Out", "Bytes In", "DNS Lookups (Doc)", "Segments Retransmitted", "DOCTYPE Score", "Image Total Bytes", "Host", "Lab ID"]

Class Method Summary collapse

Class Method Details

.csv_to_array(csv) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/pagespeed_grabber.rb', line 39

def self.csv_to_array(csv)
  data = []
  FasterCSV.parse(csv, :headers=>true) do |row|
    data << row.to_hash
  end
  data
end

.download_csv(test_url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pagespeed_grabber.rb', line 20

def self.download_csv(test_url)
  agent = Mechanize.new
  page = agent.get(URL)
  form = page.forms.first
  form.field_with('url').value = test_url
  page = form.submit

  url = page.uri.to_s
  link = nil

  loop do
    sleep TIME_BETWEEN_TRIES
    page = agent.get(url)
    break if link = page.link_with(:text => CSV_LINK)
  end

  agent.get(URL + link.href).body
end

.fetch(test_url, options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/pagespeed_grabber.rb', line 14

def self.fetch(test_url, options={})
  Timeout.timeout(options[:timeout]||DEFAULT_TIMEOUT) do
    csv_to_array(download_csv(test_url))
  end
end