active_device 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -4,6 +4,18 @@ ActiveDevice : Open Mobile Device Detector
4
4
  Mobile and Devices User Agent Detector, For Mobile Handsets, Devices and Desktop Browsers.
5
5
  For Detect the Mobile and Recognize its Brand, Model, Engine, OS and Browser.
6
6
 
7
+ Installation
8
+ ============
9
+
10
+ Install the gem from gemcutter:
11
+
12
+ sudo gem install active_device
13
+
14
+ You can also install this as a plugin:
15
+
16
+ script/plugin install git://github.com/shenoudab/active_device.git
17
+
18
+
7
19
  Usage
8
20
  =======
9
21
 
@@ -27,10 +39,31 @@ Add this line to your Application Controller
27
39
 
28
40
  skip_before_filter :set_mobile_format
29
41
 
30
-
31
42
  Example
32
43
  =======
33
44
 
45
+ Examples from ActiveDevice Helper Methods.
46
+
47
+ is_mobile_device? : Checking if the Request from Mobile Device
48
+ is_mobile_browser?
49
+ is_bot?
50
+
51
+ is_device? 'iphone'
52
+ is_brand? 'Nokia'
53
+ is_model? 'NokiaE72'
54
+
55
+ device_model : Return the Device Model if Mobile.
56
+ device_brand : Return the Device Brand if Mobile.
57
+
58
+ agent_engine : Reurn the Useragnet Engine.
59
+ agent_os : Return Useragent Device OS.
60
+
61
+ Feedback
62
+ ========
63
+
64
+ Send Feedback and questions to: sbertel at mobithought.com
65
+
66
+
34
67
  More will Coming Soon, Wait for MobiThought
35
68
 
