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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ba7fef2f942164b42f111eaab0271530cf64af4
4
- data.tar.gz: 3ad5b568e8675cad9b5295394129346564d0390e
3
+ metadata.gz: f74e2f39ed2880de537c8ddb79bb621fc4b77779
4
+ data.tar.gz: 2ecedea7096e497fd54fecb86492de264c766c37
5
5
  SHA512:
6
- metadata.gz: 700eb49a714b3aeb5e8a9ea4b9fbe2b2e6f204a9fb13be20bbfe69d0757d1b58cbe862aca8af4f8a45a700026ef8abc47d4779f9737e5296029724189333751d
7
- data.tar.gz: c8b6382f6e1dbf6b2a9a819d116ec7c6ae01886cef77d272d2c56821a5b526793df0357ba36f4cf45bc183d849d0124f4054845e5415b7f5c511d83375bbbd0d
6
+ metadata.gz: 344ae2ca1235942ee74786d72d6799a57adc230271de3a7cd60b69b0cc16f21e7fce4033e6bcf64d5636271bbc60baa88eaa3667a435456500b1b8de8ec5394e
7
+ data.tar.gz: 3aa63f8e36373f64593fd72b25d576400ac139ce789892a16260cc6c263f3497be72e4e48fdd1a0f0ad526a3922b2bb629ee16ad18ad7cecfef4054a775389e9
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.2.4
4
+ - 2.2.5
5
5
  - 2.3.1
6
6
  before_install: gem install bundler -v 1.11.2
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 request user-agent string. No complicated logic for the detection, it simply(stupidly) checks if user-agent includes particular string.
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. 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).
47
+ Installing `rack-simple_user_agent` automatically makes all detection methods available.
25
48
 
26
- For example, you can use below detection methods in your Rails application.
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
- "Hello World!"
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
@@ -0,0 +1,11 @@
1
+ module Rack
2
+ class SimpleUserAgent
3
+ module Detectors
4
+ module WindowsPhone
5
+ def from_windows_phone?
6
+ user_agent_string.include?("Windows Phone")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,13 +1,33 @@
1
- require "rack/simple_user_agent/detectors/helper"
1
+ require "rack/simple_user_agent/detectors/android"
2
2
  require "rack/simple_user_agent/detectors/bot"
3
- require "rack/simple_user_agent/detectors/smartphone"
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 Helper
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class SimpleUserAgent
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0.rc"
4
4
  end
5
5
  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", "~> 10.0"
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.2.2
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-14 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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/helper.rb
133
- - lib/rack/simple_user_agent/detectors/smartphone.rb
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: '0'
155
+ version: 1.3.1
155
156
  requirements: []
156
157
  rubyforge_project:
157
158
  rubygems_version: 2.5.1
@@ -1,14 +0,0 @@
1
- module Rack
2
- class SimpleUserAgent
3
- module Detectors
4
- module Helper
5
-
6
- private
7
-
8
- def user_agent_string
9
- user_agent.to_s
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -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