Permalink
Browse files

add googlebot_mobile user agent

  • Loading branch information...
1 parent 179acf1 commit 399665bfd6bc0769af8fe8f8fe7c5cde07242cc3 @Migoo Migoo committed Mar 15, 2012
View
2 lib/user_agent.rb
@@ -56,7 +56,7 @@ def initialize(product, version=nil, comment=nil)
else
raise ArgumentError, "expected a value for product"
end
-
+
if version && !version.empty?
@version = version
else
View
4 lib/user_agent/browsers.rb
@@ -4,6 +4,7 @@
require 'user_agent/browsers/internet_explorer'
require 'user_agent/browsers/webkit'
require 'user_agent/browsers/googlebot'
+require 'user_agent/browsers/googlebot_mobile'
require 'user_agent/browsers/gecko'
class UserAgent
@@ -18,7 +19,8 @@ module Browsers
def self.all
# Opera must be checked before Firefox due to the odd user agents used in some older versions of Opera
# Googlebot must be checked before Gecko because 2.1 uses Mozilla as user-agent
- [Other, Opera, InternetExplorer, Webkit, Googlebot, Gecko]
+ # Googlebot mobile must be checked before Webkit and Googlebot
+ [Other, Opera, InternetExplorer, GooglebotMobile, Webkit, Googlebot, Gecko]
end
def self.extend(array)
View
37 lib/user_agent/browsers/googlebot_mobile.rb
@@ -0,0 +1,37 @@
+class UserAgent
+ module Browsers
+ module GooglebotMobile
+ def self.extend?(agent)
+ agent.detect_user_agent_by_product_or_comment('Googlebot-Mobile')
+ end
+
+ def browser
+ "Googlebot-Mobile"
+ end
+
+ def version
+ (application.product == 'Safari' &&
+ application.comment &&
+ application.comment[1]) ?
+ application.comment[1].sub("Googlebot-Mobile/", "") :
+ application.version.sub(';', '')
+ end
+
+ def compatibility
+ application.comment ? application.comment[0] : nil
+ end
+
+ def compatible?
+ compatibility == "compatible"
+ end
+
+ def crawler?
+ true
+ end
+
+ def mobile?
+ true
+ end
+ end
+ end
+end
View
21 spec/user_agent/browsers/googlebot_mobile_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe UserAgent::Browsers::GooglebotMobile do
+
+ describe "Googlebot-Mobile" do
+ it { "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)".
+ should be_browser("Googlebot-Mobile").
+ platform('iPhone').
+ security(:strong).
+ webkit_version('532.9').
+ build('532.9').
+ language('en-US').
+ compatible(true).
+ version("2.1").
+ crawler(true).
+ mobile(true) }
+ it { "Googlebot-Mobile/2.1; +http://www.google.com/bot.html".should be_browser("Googlebot-Mobile").version("2.1").crawler(true).mobile(true) }
+ end
+
+end
+

0 comments on commit 399665b

Please sign in to comment.