Module: PageSpeed
- Defined in:
- lib/page_speed.rb,
lib/page_speed/version.rb
Constant Summary collapse
- VERSION =
"0.1.5"
Class Method Summary collapse
- .analyze(url) ⇒ Object
- .api_key_exists? ⇒ Boolean
- .get_api_key ⇒ Object
- .help ⇒ Object
- .set_api_key(key) ⇒ Object
- .usage ⇒ Object
- .version ⇒ Object
Class Method Details
.analyze(url) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/page_speed.rb', line 19 def analyze(url) begin # Parse URL uri = get_uri(url) # Get scores desktop, mobile = scores_for(uri) # Show results show_results(uri, desktop, mobile) rescue URI::InvalidURIError puts "Please check your URL and try again." rescue OpenURI::HTTPError puts "The API you used is not correct. Use the -k option to replace it." reset_api_key help rescue Exception => e puts "There has been an unexpected error:" puts e. puts e.backtrace.inspect end end |
.api_key_exists? ⇒ Boolean
70 71 72 73 74 75 76 77 78 |
# File 'lib/page_speed.rb', line 70 def api_key_exists? begin get_api_key true rescue Exception => e p e false end end |
.get_api_key ⇒ Object
63 64 65 66 67 68 |
# File 'lib/page_speed.rb', line 63 def get_api_key file = File.new(api_key_path, "r") api_key = file.gets file.close api_key end |
.help ⇒ Object
45 46 47 48 |
# File 'lib/page_speed.rb', line 45 def help version usage end |
.set_api_key(key) ⇒ Object
59 60 61 |
# File 'lib/page_speed.rb', line 59 def set_api_key(key) File.open(api_key_path, "w") {|f| f.write(key) } end |
.usage ⇒ Object
54 55 56 57 |
# File 'lib/page_speed.rb', line 54 def usage puts "usage: page_speed url | [ -k key | --key key ] | [ -v | --version ] | [ -h | --help ]" puts "You can get your key at http://code.google.com/intl/en-EN/apis/pagespeedonline/v1/getting_started.html" end |