rails_agent_detect 1.0.0
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/lib/rails_agent_detect.rb +43 -0
- metadata +46 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
class Rails_Agent_Detect
|
2
|
+
@@is_mobile, @@is_tablet = false
|
3
|
+
def self.is_mobile
|
4
|
+
docomo = "docomo"
|
5
|
+
softbank = "softbank"
|
6
|
+
au = "au"
|
7
|
+
iphone = "iphone"
|
8
|
+
ipad = "ipad"
|
9
|
+
android = "anroid"
|
10
|
+
blackberry = "blackberry"
|
11
|
+
blackberry5 = "blackberry5"
|
12
|
+
windowsphone = "windowsphone"
|
13
|
+
windowsphone7 = "windowsphone7"
|
14
|
+
windowsphone8 = "windowsphone8"
|
15
|
+
motorola = "motorola"
|
16
|
+
symbian = "symbian"
|
17
|
+
mobile = "mobile"
|
18
|
+
lg = "lg"
|
19
|
+
pc = "pc"
|
20
|
+
default = "default"
|
21
|
+
# url = "http://#{request.host+request.fullpath}"
|
22
|
+
# url1 = "http://#{request.host}:#{request.port}#{request.fullpath}"
|
23
|
+
# link = url1.gsub("#{request.host}:#{request.port}","#{request.host}:#{request.port}/m")
|
24
|
+
# check_url = "http://#{request.host}:#{request.port}\/m"
|
25
|
+
user_agent = request.env['HTTP_USER_AGENT'].downcase if request.env['HTTP_USER_AGENT'].present?
|
26
|
+
|
27
|
+
if (user_agent.to_s.match(/iphone/) || user_agent.to_s.match(/ipad/) || user_agent.to_s.match(/android/) || user_agent.to_s.match(/blackberry/) || user_agent.to_s.match(/blackberry5/) || user_agent.to_s.match(/windowsphone/) || user_agent.to_s.match(/windowsphone7/) || user_agent.to_s.match(/windowsphone8/) || user_agent.to_s.match(/motorola/) || user_agent.to_s.match(/symbian/))
|
28
|
+
return true
|
29
|
+
# if (user_agent.to_s.match(/ipad/))
|
30
|
+
# @@is_tablet = true
|
31
|
+
# elsif (user_agent.to_s.match(/android/))
|
32
|
+
# if (user_agent.to_s.match(/mobile/))
|
33
|
+
# @@is_tablet = false
|
34
|
+
# else
|
35
|
+
# @@is_tablet = true
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#redirect_to link unless url1.to_s.match(check_url.to_s)
|
39
|
+
else
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_agent_detect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- On Ha Chung Phuoc
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple detect user agent gem.
|
15
|
+
email: onhachungphuoc@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/rails_agent_detect.rb
|
21
|
+
homepage: https://github.com/chungphuoc/rails_agent_detect
|
22
|
+
licenses:
|
23
|
+
- chungphuoc
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.25
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Detect UserAgent.
|
46
|
+
test_files: []
|