rack-simple_user_agent 0.2.2 → 0.3.0.rc
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 -1
- data/README.md +35 -31
- data/lib/rack/simple_user_agent/detectors/android.rb +25 -0
- data/lib/rack/simple_user_agent/detectors/ios.rb +23 -0
- data/lib/rack/simple_user_agent/detectors/windows_phone.rb +11 -0
- data/lib/rack/simple_user_agent/detectors.rb +24 -4
- data/lib/rack/simple_user_agent/version.rb +1 -1
- data/rack-simple_user_agent.gemspec +2 -2
- metadata +9 -8
- data/lib/rack/simple_user_agent/detectors/helper.rb +0 -14
- data/lib/rack/simple_user_agent/detectors/smartphone.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f74e2f39ed2880de537c8ddb79bb621fc4b77779
|
4
|
+
data.tar.gz: 2ecedea7096e497fd54fecb86492de264c766c37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 344ae2ca1235942ee74786d72d6799a57adc230271de3a7cd60b69b0cc16f21e7fce4033e6bcf64d5636271bbc60baa88eaa3667a435456500b1b8de8ec5394e
|
7
|
+
data.tar.gz: 3aa63f8e36373f64593fd72b25d576400ac139ce789892a16260cc6c263f3497be72e4e48fdd1a0f0ad526a3922b2bb629ee16ad18ad7cecfef4054a775389e9
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,10 +4,9 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/toshimaru/rack-simple_user_agent.svg)](https://travis-ci.org/toshimaru/rack-simple_user_agent)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/github/toshimaru/rack-simple_user_agent/badge.svg)](https://coveralls.io/github/toshimaru/rack-simple_user_agent)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/toshimaru/rack-simple_user_agent/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/rack-simple_user_agent)
|
7
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/toshimaru/rack-simple_user_agent.svg)](https://gemnasium.com/github.com/toshimaru/rack-simple_user_agent)
|
7
8
|
|
8
|
-
Rack::SimpleUserAgent is Rack::Request extension which detects user-agent from
|
9
|
-
|
10
|
-
**[ANNOUNCEMENT] Current `request.from_smartphone?` behavior is going to be changed in the next version. Please don't use `request.from_smartphone?`, use `request.from_smartphone?`, `request.from_android?` instead depending on the use case.**
|
9
|
+
Rack::SimpleUserAgent is Rack::Request extension which detects user-agent from user-agent string. No complicated logic for the detection, it simply(stupidly) checks if user-agent includes particular string or not.
|
11
10
|
|
12
11
|
## Installation
|
13
12
|
|
@@ -17,18 +16,37 @@ Add this line to your application's `Gemfile`:
|
|
17
16
|
gem 'rack-simple_user_agent'
|
18
17
|
```
|
19
18
|
|
19
|
+
## Available Detection Methods
|
20
|
+
|
21
|
+
```
|
22
|
+
request ─ from_smartdevice?
|
23
|
+
│ ├─ from_ios?
|
24
|
+
│ ├─ from_android?
|
25
|
+
│ └─ from_windows_phone?
|
26
|
+
│
|
27
|
+
├ from_smartphone?
|
28
|
+
│ ├─ from_android_mobile?
|
29
|
+
│ ├─ from_iphone?
|
30
|
+
│ ├─ from_ipod?
|
31
|
+
│ └─ from_windows_phone?
|
32
|
+
│
|
33
|
+
├ from_tablet?
|
34
|
+
│ ├─ from_ipad?
|
35
|
+
│ └─ from_android_tablet?
|
36
|
+
│
|
37
|
+
└ from_googlebot?
|
38
|
+
├─ from_googlebot_news?
|
39
|
+
├─ from_googlebot_images?
|
40
|
+
└─ from_googlebot_video?
|
41
|
+
```
|
42
|
+
|
20
43
|
## Usage
|
21
44
|
|
22
45
|
### on Rails
|
23
46
|
|
24
|
-
Installing `rack-simple_user_agent` automatically makes all detection methods available.
|
47
|
+
Installing `rack-simple_user_agent` automatically makes all detection methods available.
|
25
48
|
|
26
|
-
|
27
|
-
|
28
|
-
- `request.from_smartphone?`
|
29
|
-
- `request.from_android?`
|
30
|
-
- `request.from_iphone?`
|
31
|
-
- `request.from_windows_phone?`
|
49
|
+
These methods are useful when you use the Rails' [Action Pack Variants](http://guides.rubyonrails.org/4_1_release_notes.html#action-pack-variants) (as of Rails4.1).
|
32
50
|
|
33
51
|
### on Sinatra
|
34
52
|
|
@@ -41,30 +59,16 @@ configure do
|
|
41
59
|
end
|
42
60
|
|
43
61
|
get "/" do
|
44
|
-
request.from_smartphone?
|
45
|
-
|
62
|
+
if request.from_smartphone?
|
63
|
+
"Hello World from smartphone"
|
64
|
+
elsif request.from_tablet?
|
65
|
+
"Hello World from tablet"
|
66
|
+
else
|
67
|
+
"Hello World"
|
68
|
+
end
|
46
69
|
end
|
47
70
|
```
|
48
71
|
|
49
|
-
## Available Detection Methods
|
50
|
-
|
51
|
-
```
|
52
|
-
request ── from_smartphone?
|
53
|
-
│ ├── from_android?
|
54
|
-
│ │ ├── from_android_mobile?
|
55
|
-
│ │ └── from_android_tablet?
|
56
|
-
│ ├── from_ios?
|
57
|
-
│ │ ├── from_ipad?
|
58
|
-
│ │ ├── from_iphone?
|
59
|
-
│ │ └── from_ipod?
|
60
|
-
│ └── from_windows_phone?
|
61
|
-
│
|
62
|
-
└ from_googlebot?
|
63
|
-
├── from_googlebot_news?
|
64
|
-
├── from_googlebot_images?
|
65
|
-
└── from_googlebot_video?
|
66
|
-
```
|
67
|
-
|
68
72
|
## Development
|
69
73
|
|
70
74
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rack
|
2
|
+
class SimpleUserAgent
|
3
|
+
module Detectors
|
4
|
+
module Android
|
5
|
+
def from_android?
|
6
|
+
user_agent_string.include?("Android")
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_android_tablet?
|
10
|
+
from_android? && !android_mobile?
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_android_mobile?
|
14
|
+
from_android? && android_mobile?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def android_mobile?
|
20
|
+
!(user_agent =~ /Android.+Mobi(le)?/).nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rack
|
2
|
+
class SimpleUserAgent
|
3
|
+
module Detectors
|
4
|
+
module Ios
|
5
|
+
def from_ios?
|
6
|
+
from_iphone? || from_ipad? || from_ipod?
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_iphone?
|
10
|
+
user_agent_string.include?("iPhone;")
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_ipad?
|
14
|
+
user_agent_string.include?("iPad;")
|
15
|
+
end
|
16
|
+
|
17
|
+
def from_ipod?
|
18
|
+
user_agent_string.include?("iPod touch;")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,13 +1,33 @@
|
|
1
|
-
require "rack/simple_user_agent/detectors/
|
1
|
+
require "rack/simple_user_agent/detectors/android"
|
2
2
|
require "rack/simple_user_agent/detectors/bot"
|
3
|
-
require "rack/simple_user_agent/detectors/
|
3
|
+
require "rack/simple_user_agent/detectors/ios"
|
4
|
+
require "rack/simple_user_agent/detectors/windows_phone"
|
4
5
|
|
5
6
|
module Rack
|
6
7
|
class SimpleUserAgent
|
7
8
|
module Detectors
|
8
|
-
include
|
9
|
-
include Smartphone
|
9
|
+
include Android
|
10
10
|
include Bot
|
11
|
+
include Ios
|
12
|
+
include WindowsPhone
|
13
|
+
|
14
|
+
def from_smartdevice?
|
15
|
+
from_ios? || from_android? || from_windows_phone?
|
16
|
+
end
|
17
|
+
|
18
|
+
def from_smartphone?
|
19
|
+
from_iphone? || from_ipod? || from_android_mobile? || from_windows_phone?
|
20
|
+
end
|
21
|
+
|
22
|
+
def from_tablet?
|
23
|
+
from_ipad? || from_android_tablet?
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def user_agent_string
|
29
|
+
user_agent.to_s
|
30
|
+
end
|
11
31
|
end
|
12
32
|
end
|
13
33
|
end
|
@@ -13,13 +13,13 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/toshimaru/rack-simple_user_agent"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sample)/}) }
|
17
17
|
spec.bindir = "exe"
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
-
spec.add_development_dependency "rake", "~>
|
22
|
+
spec.add_development_dependency "rake", "~> 11.0"
|
23
23
|
spec.add_development_dependency "minitest", "~> 5.0"
|
24
24
|
spec.add_development_dependency "minitest-reporters"
|
25
25
|
spec.add_development_dependency "pry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-simple_user_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshimaru
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '11.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '11.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,9 +128,10 @@ files:
|
|
128
128
|
- bin/setup
|
129
129
|
- lib/rack/simple_user_agent.rb
|
130
130
|
- lib/rack/simple_user_agent/detectors.rb
|
131
|
+
- lib/rack/simple_user_agent/detectors/android.rb
|
131
132
|
- lib/rack/simple_user_agent/detectors/bot.rb
|
132
|
-
- lib/rack/simple_user_agent/detectors/
|
133
|
-
- lib/rack/simple_user_agent/detectors/
|
133
|
+
- lib/rack/simple_user_agent/detectors/ios.rb
|
134
|
+
- lib/rack/simple_user_agent/detectors/windows_phone.rb
|
134
135
|
- lib/rack/simple_user_agent/railtie.rb
|
135
136
|
- lib/rack/simple_user_agent/version.rb
|
136
137
|
- rack-simple_user_agent.gemspec
|
@@ -149,9 +150,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
150
|
version: '0'
|
150
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
152
|
requirements:
|
152
|
-
- - "
|
153
|
+
- - ">"
|
153
154
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
155
|
+
version: 1.3.1
|
155
156
|
requirements: []
|
156
157
|
rubyforge_project:
|
157
158
|
rubygems_version: 2.5.1
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
class SimpleUserAgent
|
3
|
-
module Detectors
|
4
|
-
module Smartphone
|
5
|
-
def from_smartphone?
|
6
|
-
from_ios? || from_android? || from_windows_phone?
|
7
|
-
end
|
8
|
-
|
9
|
-
def from_ios?
|
10
|
-
from_iphone? || from_ipad? || from_ipod?
|
11
|
-
end
|
12
|
-
|
13
|
-
def from_iphone?
|
14
|
-
user_agent_string.include?("iPhone")
|
15
|
-
end
|
16
|
-
|
17
|
-
def from_ipad?
|
18
|
-
user_agent_string.include?("iPad")
|
19
|
-
end
|
20
|
-
|
21
|
-
def from_ipod?
|
22
|
-
user_agent_string.include?("iPod")
|
23
|
-
end
|
24
|
-
|
25
|
-
def from_android?
|
26
|
-
user_agent_string.include?("Android")
|
27
|
-
end
|
28
|
-
|
29
|
-
def from_android_tablet?
|
30
|
-
from_android? && !android_mobile?
|
31
|
-
end
|
32
|
-
|
33
|
-
def from_android_mobile?
|
34
|
-
from_android? && android_mobile?
|
35
|
-
end
|
36
|
-
|
37
|
-
def from_windows_phone?
|
38
|
-
user_agent_string.include?("Windows Phone")
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def android_mobile?
|
44
|
-
!(user_agent =~ /Android.+Mobi(le)?/).nil?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|