15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rspec/webservice_matchers/be_fast.rb', line 15
def self.page_speed_score(url:)
url_param = CGI.escape(Util.make_url(url))
key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
if key.nil?
fail 'be_fast requires the WEBSERVICE_MATCHER_INSIGHTS_KEY '\
'environment variable to be set to a Google PageSpeed '\
'Insights API key.'
end
endpoint = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed'
api_url = "#{endpoint}?url=#{url_param}&screenshot=false&key=#{key}"
BeFast.parse(json: Excon.get(api_url).body)[:score]
end
|