schmobile 0.1.1 → 0.1.2
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/VERSION +1 -1
- data/lib/rack/schmobile/request_extension.rb +15 -7
- data/schmobile.gemspec +2 -2
- data/test/helper.rb +28 -0
- data/test/test_rack_request.rb +6 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -1,10 +1,18 @@
|
|
1
|
-
Rack
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Rack
|
2
|
+
module Schmobile
|
3
|
+
module Request
|
4
|
+
def is_mobile?
|
5
|
+
Rack::Schmobile::Filters::CHAIN.each do |filter|
|
6
|
+
result = filter.call(self)
|
7
|
+
return result unless result.nil?
|
8
|
+
end
|
7
9
|
|
8
|
-
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
15
|
+
|
16
|
+
Rack::Request.class_eval do
|
17
|
+
include Rack::Schmobile::Request
|
18
|
+
end
|
data/schmobile.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{schmobile}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Morten Primdahl"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-26}
|
13
13
|
s.description = %q{Used to determine if a request is from a mobile client, and possibly redirect it if that's the case}
|
14
14
|
s.email = %q{morten@zendesk.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/helper.rb
CHANGED
@@ -25,10 +25,38 @@ class Test::Unit::TestCase
|
|
25
25
|
'BlackBerry9000/4.6.0.167 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/102'
|
26
26
|
end
|
27
27
|
|
28
|
+
def ipad
|
29
|
+
"Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10"
|
30
|
+
end
|
31
|
+
|
32
|
+
def palm
|
33
|
+
"Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0"
|
34
|
+
end
|
35
|
+
|
28
36
|
def samsung
|
29
37
|
'Mozilla/4.0 (compatible; MSIE 6.0; BREW 3.1.5; en )/800x480 Samsung SCH-U960'
|
30
38
|
end
|
31
39
|
|
40
|
+
def htc_touch
|
41
|
+
"HTC_Touch_Diamond2_T5353 Opera/9.50 (Windows NT 5.1; U; en)"
|
42
|
+
end
|
43
|
+
|
44
|
+
def danger
|
45
|
+
"Mozilla/5.0 (Danger hiptop 5.0; U; rv:1.7.12) Gecko/20050920"
|
46
|
+
end
|
47
|
+
|
48
|
+
def msie6
|
49
|
+
"Mozilla/4.0 (compatible; MSIE 6.0; Update a; AOL 6.0; Windows 98)"
|
50
|
+
end
|
51
|
+
|
52
|
+
def msie8
|
53
|
+
"Client: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; MDDR; .NET CLR 3.5.30729; InfoPath.2; .NET CLR 3.0.30729; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 4.0.20506; Creative AutoUpdate v1.40.01)"
|
54
|
+
end
|
55
|
+
|
56
|
+
def opera
|
57
|
+
"Opera/9.25 (Windows NT 6.0; U; en)"
|
58
|
+
end
|
59
|
+
|
32
60
|
def request(overwrite = {})
|
33
61
|
Rack::Request.new(environment(overwrite))
|
34
62
|
end
|
data/test/test_rack_request.rb
CHANGED
@@ -12,10 +12,15 @@ class TestRackRequest < Test::Unit::TestCase
|
|
12
12
|
should "not detect a regular browser as mobile" do
|
13
13
|
assert !request.is_mobile?
|
14
14
|
assert !request("HTTP_USER_AGENT" => nil).is_mobile?
|
15
|
+
|
16
|
+
[ :msie6, :msie8, :opera ].each do |browser|
|
17
|
+
agent = self.send(browser)
|
18
|
+
assert request("HTTP_USER_AGENT" => agent).is_mobile?
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
should "detect mobile units as mobile" do
|
18
|
-
[ :ipod, :iphone, :android, :blackberry, :samsung ].each do |phone|
|
23
|
+
[ :ipod, :iphone, :android, :blackberry, :samsung, :palm, :htc_touch, :danger ].each do |phone|
|
19
24
|
agent = self.send(phone)
|
20
25
|
assert request("HTTP_USER_AGENT" => agent).is_mobile?
|
21
26
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schmobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-26 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|