agentry 3.1.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/README.md +97 -75
- data/lib/{browser → agentry}/accept_language.rb +2 -2
- data/lib/agentry/action_controller.rb +27 -0
- data/lib/agentry/agentry.rb +213 -0
- data/lib/agentry/aliases.rb +33 -0
- data/lib/{browser → agentry}/alipay.rb +1 -1
- data/lib/{browser → agentry}/base.rb +3 -3
- data/lib/{browser → agentry}/blackberry.rb +1 -1
- data/lib/{browser → agentry}/bot/empty_user_agent_matcher.rb +1 -1
- data/lib/{browser → agentry}/bot/ip_ranges.rb +3 -3
- data/lib/{browser → agentry}/bot/keyword_matcher.rb +1 -1
- data/lib/{browser → agentry}/bot/known_bots_matcher.rb +2 -2
- data/lib/{browser → agentry}/bot.rb +9 -9
- data/lib/agentry/browser_constant.rb +15 -0
- data/lib/{browser → agentry}/cache.rb +6 -6
- data/lib/{browser → agentry}/chrome.rb +1 -1
- data/lib/{browser → agentry}/client_hints.rb +1 -1
- data/lib/{browser → agentry}/cloudflare.rb +2 -2
- data/lib/{browser → agentry}/detect_version.rb +1 -1
- data/lib/{browser → agentry}/detection.rb +1 -1
- data/lib/{browser → agentry}/device/android.rb +1 -1
- data/lib/{browser → agentry}/device/base.rb +1 -1
- data/lib/{browser → agentry}/device/blackberry_playbook.rb +1 -1
- data/lib/{browser → agentry}/device/ipad.rb +1 -1
- data/lib/{browser → agentry}/device/iphone.rb +1 -1
- data/lib/{browser → agentry}/device/ipod_touch.rb +1 -1
- data/lib/{browser → agentry}/device/kindle.rb +1 -1
- data/lib/{browser → agentry}/device/kindle_fire.rb +1 -1
- data/lib/{browser → agentry}/device/playstation3.rb +1 -1
- data/lib/{browser → agentry}/device/playstation4.rb +1 -1
- data/lib/{browser → agentry}/device/psp.rb +1 -1
- data/lib/{browser → agentry}/device/psvita.rb +1 -1
- data/lib/{browser → agentry}/device/samsung.rb +2 -2
- data/lib/{browser → agentry}/device/surface.rb +1 -1
- data/lib/{browser → agentry}/device/switch.rb +1 -1
- data/lib/{browser → agentry}/device/tv.rb +1 -1
- data/lib/{browser → agentry}/device/unknown.rb +1 -1
- data/lib/{browser → agentry}/device/wii.rb +1 -1
- data/lib/{browser → agentry}/device/wiiu.rb +1 -1
- data/lib/{browser → agentry}/device/xbox_360.rb +1 -1
- data/lib/{browser → agentry}/device/xbox_one.rb +1 -1
- data/lib/{browser → agentry}/device.rb +1 -1
- data/lib/{browser → agentry}/duck_duck_go.rb +1 -1
- data/lib/{browser → agentry}/edge.rb +1 -1
- data/lib/{browser → agentry}/electron.rb +1 -1
- data/lib/{browser → agentry}/epiphany.rb +1 -1
- data/lib/{browser → agentry}/facebook.rb +1 -1
- data/lib/{browser → agentry}/firefox.rb +1 -1
- data/lib/{browser → agentry}/google_search_app.rb +1 -1
- data/lib/{browser → agentry}/huawei_browser.rb +1 -1
- data/lib/{browser → agentry}/instagram.rb +1 -1
- data/lib/{browser → agentry}/internet_explorer.rb +1 -1
- data/lib/{browser → agentry}/maxthon.rb +1 -1
- data/lib/{browser → agentry}/meta/base.rb +1 -1
- data/lib/{browser → agentry}/meta/device.rb +1 -1
- data/lib/{browser → agentry}/meta/generic_browser.rb +1 -1
- data/lib/{browser → agentry}/meta/id.rb +1 -1
- data/lib/{browser → agentry}/meta/ie.rb +1 -1
- data/lib/{browser → agentry}/meta/ios.rb +1 -1
- data/lib/{browser → agentry}/meta/mobile.rb +1 -1
- data/lib/{browser → agentry}/meta/platform.rb +1 -1
- data/lib/{browser → agentry}/meta/proxy.rb +1 -1
- data/lib/{browser → agentry}/meta/safari.rb +1 -1
- data/lib/{browser → agentry}/meta/tablet.rb +1 -1
- data/lib/{browser → agentry}/meta/webkit.rb +1 -1
- data/lib/{browser → agentry}/micro_messenger.rb +1 -1
- data/lib/{browser → agentry}/middleware/context/additions.rb +4 -2
- data/lib/agentry/middleware/context/url_methods.rb +17 -0
- data/lib/{browser → agentry}/middleware/context.rb +9 -3
- data/lib/{browser → agentry}/middleware.rb +2 -2
- data/lib/{browser → agentry}/miui_browser.rb +1 -1
- data/lib/{browser → agentry}/nokia.rb +1 -1
- data/lib/{browser → agentry}/opera.rb +1 -1
- data/lib/{browser → agentry}/otter.rb +1 -1
- data/lib/{browser → agentry}/phantom_js.rb +1 -1
- data/lib/{browser → agentry}/platform/adobe_air.rb +1 -1
- data/lib/{browser → agentry}/platform/android.rb +1 -1
- data/lib/{browser → agentry}/platform/base.rb +1 -1
- data/lib/{browser → agentry}/platform/blackberry.rb +1 -1
- data/lib/{browser → agentry}/platform/chrome_os.rb +1 -1
- data/lib/{browser → agentry}/platform/firefox_os.rb +1 -1
- data/lib/{browser → agentry}/platform/ios.rb +1 -1
- data/lib/{browser → agentry}/platform/kai_os.rb +1 -1
- data/lib/{browser → agentry}/platform/linux.rb +1 -1
- data/lib/{browser → agentry}/platform/mac.rb +1 -1
- data/lib/{browser → agentry}/platform/unknown.rb +1 -1
- data/lib/{browser → agentry}/platform/windows.rb +1 -1
- data/lib/{browser → agentry}/platform/windows_mobile.rb +1 -1
- data/lib/{browser → agentry}/platform/windows_phone.rb +1 -1
- data/lib/{browser → agentry}/platform.rb +1 -1
- data/lib/{browser → agentry}/qq.rb +1 -1
- data/lib/agentry/rails.rb +44 -0
- data/lib/{browser → agentry}/safari.rb +1 -1
- data/lib/{browser → agentry}/samsung_browser.rb +1 -1
- data/lib/{browser → agentry}/snapchat.rb +1 -1
- data/lib/{browser → agentry}/sougou_browser.rb +1 -1
- data/lib/{browser → agentry}/sputnik.rb +1 -1
- data/lib/agentry/testing.rb +30 -0
- data/lib/{browser → agentry}/uc_browser.rb +1 -1
- data/lib/{browser → agentry}/unknown.rb +1 -1
- data/lib/{browser → agentry}/version.rb +2 -2
- data/lib/{browser → agentry}/weibo.rb +1 -1
- data/lib/{browser → agentry}/yandex.rb +1 -1
- data/lib/agentry.rb +2 -1
- data/lib/browser/aliases.rb +2 -31
- data/lib/browser/browser.rb +2 -202
- data/lib/browser/rails.rb +3 -22
- data/lib/browser/testing.rb +3 -27
- data/lib/browser.rb +2 -2
- metadata +272 -252
- data/lib/browser/action_controller.rb +0 -21
- data/lib/browser/middleware/context/url_methods.rb +0 -15
- /data/lib/{browser → agentry}/meta.rb +0 -0
data/lib/browser/browser.rb
CHANGED
|
@@ -1,204 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"remove gem \"browser\" from the Gemfile (or whatever depends on it)"
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
require "json"
|
|
9
|
-
require "pathname"
|
|
10
|
-
|
|
11
|
-
require_relative "version"
|
|
12
|
-
require_relative "detect_version"
|
|
13
|
-
require_relative "accept_language"
|
|
14
|
-
require_relative "base"
|
|
15
|
-
require_relative "safari"
|
|
16
|
-
require_relative "chrome"
|
|
17
|
-
require_relative "internet_explorer"
|
|
18
|
-
require_relative "firefox"
|
|
19
|
-
require_relative "edge"
|
|
20
|
-
require_relative "opera"
|
|
21
|
-
require_relative "blackberry"
|
|
22
|
-
require_relative "unknown"
|
|
23
|
-
require_relative "phantom_js"
|
|
24
|
-
require_relative "uc_browser"
|
|
25
|
-
require_relative "nokia"
|
|
26
|
-
require_relative "micro_messenger"
|
|
27
|
-
require_relative "weibo"
|
|
28
|
-
require_relative "qq"
|
|
29
|
-
require_relative "alipay"
|
|
30
|
-
require_relative "electron"
|
|
31
|
-
require_relative "facebook"
|
|
32
|
-
require_relative "otter"
|
|
33
|
-
require_relative "instagram"
|
|
34
|
-
require_relative "yandex"
|
|
35
|
-
require_relative "sputnik"
|
|
36
|
-
require_relative "snapchat"
|
|
37
|
-
require_relative "duck_duck_go"
|
|
38
|
-
require_relative "samsung_browser"
|
|
39
|
-
require_relative "huawei_browser"
|
|
40
|
-
require_relative "miui_browser"
|
|
41
|
-
require_relative "maxthon"
|
|
42
|
-
require_relative "sougou_browser"
|
|
43
|
-
require_relative "google_search_app"
|
|
44
|
-
require_relative "epiphany"
|
|
45
|
-
|
|
46
|
-
require_relative "bot"
|
|
47
|
-
require_relative "bot/empty_user_agent_matcher"
|
|
48
|
-
require_relative "bot/keyword_matcher"
|
|
49
|
-
require_relative "bot/known_bots_matcher"
|
|
50
|
-
require_relative "bot/ip_ranges"
|
|
51
|
-
|
|
52
|
-
require_relative "middleware"
|
|
53
|
-
require_relative "platform"
|
|
54
|
-
require_relative "device"
|
|
55
|
-
require_relative "meta"
|
|
56
|
-
require_relative "client_hints"
|
|
57
|
-
require_relative "cloudflare"
|
|
58
|
-
require_relative "detection"
|
|
59
|
-
require_relative "cache"
|
|
60
|
-
|
|
61
|
-
module Browser
|
|
62
|
-
EMPTY_STRING = ""
|
|
63
|
-
|
|
64
|
-
Bot::DEFAULT_MATCHERS =
|
|
65
|
-
[Bot::EmptyUserAgentMatcher, Bot::KnownBotsMatcher, Bot::KeywordMatcher]
|
|
66
|
-
.freeze
|
|
67
|
-
|
|
68
|
-
Error = Class.new(StandardError)
|
|
69
|
-
|
|
70
|
-
def self.root
|
|
71
|
-
@root ||= Pathname.new(File.expand_path("../..", __dir__))
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# data/bots.json for "bots", written from bots.yml by script/build_data.rb: edit the YAML.
|
|
75
|
-
def self.load_data(name)
|
|
76
|
-
JSON.load_file(root.join("data", "#{name}.json"))
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.eager_load!
|
|
80
|
-
[self, Platform, Device, Bot].each(&:matchers)
|
|
81
|
-
Meta.rules
|
|
82
|
-
AcceptLanguage.languages
|
|
83
|
-
Device::Samsung.names
|
|
84
|
-
Bot.known_bots_trie
|
|
85
|
-
[Bot.bot_exceptions, Bot.search_engines, Bot.category_by_keyword].each { |keywords| Bot.keywords_pattern(keywords) }
|
|
86
|
-
Bot::IPRanges.ranges_by_owner
|
|
87
|
-
nil
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
class << self
|
|
91
|
-
attr_accessor :user_agent_size_limit, :accept_language_size_limit
|
|
92
|
-
attr_reader :cache_size
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
self.user_agent_size_limit = 2048
|
|
96
|
-
self.accept_language_size_limit = 2048
|
|
97
|
-
|
|
98
|
-
def self.cache_size=(size)
|
|
99
|
-
unless size.is_a?(Integer) && size >= 0
|
|
100
|
-
raise ArgumentError, "cache_size must be an Integer >= 0, got #{size.inspect}"
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
@cache_size = size
|
|
104
|
-
Cache.clear
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
self.cache_size = 1000
|
|
108
|
-
|
|
109
|
-
# Hold the list of browser matchers.
|
|
110
|
-
# Order is important.
|
|
111
|
-
def self.matchers
|
|
112
|
-
@matchers ||= [
|
|
113
|
-
Nokia,
|
|
114
|
-
UCBrowser,
|
|
115
|
-
PhantomJS,
|
|
116
|
-
BlackBerry,
|
|
117
|
-
Opera,
|
|
118
|
-
Edge,
|
|
119
|
-
InternetExplorer,
|
|
120
|
-
Firefox,
|
|
121
|
-
Otter,
|
|
122
|
-
Epiphany,
|
|
123
|
-
Facebook,
|
|
124
|
-
Instagram,
|
|
125
|
-
Snapchat,
|
|
126
|
-
Weibo,
|
|
127
|
-
MicroMessenger, # must be placed before QQ
|
|
128
|
-
QQ,
|
|
129
|
-
Alipay,
|
|
130
|
-
Electron,
|
|
131
|
-
Yandex,
|
|
132
|
-
Sputnik,
|
|
133
|
-
DuckDuckGo,
|
|
134
|
-
SamsungBrowser,
|
|
135
|
-
HuaweiBrowser,
|
|
136
|
-
MiuiBrowser,
|
|
137
|
-
Maxthon,
|
|
138
|
-
SougouBrowser,
|
|
139
|
-
GoogleSearchApp,
|
|
140
|
-
|
|
141
|
-
# Must be last
|
|
142
|
-
Chrome,
|
|
143
|
-
Safari,
|
|
144
|
-
Unknown
|
|
145
|
-
]
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# A pattern that every user agent a built-in browser matches also matches:
|
|
149
|
-
# Browser.new skips, without building it, a browser whose pattern fails.
|
|
150
|
-
REQUIRED_PATTERN_BY_MATCHER = {
|
|
151
|
-
Nokia => /S40OviBrowser/,
|
|
152
|
-
UCBrowser => /UCBrowser/,
|
|
153
|
-
PhantomJS => /PhantomJS/,
|
|
154
|
-
BlackBerry => /BlackBerry|BB10/,
|
|
155
|
-
Opera => %r{Opera|OPR/},
|
|
156
|
-
Edge => %r{Edg|Trident/8},
|
|
157
|
-
InternetExplorer => %r{MSIE|Trident/},
|
|
158
|
-
Firefox => /Firefox|FxiOS/,
|
|
159
|
-
Otter => /Otter/,
|
|
160
|
-
Epiphany => /Epiphany/,
|
|
161
|
-
Facebook => /FBAV|FBAN/,
|
|
162
|
-
Instagram => /Instagram/,
|
|
163
|
-
Snapchat => /Snapchat/,
|
|
164
|
-
Weibo => /__weibo__/i,
|
|
165
|
-
MicroMessenger => /MicroMessenger/i,
|
|
166
|
-
QQ => %r{QQ/|QQBrowser}i,
|
|
167
|
-
Alipay => /AlipayClient/i,
|
|
168
|
-
Electron => /Electron/,
|
|
169
|
-
Yandex => /YaBrowser/,
|
|
170
|
-
Sputnik => /SputnikBrowser/,
|
|
171
|
-
DuckDuckGo => /DuckDuckGo/,
|
|
172
|
-
SamsungBrowser => /SamsungBrowser/,
|
|
173
|
-
HuaweiBrowser => /HuaweiBrowser/i,
|
|
174
|
-
MiuiBrowser => /MiuiBrowser/,
|
|
175
|
-
Maxthon => /Maxthon/i,
|
|
176
|
-
SougouBrowser => /(?i:SogouMobileBrowser)|\bSE\b/,
|
|
177
|
-
GoogleSearchApp => /GSA/
|
|
178
|
-
}.compare_by_identity.freeze
|
|
179
|
-
|
|
180
|
-
def self.new(user_agent, **)
|
|
181
|
-
user_agent ||= EMPTY_STRING
|
|
182
|
-
# Before the first regexp: an oversized user agent then costs nothing, and
|
|
183
|
-
# a byte that is not UTF-8 (forged, or read from a log) would make it raise.
|
|
184
|
-
Base.validate_size(:user_agent, user_agent.to_s)
|
|
185
|
-
user_agent = user_agent.scrub unless user_agent.valid_encoding?
|
|
186
|
-
browser_class = Cache.cached_detection(user_agent)&.browser_class
|
|
187
|
-
return browser_class.new(user_agent, **) if browser_class
|
|
188
|
-
|
|
189
|
-
browser = detect(user_agent, **)
|
|
190
|
-
Cache.detection(user_agent).browser_class = browser.class
|
|
191
|
-
browser
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def self.detect(user_agent, **)
|
|
195
|
-
matchers.each do |matcher_class|
|
|
196
|
-
required_pattern = REQUIRED_PATTERN_BY_MATCHER[matcher_class]
|
|
197
|
-
next if required_pattern && !required_pattern.match?(user_agent)
|
|
198
|
-
|
|
199
|
-
matcher = matcher_class.new(user_agent, **)
|
|
200
|
-
return matcher if matcher.match?
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
private_class_method :detect
|
|
204
|
-
end
|
|
3
|
+
require_relative "../agentry/agentry"
|
|
4
|
+
require_relative "../agentry/browser_constant"
|
data/lib/browser/rails.rb
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require_relative "
|
|
5
|
-
require_relative "
|
|
6
|
-
|
|
7
|
-
module Browser
|
|
8
|
-
class Railtie < Rails::Railtie
|
|
9
|
-
config.browser = ActiveSupport::OrderedOptions.new
|
|
10
|
-
config.eager_load_namespaces << Browser
|
|
11
|
-
|
|
12
|
-
initializer "browser" do
|
|
13
|
-
ActiveSupport.on_load(:action_controller) do
|
|
14
|
-
::ActionController::Base.include(Browser::ActionController)
|
|
15
|
-
|
|
16
|
-
::ActionController::Metal.include(Browser::ActionController) if defined?(::ActionController::Metal) # rubocop:disable Layout/LineLength
|
|
17
|
-
|
|
18
|
-
Browser::Middleware::Context.include(
|
|
19
|
-
Browser::Middleware::Context::Additions
|
|
20
|
-
)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
3
|
+
require_relative "../agentry/agentry"
|
|
4
|
+
require_relative "../agentry/rails"
|
|
5
|
+
require_relative "../agentry/browser_constant"
|
data/lib/browser/testing.rb
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def self.user_agents
|
|
7
|
-
@user_agents ||= browser_user_agents
|
|
8
|
-
.merge(bot_user_agents)
|
|
9
|
-
.merge(search_engine_user_agents)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.browser_user_agents
|
|
13
|
-
@browser_user_agents ||= YAML.load_file(Browser.root.join("test/ua.yml"))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.bot_user_agents
|
|
17
|
-
@bot_user_agents ||= YAML.load_file(Browser.root.join("test/ua_bots.yml"))
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.search_engine_user_agents
|
|
21
|
-
@search_engine_user_agents ||= YAML.load_file(
|
|
22
|
-
Browser.root.join("test/ua_search_engines.yml")
|
|
23
|
-
)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def self.[](key)
|
|
27
|
-
user_agents.fetch(key)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
3
|
+
require_relative "../agentry/agentry"
|
|
4
|
+
require_relative "../agentry/testing"
|
|
5
|
+
require_relative "../agentry/browser_constant"
|
data/lib/browser.rb
CHANGED