36
- Copyright (c) 2009 Shenouda Bertel, MobiThought, released under the MIT license
69
+ Copyright (c) 2009 Shenouda Bertel, MobiThought, released under the MIT license
data/Rakefile CHANGED
@@ -28,7 +28,7 @@ PKG_FILES = FileList[ '[a-zA-Z]*', 'generators/**/*', 'lib/**/*', 'rails/**/*',
28
28
 
29
29
  spec = Gem::Specification.new do |s|
30
30
  s.name = "active_device"
31
- s.version = "1.0.0"
31
+ s.version = "1.0.1"
32
32
  s.authors = ["Shenouda Bertel"]
33
33
  s.description = "Device UserAgent Detector"
34
34
  s.email = "sbertel@mobithought.com"
data/lib/active_device.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009 Shenouda Bertel <sbertel@mobithought.com>
2
+ # Copyright (c) 2009 Shenouda Bertel <sbertel@mobithought.com>, MobiThought.
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -84,50 +84,50 @@ module ActiveDevice
84
84
  Bot.is_bot? request.user_agent
85
85
  end
86
86
 
87
- # Can check for a specific user agent
87
+ # Can check for a specific type
88
88
  # e.g., is_device?('iphone') or is_device?('mobileexplorer')
89
89
 
90
90
  def is_device? type
91
91
  request.user_agent.to_s.downcase.include?(type.to_s.downcase)
92
92
  end
93
93
 
94
- # Can check for a specific user agent
95
- # e.g., is_device?('iphone') or is_device?('mobileexplorer')
94
+ # Can check for a specific type
95
+ # e.g., is_handset?('iphone') or is_handset?('mobileexplorer')
96
96
 
97
97
  def is_handset? type
98
98
  Handset.is_handset? request.user_agent, type
99
99
  end
100
100
 
101
- # Can check for a specific user agent
102
- # e.g., is_device?('iphone') or is_device?('mobileexplorer')
101
+ # Can check for a specific brand
102
+ # e.g., is_brand?('Nokia') or is_brand?('HTC')
103
103
 
104
104
  def is_brand? brand
105
105
  Handset.is_brand? request.user_agent, brand
106
106
  end
107
107
 
108
- # Can check for a specific user agent
109
- # e.g., is_device?('iphone') or is_device?('mobileexplorer')
108
+ # Can check for a specific Mobile Model
109
+ # e.g., is_model?('NokiaE72') or is_model?('Nokia6630')
110
110
 
111
111
  def is_model? model
112
112
  Handset.is_model? request.user_agent, model
113
113
  end
114
114
 
115
- # Can check for a specific user agent
116
- # e.g., is_device?('iphone') or is_device?('mobileexplorer')
115
+ # Can check for a specific OS
116
+ # e.g., is_os?('SymbianOS') or is_os?('Linux')
117
117
 
118
118
  def is_os? os
119
119
  Os.is_os? request.user_agent, os
120
120
  end
121
121
 
122
- # Can check for a specific user agent
123
- # e.g., is_device?('iphone') or is_device?('mobileexplorer')
122
+ # Can check for a specific Engine
123
+ # e.g., is_engine?('Webkit') or is_engine?('Chrome')
124
124
 
125
125
  def is_engine? engine
126
126
  Engine.is_engine? request.user_agent, engine
127
127
  end
128
128
 
129
129
  # Can check for a specific user agent
130
- # e.g., is_device?('iphone') or is_device?('mobileexplorer')
130
+ # e.g., is_browser?('Firefox') or is_browser?('Chrome')
131
131
 
132
132
  def is_browser? browser
133
133
  Browser.is_browser? request.user_agent, browser
@@ -1,90 +1,50 @@
1
- module ActiveDevice
2
- class Bot
3
- PREFIX = {
4
- # Common prefixes (mozilla not included)
5
- :common => %w(opera),
6
- # Mobile browser prefixes
7
- :embedded => %w(blackberry docomo waptiger winwap),
8
- # Textmode browser prefixes
9
- :text => %w(elinks lynx retawq w3m/) << "links ",
10
- # Uncommon browser prefixes
11
- :rare => %w(advanced amaya amiga aplix cyberdog dillo galaxy genius
12
- hotjava ibm ibrowse icab ice klondike ncsa netsurf openwave
13
- reqwirelessweb sunrise worldwideweb),
14
- # These usually are not prefixes in their normal UA string
15
- :odd => %w(android avant firefox k-meleon konqueror netscape safari
16
- seamonkey) }
1
+ class Bot
2
+
3
+ ##
4
+ # User agent string.
17
5
 
18
- ID = {
19
- :mobile => %w(^sec blackberry midp mmp netfront opera safari semc
20
- sonyericsson symbian up\\.browser up\\.link) << "windows ce",
21
- :moz_compatible => %w(amigavoyager antfresco aol applewebkit avant
22
- blackberry elaine gecko ibrowse icab khtml konqueror msie netfront netp
23
- netscape omniweb opera teleca voyager),
24
- :moz_platform => %w(amiga beos brew bsd danger dreamcast iphone ipod linux
25
- mac os/2 palm pda playstation ps2 ps3 psp risc star-blade sunos syllable
26
- symbian win x11 zx),
27
- :bot => %w(<a <script bot butterfly checker crawl daumoa del\\.icio\\.us
28
- depspid flycast heritrix httrack indexing ktxn larbin links-sql
29
- me\\.dium miro mozshot nutch odp-entries oneriot pbwf planetwide slurp
30
- spider survey thunderbird vermut) << "black widow" }
6
+ attr_reader :user_agent
31
7
 
32
- REGEXP = {
33
- :prefix => /^#{PREFIX.values.flatten! * "|^"}/,
34
- :mobile => /#{ID[:mobile] * "|"}/,
35
- :moz_compatible => /#{ID[:moz_compatible] * "|"}/,
36
- :moz_platform => /#{ID[:moz_platform] * "|"}/,
37
- :bot => /#{ID[:bot] * "|"}/ }
8
+ ##
9
+ # Initialize with user agent _string_.
38
10
 
39
- def is_bot?
40
- self.is_bot? user_agent
41
- end
42
-
43
- ##
44
- # User agent brand symbol.
45
- def self.is_bot? user_agent
46
- case user_agent
47
- when /bot/i ; true
48
- when /Spider/i ; true
49
- else ; false
50
- end
51
- end
52
-
53
- def robot?(user_agent)
54
- !browser?(user_agent)
55
- end
56
-
57
- def browser?(user_agent)
58
- # Empty string might be an anonymized browser
59
- return true if user_agent.nil? || user_agent =~ /^\s*$/
60
- ua_lc = user_agent.downcase
61
- if ua_lc[0,7] == "mozilla"
62
- is_browser = ua_lc =~ REGEXP[:moz_compatible] || ua_lc =~ REGEXP[:moz_platform]
63
- else
64
- is_browser = ua_lc =~ REGEXP[:prefix] || ua_lc =~ REGEXP[:mobile]
65
- end
66
- is_browser = ua_lc[REGEXP[:bot]].nil? if is_browser
67
- return is_browser
68
- end
11
+ def initialize user_agent
12
+ @user_agent = user_agent.strip
69
13
  end
70
14
 
71
- module BotHelper
72
- def robot?(user_agent)
73
- self.class.urobot.robot?(user_agent)
74
- end
75
-
76
- def browser?(user_agent)
77
- self.class.urobot.browser?(user_agent)
78
- end
79
-
80
- def self.included(base)
81
- base.extend(ClassMethods)
82
- end
83
-
84
- module ClassMethods
85
- def bot
86
- @bot ||= ActiveDevice::BOT.new
87
- end
15
+ ##
16
+ # Check UserAgent is Bot.
17
+ def self.is_bot? user_agent
18
+ case user_agent
19
+ when /bot/i ; true
20
+ when /Spider/i ; true
21
+ when /Butterfly/i ; true
22
+ when /Checker/i ; true
23
+ when /Crawl/i ; true
24
+ when /Daumoa/i ; true
25
+ when /Delicious/i ; true
26
+ when /del.icio.us/i ; true
27
+ when /Depspid/i ; true
28
+ when /Flycast/i ; true
29
+ when /Heritrix/i ; true
30
+ when /Httrack/i ; true
31
+ when /Indexing/i ; true
32
+ when /Ktxn/i ; true
33
+ when /Larbin/i ; true
34
+ when /Links-sql/i ; true
35
+ when /Me.dium/i ; true
36
+ when /Miro/i ; true
37
+ when /Mozshot/i ; true
38
+ when /Nutch/i ; true
39
+ when /odp-entries/i ; true
40
+ when /oneriot/i ; true
41
+ when /pbwf/i ; true
42
+ when /planetwide/i ; true
43
+ when /slurp/i ; true
44
+ when /Survey/i ; true
45
+ when /Thunderbird/i ; true
46
+ when /Vermut/i ; true
47
+ else ; false
88
48
  end
89
49
  end
90
50
 
@@ -1,6 +1,3 @@
1
- # To change this template, choose Tools | Templates
2
- # and open the template in the editor.
3
-
4
1
  class Browser
5
2
  ##
6
3
  # User agent string.
@@ -8,7 +5,7 @@ class Browser
8
5
  attr_reader :user_agent
9
6
 
10
7
  ##
11
- # Initialize with user agent _string_.
8
+ # Initialize with user agent _user_agent_.
12
9
 
13
10
  def initialize user_agent
14
11
  @user_agent = user_agent.strip
@@ -19,21 +16,155 @@ class Browser
19
16
 
20
17
  def self.name user_agent
21
18
  case user_agent
22
- when /Konqueror/i ; :Konqueror
23
- when /Safari/i ; :Safari
24
- when /MSIE/i ; :IE
25
- when /Chrome/i ; :Chrome
19
+ when /ABrowse/i ; :ABrowse
20
+ when /AbiLogicBot/i ; :AbiLogicBot # Link Checker
21
+ when /Acoo/i ; :'Acoo Browser'
22
+ when /Advanced/i ; :Advanced
23
+ when /America Online/i ; :'America Online Browser'
24
+ when /Amaya/i ; :Amaya
25
+ when /Amiga[\/ ]/i ; :Amiga
26
+ when /AmigaVoyager/i ; :AmigaVoyager
26
27
  when /Android/i ; :Android
27
- when /Opera Mini/i ; :'Opera Mini'
28
- when /Opera Mobi/i ; :'Opera Mobile'
29
- when /Opera/i ; :Opera
30
- when /playstation 3/i ; :PS3
31
- when /playstation portable/i ; :PSP
32
- when /SymbianOS/i ; :SymbianOS
33
- when /Symbian/i ; :Symbian
34
- when /iPhone/i ; :iPhone
35
- when /Firefox/i ; :Firefox
36
- when /Mozilla/i ; :Mozilla
28
+ when /AOL/i ; :AOL
29
+ when /Aplix/i ; :Aplix
30
+ when /Arora/i ; :Arora
31
+ when /Avant/i ; :Avant
32
+ when /Beonex/i ; :Beonex
33
+ when /Bloglines/i ; :Bloglines # Feed Reader
34
+ when /BonEcho/i ; :BonEcho
35
+ when /Camino/i ; :Camino
36
+ when /Charon/i ; :Charon
37
+ when /Cheshire/i ; :Cheshire
38
+ when /Chimera/i ; :Chimera
39
+ when /Chrome[\/ ]/i ; :Chrome
40
+ when /ChromePlus/i ; :ChromePlus
41
+ when /CometBird/i ; :CometBird
42
+ when /Crazy/i ; :Crazy
43
+ when /CSE HTML Validator/i ; :'CSE HTML Validator' # Validator
44
+ when /CSSCheck/i ; :CSSCheck # Validator
45
+ when /Cyberdog/i ; :Cyberdog
46
+ when /Cynthia/i ; :Cynthia # Validator
47
+ when /Deepnet/i ; :Deepnet
48
+ when /DeskBrowse/i ; :DeskBrowse
49
+ when /DOCOMO/i ; :DOCOMO #Embedded Mobile Based
50
+ when /Dillo/i ; :Dillo
51
+ when /Elinks/i ; :Elinks
52
+ when /Enigma/i ; :Enigma
53
+ when /Epiphany/i ; :Epiphany
54
+ when /Everyfeed-spider/i ; :'Everyfeed-spider' # Feed Reader
55
+ when /FeedFetcher-Google/i ; :'FeedFetcher-Google' # Feed Reader
56
+ when /Fennec/i ; :Fennec
57
+ when /Firebird/i ; :Firebird
58
+ when /Firefox[\/ ]/i ; :Firefox
59
+ when /Flock/i ; :Flock
60
+ when /Fluid/i ; :Fluid
61
+ when /Galaxy/i ; :Galaxy
62
+ when /Galeon/i ; :Galeon
63
+ when /Genius/i ; :Genius
64
+ when /GranParadiso/i ; :GranParadiso
65
+ when /Green/i ; :Green
66
+ when /Gregarius/i ; :Gregarius # Feed Reader
67
+ when /HTMLParser/i ; :HTMLParser # Validator
68
+ when /Hana/i ; :Hana
69
+ when /HotJava/i ; :HotJava
70
+ when /IBM WebExplorer/i ; :'IBM WebExplorer'
71
+ when /IBrowse/i ; :IBrowse
72
+ when /iCab/i ; :iCab
73
+ when /Iceape/i ; :Iceape
74
+ when /IceCat/i ; :IceCat
75
+ when /Iceweasel/i ; :Iceweasel
76
+ when /iNet/i ; :iNet
77
+ when /iPhone/i ; :iPhone #Embedded Mobile Based
78
+ when /Iron/i ; :Iron
79
+ when /Java/i ; :Java # Library
80
+ when /K-Meleon/i ; :'K-Meleon'
81
+ when /K-Ninja/i ; :'K-Ninja'
82
+ when /Kapiko/i ; :Kapiko
83
+ when /Kazehakase/i ; :Kazehakase
84
+ when /KKman/i ; :KKman
85
+ when /klondike/i ; :Klondike
86
+ when /KMLite/i ; :KMLite
87
+ when /Konqueror/i ; :Konqueror
88
+ when /LeechCraft/i ; :LeechCraft
89
+ when /Link Valet/i ; :'Link Valet' # Link Checker
90
+ when /Link Validity Check/i ; :'Link Validity Check' # Link Checker
91
+ when /LinksManager.com_bot/i ; :'LinksManager.com_bot' # Link Checker
92
+ when /Links/i ; :Links
93
+ when /libwww-perl/i ; :'libwww-perl' # Library
94
+ when /Lobo/i ; :Lobo
95
+ when /Lolifox/i ; :Lolifox
96
+ when /Lunascape/i ; :Lunascape
97
+ when /Lynx/i ; :Lynx
98
+ when /Madfox/i ; :Madfox
99
+ when /Maxthon/i ; :Maxthon
100
+ when /Midori/i ; :Midori
101
+ when /Minefield/i ; :Minefield
102
+ when /Minimo/i ; :Minimo
103
+ when /Mojoo Robot/i ; :'Mojoo Robot' # Link Checker
104
+ when /MSIE[\/ ]/i ; :IE #Common
105
+ when /MultiZilla/i ; :MultiZilla
106
+ when /MyIE2/i ; :MyIE2
107
+ when /Namoroka/i ; :Namoroka
108
+ when /NCSA/i ; :NCSA_Mosaic
109
+ when /NetFront/i ; :NetFront
110
+ when /NetNewsWire/i ; :NetNewsWire
111
+ when /NetPositive/i ; :NetPositive
112
+ when /Netscape/i ; :Netscape
113
+ when /NetSurf/i ; :NetSurf
114
+ when /Notifixious/i ; :Notifixious # Link Validator
115
+ when /Offline Explorer/i ; :'Offline Explorer' # Offline Browser
116
+ when /OmniWeb/i ; :OmniWeb
117
+ when /Online link validator/i; :'Online link validator' # Link Validator
118
+ when /Openwave/i ; :OpenWave
119
+ when /Opera Mini/i ; :'Opera Mini' #Embedded Mobile Based
120
+ when /Opera Mobi/i ; :'Opera Mobile' #Embedded Mobile Based
121
+ when /Opera[\/ ]/i ; :Opera #Common
122
+ when /Orca/i ; :Orca
123
+ when /Oregano/i ; :Oregano
124
+ when /P3P Validator/i ; :'P3P Validator' # Validator
125
+ when /Palm/i ; :Palm
126
+ when /Peach/i ; :Peach # Library
127
+ when /Playstation 3/i ; :PS3 # Console
128
+ when /Playstation portable/i ; :PSP # Console
129
+ when /Phoenix/i ; :Phoenix
130
+ when /Pogo/i ; :Pogo
131
+ when /Python-urllib/i ; :'Python-urllib' # Library
132
+ when /QtWeb/i ; :QtWeb
133
+ when /Reciprocal Link/i ; :'Reciprocal Link' # Link Checker
134
+ when /REL Link Checker Lite/i; :'REL Link Checker Lite' # Link Checker
135
+ when /retawq/i ; :Retawq
136
+ when /reqwirelessweb/i ; :Reqwirelessweb
137
+ when /Safari[\/ ]/i ; :Safari
138
+ when /SeaMonkey/i ; :SeaMonkey
139
+ when /Shiira/i ; :Shiira
140
+ when /Shiretoko/i ; :Shiretoko
141
+ when /SiteBar/i ; :SiteBar #Link Checker
142
+ when /Sleipnir/i ; :Sleipnir
143
+ when /Stainless/i ; :Stainless
144
+ when /Sunrise/i ; :Sunrise
145
+ when /SuperBot/i ; :SuperBot # Offline Browser
146
+ when /SymbianOS/i ; :SymbianOS #Embedded Mobile Based
147
+ when /Symbian/i ; :Symbian #Embedded Mobile Based
148
+ when /TeaShark/i ; :TeaShark
149
+ when /Thunderbird/i ; :Thunderbird # E-Mail Client
150
+ when /uzbl/i ; :Uzbl
151
+ when /Vivante Link Checker/i ; :'Vivante Link Checker' # Link Checker
152
+ when /w3m/i ; :w3m
153
+ when /W3C-checklink/i ; :'W3C-checklink' # Link Checker
154
+ when /W3C_CSS_Validator_JFouffa/i ; :W3C_CSS_Validator_JFouffa # Validator
155
+ when /W3C_Validator/i ; :W3C_Validator # Validator
156
+ when /WapTiger/i ; :WapTiger #Embedded Mobile Based
157
+ when /WDG_Validator/i ; :WDG_Validator # Validator
158
+ when /Web Downloader/i ; :'Web Downloader' # Offline Browser
159
+ when /WebCopier/i ; :WebCopier # Offline Browser
160
+ when /WebZIP/i ; :WebZIP # Offline Browser
161
+ when /Wget/i ; :Wget # Offline Browser
162
+ when /Winwap/i ; :Winwap #Embedded Mobile Based
163
+ when /Wii/i ; :Wii # Console
164
+ when /WorldWideWeb/i ; :WorldWideWeb
165
+ when /Wyzo/i ; :Wyzo
166
+ when /Xenu Link Sleuth/i ; :'Xenu Link Sleuth' # Link Checker
167
+ when /Mozilla/i ; :Mozilla #Common
37
168
  else ; :Unknown
38
169
  end
39
170
  end
@@ -29,6 +29,7 @@ class Engine
29
29
  when /Darwin/i ; :Darwin
30
30
  when /NetFront/i ; :NetFront
31
31
  when /UP.Browser/i; :'UP.Browser'
32
+ when /Palm/i ; :Palm
32
33
  else :Unknown
33
34
  end
34
35
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009 Shenouda Bertel <sbertel@mobithought.com>
2
+ # Copyright (c) 2009 Shenouda Bertel <sbertel@mobithought.com>, MobiThought.
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -86,21 +86,21 @@ module ActiveDevice
86
86
  ##
87
87
  # User agent model symbol.
88
88
 
89
- def model
89
+ def device_model
90
90
  Model.brand_model request.user_agent
91
91
  end
92
92
 
93
93
  ##
94
94
  # User agent model Reselution symbol.
95
95
 
96
- def model_reselution
96
+ def device_model_reselution
97
97
  Model.model_reselution request.user_agent
98
98
  end
99
99
 
100
100
  ##
101
101
  # User agent brand symbol.
102
102
 
103
- def brand
103
+ def device_brand
104
104
  Brand.mobile_brand request.user_agent
105
105
  end
106
106
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shenouda Bertel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-26 00:00:00 +02:00
12
+ date: 2009-12-26 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15