rack-user_agent 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/lib/rack/user_agent/detector.rb +8 -0
- data/lib/rack/user_agent/version.rb +1 -1
- data/spec/lib/rack/user_agent/detector_spec.rb +32 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e77ace242d9acad266c01d710575a5bf6345b4db
|
4
|
+
data.tar.gz: 3d403a258cec9b2d03a17dbe1726919114972205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b83e2cc607bf898700702f4d0c18cb74cd728daeba143f16c81eafd72401130cec4c82db0fbde84df86ef4d469ab6efde626be53d0b2951bc4cfe229d3abe116
|
7
|
+
data.tar.gz: a18eeb7ad762ce313c26e6a97f9f91cb827bba4bf050a424ff872a65de43115fb28accc60a54bbda6486efc8181b7f8aa9f7e09bf59b44bb3f727698e016d1b6
|
data/.travis.yml
CHANGED
@@ -24,6 +24,10 @@ module Rack
|
|
24
24
|
os == "iPod"
|
25
25
|
end
|
26
26
|
|
27
|
+
def from_ios?
|
28
|
+
from_iphone? || from_ipad? || from_ipod?
|
29
|
+
end
|
30
|
+
|
27
31
|
def from_android?
|
28
32
|
os == "Android" && android_mobile?
|
29
33
|
end
|
@@ -32,6 +36,10 @@ module Rack
|
|
32
36
|
os == "Android" && !android_mobile?
|
33
37
|
end
|
34
38
|
|
39
|
+
def from_android_os?
|
40
|
+
from_android? || from_android_tablet?
|
41
|
+
end
|
42
|
+
|
35
43
|
def from_windows_phone?
|
36
44
|
os == "Windows Phone OS"
|
37
45
|
end
|
@@ -8,6 +8,7 @@ describe "Rack::UserAgent::Detector" do
|
|
8
8
|
SMARTPHONES = [
|
9
9
|
{
|
10
10
|
name: "iPhone",
|
11
|
+
os: "iOS",
|
11
12
|
version: "5.1.1",
|
12
13
|
user_agents: [
|
13
14
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3",
|
@@ -15,6 +16,7 @@ describe "Rack::UserAgent::Detector" do
|
|
15
16
|
},
|
16
17
|
{
|
17
18
|
name: "iPhone",
|
19
|
+
os: "iOS",
|
18
20
|
version: "6.0",
|
19
21
|
user_agents: [
|
20
22
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25",
|
@@ -22,6 +24,7 @@ describe "Rack::UserAgent::Detector" do
|
|
22
24
|
},
|
23
25
|
{
|
24
26
|
name: "iPad",
|
27
|
+
os: "iOS",
|
25
28
|
version: "6.0",
|
26
29
|
user_agents: [
|
27
30
|
"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25"
|
@@ -29,6 +32,7 @@ describe "Rack::UserAgent::Detector" do
|
|
29
32
|
},
|
30
33
|
{
|
31
34
|
name: "iPod",
|
35
|
+
os: "iOS",
|
32
36
|
version: "8.0",
|
33
37
|
user_agents: [
|
34
38
|
"Mozilla/5.0 (iPod touch; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4"
|
@@ -36,6 +40,7 @@ describe "Rack::UserAgent::Detector" do
|
|
36
40
|
},
|
37
41
|
{
|
38
42
|
name: "Android",
|
43
|
+
os: "Android",
|
39
44
|
version: "4.0.1",
|
40
45
|
user_agents: [
|
41
46
|
"Mozilla/5.0 (Linux; U; Android 4.0.1; ja-jp; Galaxy Nexus Build/ITL41D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
|
@@ -43,6 +48,7 @@ describe "Rack::UserAgent::Detector" do
|
|
43
48
|
},
|
44
49
|
{
|
45
50
|
name: "Android",
|
51
|
+
os: "Android",
|
46
52
|
version: "4.2.1",
|
47
53
|
user_agents: [
|
48
54
|
"Opera/9.80 (Android 4.2.1; Linux; Opera Mobi/ADR-1301080958) Presto/2.11.355 Version/12.10"
|
@@ -50,6 +56,7 @@ describe "Rack::UserAgent::Detector" do
|
|
50
56
|
},
|
51
57
|
{
|
52
58
|
name: "Android",
|
59
|
+
os: "Android",
|
53
60
|
version: nil,
|
54
61
|
user_agents: [
|
55
62
|
"Mozilla/5.0 (Android; Mobile; rv:18.0) Gecko/18.0 Firefox/18.0",
|
@@ -57,6 +64,7 @@ describe "Rack::UserAgent::Detector" do
|
|
57
64
|
},
|
58
65
|
{
|
59
66
|
name: "Android Tablet",
|
67
|
+
os: "Android",
|
60
68
|
version: "4.1.1",
|
61
69
|
user_agents: [
|
62
70
|
"Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03S) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19"
|
@@ -64,6 +72,7 @@ describe "Rack::UserAgent::Detector" do
|
|
64
72
|
},
|
65
73
|
{
|
66
74
|
name: "Windows Phone",
|
75
|
+
os: "Windows Phone",
|
67
76
|
version: "7.5",
|
68
77
|
user_agents: [
|
69
78
|
"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; FujitsuToshibaMobileCommun; IS12T; KDDI)"
|
@@ -146,6 +155,16 @@ describe "Rack::UserAgent::Detector" do
|
|
146
155
|
end
|
147
156
|
end
|
148
157
|
|
158
|
+
describe "#from_ios?" do
|
159
|
+
it "returns true if the request comes from ios" do
|
160
|
+
user_agents("iOS", key: :os).each do |ua|
|
161
|
+
header "User-Agent", ua
|
162
|
+
get "/"
|
163
|
+
last_request.from_ios?.must_equal true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
149
168
|
describe "#from_android?" do
|
150
169
|
it "returns true if the request comes from android mobile" do
|
151
170
|
user_agents("Android").each do |ua|
|
@@ -166,6 +185,16 @@ describe "Rack::UserAgent::Detector" do
|
|
166
185
|
end
|
167
186
|
end
|
168
187
|
|
188
|
+
describe "#from_android_os?" do
|
189
|
+
it "returns true if the request comes from android os" do
|
190
|
+
user_agents("Android", key: :os) .each do |ua|
|
191
|
+
header "User-Agent", ua
|
192
|
+
get "/"
|
193
|
+
last_request.from_android_os?.must_equal true
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
169
198
|
describe "#from_windows_phone?" do
|
170
199
|
it "returns true if the request comes from windows phone" do
|
171
200
|
user_agents("Windows Phone").each do |ua|
|
@@ -176,7 +205,8 @@ describe "Rack::UserAgent::Detector" do
|
|
176
205
|
end
|
177
206
|
end
|
178
207
|
|
179
|
-
def user_agents(name)
|
180
|
-
SMARTPHONES.
|
208
|
+
def user_agents(word, key: :name)
|
209
|
+
SMARTPHONES.find_all { |info| info[key] == word }
|
210
|
+
.flat_map { |info| info[:user_agents]}
|
181
211
|
end
|
182
212
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-user_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
version: '0'
|
215
215
|
requirements: []
|
216
216
|
rubyforge_project:
|
217
|
-
rubygems_version: 2.
|
217
|
+
rubygems_version: 2.5.1
|
218
218
|
signing_key:
|
219
219
|
specification_version: 4
|
220
220
|
summary: Rack::Request extension for handling User-Agent.
|
@@ -224,4 +224,3 @@ test_files:
|
|
224
224
|
- spec/lib/rack/user_agent/result_spec.rb
|
225
225
|
- spec/lib/rack/user_agent_spec.rb
|
226
226
|
- spec/spec_helper.rb
|
227
|
-
has_rdoc:
|