user-agent-randomizer 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +79 -0
- data/Rakefile +45 -0
- data/data/user_agents.yml +10796 -0
- data/lib/user_agent_randomizer.rb +34 -0
- data/lib/user_agent_randomizer/user_agent.rb +25 -0
- data/lib/user_agent_randomizer/version.rb +4 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/user_agent_randomizer_spec.rb +25 -0
- data/user_agent_randomizer.gemspec +28 -0
- metadata +143 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'user_agent_randomizer/version'
|
2
|
+
require 'user_agent_randomizer/user_agent'
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module UserAgentRandomizer
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def parameter(*names)
|
10
|
+
names.each do |name|
|
11
|
+
attr_accessor name
|
12
|
+
define_method name do |*values|
|
13
|
+
value = values.first
|
14
|
+
value ? self.send("#{name}=", value) : instance_variable_get("@#{name}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def config(&block)
|
20
|
+
instance_eval &block
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
UserAgentRandomizer.config do
|
25
|
+
parameter :user_agent_types
|
26
|
+
parameter :user_agents
|
27
|
+
end
|
28
|
+
|
29
|
+
UserAgentRandomizer.config do
|
30
|
+
user_agent_types ["crawler", "desktop_browser", "mobile_browser", "console",
|
31
|
+
"offline_browser", "email_client", "link_checker", "email_collector",
|
32
|
+
"validator", "feed_reader", "library", "cloud_platform", "other"]
|
33
|
+
user_agents YAML.load_file(File.expand_path("data/user_agents.yml", Gem.datadir("user_agent_randomizer")))
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module UserAgentRandomizer
|
4
|
+
class UserAgent
|
5
|
+
attr_accessor :type, :string
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@type = options[:type]
|
9
|
+
@string = options[:string]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fetch(options = {})
|
13
|
+
type = options[:type]
|
14
|
+
ua_types = UserAgentRandomizer.user_agent_types
|
15
|
+
user_agents = UserAgentRandomizer.user_agents
|
16
|
+
if ua_types.include?(type)
|
17
|
+
UserAgentRandomizer::UserAgent.new(type: type, string: user_agents[type].sample)
|
18
|
+
else
|
19
|
+
ua_string = user_agents.values.flatten.sample
|
20
|
+
ua_type = user_agents.select{|_,vals| vals.include?(ua_string)}.keys.first
|
21
|
+
UserAgentRandomizer::UserAgent.new(type: ua_type, string: ua_string)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require File.expand_path('../../lib/user_agent_randomizer', __FILE__)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'UserAgentRandomizer::UserAgent' do
|
4
|
+
|
5
|
+
it "contains HTTP User-Agent string" do
|
6
|
+
ua = UserAgentRandomizer::UserAgent.fetch(type: "desktop_browser")
|
7
|
+
expect(ua.string).to be_a String
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a specific type" do
|
11
|
+
ua = UserAgentRandomizer::UserAgent.fetch(type: "desktop_browser")
|
12
|
+
expect(ua.type).to eq("desktop_browser")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has any type" do
|
16
|
+
ua = UserAgentRandomizer::UserAgent.fetch()
|
17
|
+
expect(ua.type.size).to be > 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a random browser if no type is specified" do
|
21
|
+
ua = UserAgentRandomizer::UserAgent.fetch()
|
22
|
+
expect(UserAgentRandomizer.user_agent_types).to include(ua.type)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'user_agent_randomizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "user-agent-randomizer"
|
8
|
+
spec.version = UserAgentRandomizer::VERSION
|
9
|
+
spec.date = "2014-06-27"
|
10
|
+
spec.authors = ["Christoph Pilka"]
|
11
|
+
spec.email = ["c.pilka@asconix.com"]
|
12
|
+
spec.summary = %q{Random HTTP User-Agent string generator}
|
13
|
+
spec.description = ""
|
14
|
+
spec.homepage = "https://github.com/asconix/user-agent-randomizer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
25
|
+
spec.add_development_dependency "nokogiri", "~> 1.6"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.9"
|
27
|
+
spec.add_development_dependency "coveralls", "~> 0.7"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: user-agent-randomizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christoph Pilka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.7'
|
97
|
+
description: ''
|
98
|
+
email:
|
99
|
+
- c.pilka@asconix.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- data/user_agents.yml
|
111
|
+
- lib/user_agent_randomizer.rb
|
112
|
+
- lib/user_agent_randomizer/user_agent.rb
|
113
|
+
- lib/user_agent_randomizer/version.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
- spec/user_agent_randomizer_spec.rb
|
116
|
+
- user_agent_randomizer.gemspec
|
117
|
+
homepage: https://github.com/asconix/user-agent-randomizer
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Random HTTP User-Agent string generator
|
141
|
+
test_files:
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/user_agent_randomizer_spec.rb
|