useragents 0.1.4 → 0.1.5

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: 40889d9e0aa4f92825ee4b8e627d68c01d13c7da
4
- data.tar.gz: 8211f99b5d2411abb21849ba813133a55865b3d6
3
+ metadata.gz: 8d9c7bad86d98ede337bc118031aed3398fc665a
4
+ data.tar.gz: 7e5326d587c4a17e45cafdd8cf07bf964d6ea816
5
5
  SHA512:
6
- metadata.gz: 7f49fc4b69104c0aeb0040583ddede0b8e58a7de67036ca3ea228693518e50a8fa7f97eea7eca93e4bfe3887791db4d668f320e00a3788f722945fd433c95db9
7
- data.tar.gz: 119d492e1d6717fd3cc0a7277ab3ecb8c670aa6223bf357b35e604fa2ec8555ef95561b125a36051f16f930021cdeb5eb356a7c27d16554070c23135b4952292
6
+ metadata.gz: 19c630bac22513bd630599a64e6a37034de784883775f59ec64dcbe87fcbfb3a376993fd08cc2867410b838215dd2e79396edb10bfc95bbf02baf84f533f8aa9
7
+ data.tar.gz: 52b6c696c3b9f7fa3a43ec7e3dd4dcab8202019d0e72cdfaf24c1c9b3c5073de5830f1ee1a593216059bb2287c635d96b5a5ec2a2eebe99e034c22e83338c283
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2013 debbbbie
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 debbbbie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,30 +1,34 @@
1
- useragents-rb
2
- =============
3
- [![Build Status](https://travis-ci.org/debbbbie/useragents-rb.png?branch=master)](https://travis-ci.org/debbbbie/useragents-rb)
4
-
5
- Usually, spiders must disguise themselves with plenty of User-Agents, for some
6
- servers are smart. The gem `useragents` can give you that!
7
-
8
- It has frequently-used browsers such as Chrome, Firefox, Internet Explorer, Safari,
9
- Opera and so on, with frequently-used versions.
10
-
11
- The usage is simple, just install the gem at first, then `require 'useragents`,
12
- and at last, `UserAgents.rand()` works for you!
13
-
14
- Enjoy it!
15
-
16
- ## Usage
17
-
18
- ``` sh
19
- gem install useragents
20
- ```
21
-
22
- ```ruby
23
- require 'useragents'
24
-
25
- # Generate a random useragent for you
26
- UserAgents.rand()
27
- # => ""Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36"
28
- ```
29
-
30
- Copyright © 2013 debbbbie, released under the MIT license
1
+ useragents-rb
2
+ =============
3
+ [![Build Status](https://travis-ci.org/debbbbie/useragents-rb.png?branch=master)](https://travis-ci.org/debbbbie/useragents-rb)
4
+
5
+ Usually, spiders must disguise themselves with plenty of User-Agents, for some
6
+ servers are smart. The gem `useragents` can give you that!
7
+
8
+ It has frequently-used browsers such as `Chrome`, `Firefox`, `Internet Explorer`, `Safari`,
9
+ `Opera` and so on, with frequently-used versions.
10
+
11
+ The usage is simple, just install the gem at first, then `require 'useragents`,
12
+ and at last, `UserAgents.rand()` works for you!
13
+
14
+ Enjoy it!
15
+
16
+ ## Usage
17
+
18
+ ``` sh
19
+ gem install useragents
20
+ ```
21
+
22
+ ```ruby
23
+ require 'useragents'
24
+
25
+ # Generate a random useragent for you
26
+ UserAgents.rand()
27
+ # => ""Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36"
28
+ ```
29
+
30
+ Copyright © 2013 debbbbie, released under the MIT license
31
+
32
+
33
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/debbbbie/useragents-rb/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
34
+
@@ -1,20 +1,20 @@
1
- unless Object.respond_to? :blank?
2
-
3
- class Object
4
- # An object is blank if it's false, empty, or a whitespace string.
5
- # For example, "", " ", +nil+, [], and {} are all blank.
6
- #
7
- # This simplifies:
8
- #
9
- # if address.nil? || address.empty?
10
- #
11
- # ...to:
12
- #
13
- # if address.blank?
14
- def blank?
15
- respond_to?(:empty?) ? empty? : !self
16
- end
17
-
18
- end
19
-
1
+ unless Object.respond_to? :blank?
2
+
3
+ class Object
4
+ # An object is blank if it's false, empty, or a whitespace string.
5
+ # For example, "", " ", +nil+, [], and {} are all blank.
6
+ #
7
+ # This simplifies:
8
+ #
9
+ # if address.nil? || address.empty?
10
+ #
11
+ # ...to:
12
+ #
13
+ # if address.blank?
14
+ def blank?
15
+ respond_to?(:empty?) ? empty? : !self
16
+ end
17
+
18
+ end
19
+
20
20
  end
data/lib/useragents.rb CHANGED
@@ -1,26 +1,21 @@
1
- require File.expand_path('../core_ext/blank', __FILE__)
2
- require 'zlib'
3
-
4
- module UserAgents
5
-
6
- class << self
7
-
8
- def list
9
- @@list
10
- end
11
-
12
- def rand
13
- @@list[ Kernel::rand(@@list.length) ]
14
- end
15
-
16
- def init()
17
- Zlib::GzipReader.open(File.expand_path("../useragents.dat", __FILE__)) {|gz|
18
- @@list = gz.read.split("\n")
19
- }
20
- end
21
-
22
- end
23
-
24
- end
25
-
26
- UserAgents.init()
1
+ require 'zlib'
2
+ require_relative 'useragents/fetch'
3
+
4
+ module UserAgents
5
+
6
+ FILE = File.expand_path '../useragents.txt', __FILE__
7
+
8
+ class << self
9
+
10
+ def list
11
+ @@list ||= File.readlines FILE
12
+ end
13
+
14
+ def rand
15
+ list.sample
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
@@ -1,25 +1,25 @@
1
- require 'spec_helper'
2
-
3
- describe UserAgents do
4
- describe "self.list" do
5
-
6
- it "should not be empty" do
7
- UserAgents.list().blank?.should be(false)
8
- end
9
- end
10
-
11
- describe "self.rand()" do
12
- it "should be a String" do
13
- UserAgents.rand().class.should be(String)
14
- end
15
- end
16
-
17
- end
18
-
19
- describe Object do
20
- describe "[]" do
21
- it "should be blank" do
22
- [].blank?.should be(true)
23
- end
24
- end
25
- end
1
+ require 'spec_helper'
2
+
3
+ describe UserAgents do
4
+ describe "self.list" do
5
+
6
+ it "should not be empty" do
7
+ UserAgents.list().blank?.should be(false)
8
+ end
9
+ end
10
+
11
+ describe "self.rand()" do
12
+ it "should be a String" do
13
+ UserAgents.rand().class.should be(String)
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ describe Object do
20
+ describe "[]" do
21
+ it "should be blank" do
22
+ [].blank?.should be(true)
23
+ end
24
+ end
25
+ end
data/useragents.gemspec CHANGED
@@ -1,19 +1,19 @@
1
- Gem::Specification.new do |s|
2
- s.name = "useragents"
3
- s.version = "0.1.4"
4
-
5
- s.authors = "debbbbie"
6
- s.date = "2013-12-20"
7
- s.description = "Generate a random User-Agent for you"
8
- s.email = "debbbbie@163.com"
9
- s.files = ["useragents.gemspec", "lib/useragents.rb", "lib/core_ext/blank.rb", "lib/fetch.rb", "lib/useragents.dat", "spec/useragents_spec.rb", "README.md", "LICENSE"]
10
- s.homepage = "https://github.com/debbbbie/useragents-rb"
11
- s.require_paths = ["lib"]
12
- s.summary = "Generate a random User-Agent for you, use for spiders or anything."
13
- s.license = 'MIT'
14
-
15
- s.add_development_dependency "rspec"
16
- #s.add_development_dependency "nokogiri"
17
- s.add_development_dependency "useragent"
18
-
19
- end
1
+ Gem::Specification.new do |s|
2
+ s.name = 'useragents'
3
+ s.version = '0.1.5'
4
+
5
+ s.authors = 'debbbbie'
6
+ s.date = '2013-12-20'
7
+ s.description = 'Generate a random User-Agent for you'
8
+ s.email = 'debbbbie@163.com'
9
+ s.files = ['useragents.gemspec', 'lib/useragents.rb', 'lib/core_ext/blank.rb', 'spec/useragents_spec.rb', 'README.md', 'LICENSE']
10
+ s.homepage = 'https://github.com/debbbbie/useragents-rb'
11
+ s.require_paths = ['lib']
12
+ s.summary = 'Generate a random User-Agent for you, use for spiders or anything.'
13
+ s.license = 'MIT'
14
+
15
+ s.add_dependency 'nokogiri'
16
+
17
+ s.add_development_dependency 'rspec'
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useragents
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - debbbbie
@@ -11,31 +11,31 @@ cert_chain: []
11
11
  date: 2013-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: useragent
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '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
40
  version: '0'
41
41
  description: Generate a random User-Agent for you
@@ -44,14 +44,12 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - useragents.gemspec
48
- - lib/useragents.rb
47
+ - LICENSE
48
+ - README.md
49
49
  - lib/core_ext/blank.rb
50
- - lib/fetch.rb
51
- - lib/useragents.dat
50
+ - lib/useragents.rb
52
51
  - spec/useragents_spec.rb
53
- - README.md
54
- - LICENSE
52
+ - useragents.gemspec
55
53
  homepage: https://github.com/debbbbie/useragents-rb
56
54
  licenses:
57
55
  - MIT
@@ -62,17 +60,17 @@ require_paths:
62
60
  - lib
63
61
  required_ruby_version: !ruby/object:Gem::Requirement
64
62
  requirements:
65
- - - '>='
63
+ - - ">="
66
64
  - !ruby/object:Gem::Version
67
65
  version: '0'
68
66
  required_rubygems_version: !ruby/object:Gem::Requirement
69
67
  requirements:
70
- - - '>='
68
+ - - ">="
71
69
  - !ruby/object:Gem::Version
72
70
  version: '0'
73
71
  requirements: []
74
72
  rubyforge_project:
75
- rubygems_version: 2.1.11
73
+ rubygems_version: 2.6.7
76
74
  signing_key:
77
75
  specification_version: 4
78
76
  summary: Generate a random User-Agent for you, use for spiders or anything.
data/lib/fetch.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'useragent'
2
- module UserAgents
3
- def fetch
4
- require 'nokogiri'
5
- require 'open-uri'
6
- require 'zlib'
7
-
8
- urls = [
9
- 'http://www.useragentstring.com/pages/Chrome/',
10
- 'http://www.useragentstring.com/pages/Firefox/',
11
- 'http://www.useragentstring.com/pages/Internet%20Explorer/',
12
- 'http://www.useragentstring.com/pages/Opera/',
13
- 'http://www.useragentstring.com/pages/Safari/'
14
- ]
15
-
16
- agents = urls.inject([]) do |sum, url|
17
- puts "Requesting #{url}"
18
- doc = Nokogiri::HTML(open(url))
19
- doc.css('#liste ul li a').each do|link|
20
- str = link.content.strip
21
- agent = UserAgent.parse(str)
22
- case agent.browser
23
- when "Chrome" ; sum.push(str) if agent.version && agent.version >= '15'
24
- when "Firefox" ; sum.push(str) if agent.version && agent.version >= '9'
25
- when "Internet Explorer"; sum.push(str) if agent.version && agent.version >= '7'
26
- when "Opera" ; sum.push(str) if agent.version && agent.version >= '10'
27
- when "Safari" ; sum.push(str) if agent.version && agent.version >= '5'
28
- end
29
- end
30
- sum
31
- end
32
-
33
- Zlib::GzipWriter.open(File.expand_path('../useragents.dat', __FILE__)) do |gz|
34
- gz.write agents.join("\n")
35
- end
36
- puts "Fetch complete, got useragent count #{agents.length}!"
37
- end
38
- end
data/lib/useragents.dat DELETED
Binary file