Skip to content

Commit

Permalink
add googlebot_mobile user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Migoo committed Mar 15, 2012
1 parent 179acf1 commit 399665b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/user_agent.rb
Expand Up @@ -56,7 +56,7 @@ def initialize(product, version=nil, comment=nil)
else else
raise ArgumentError, "expected a value for product" raise ArgumentError, "expected a value for product"
end end

if version && !version.empty? if version && !version.empty?
@version = version @version = version
else else
Expand Down
4 changes: 3 additions & 1 deletion lib/user_agent/browsers.rb
Expand Up @@ -4,6 +4,7 @@
require 'user_agent/browsers/internet_explorer' require 'user_agent/browsers/internet_explorer'
require 'user_agent/browsers/webkit' require 'user_agent/browsers/webkit'
require 'user_agent/browsers/googlebot' require 'user_agent/browsers/googlebot'
require 'user_agent/browsers/googlebot_mobile'
require 'user_agent/browsers/gecko' require 'user_agent/browsers/gecko'


class UserAgent class UserAgent
Expand All @@ -18,7 +19,8 @@ module Browsers
def self.all def self.all
# Opera must be checked before Firefox due to the odd user agents used in some older versions of Opera # 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 # 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 end


def self.extend(array) def self.extend(array)
Expand Down
37 changes: 37 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions 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.