agentry 3.1.1 → 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 +32 -1
- data/README.md +101 -79
- data/data/bot_categories.json +1 -1
- data/data/bot_ip_ranges.json +1 -1
- data/data/bots.json +1 -1
- 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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "url_methods"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module Agentry
|
|
6
6
|
class Middleware
|
|
7
7
|
class Context
|
|
8
8
|
module Additions
|
|
@@ -10,7 +10,9 @@ module Browser
|
|
|
10
10
|
|
|
11
11
|
included do
|
|
12
12
|
include Rails.application.routes.url_helpers
|
|
13
|
-
|
|
13
|
+
# url_helpers defines default_url_options on the class itself, which an
|
|
14
|
+
# included module cannot override.
|
|
15
|
+
prepend UrlMethods
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Agentry
|
|
4
|
+
class Middleware
|
|
5
|
+
class Context
|
|
6
|
+
module UrlMethods
|
|
7
|
+
def default_url_options
|
|
8
|
+
config = Rails.configuration
|
|
9
|
+
|
|
10
|
+
config.agentry.default_url_options ||
|
|
11
|
+
(config.action_mailer.default_url_options if config.respond_to?(:action_mailer)) ||
|
|
12
|
+
{}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
3
|
+
module Agentry
|
|
4
4
|
class Middleware
|
|
5
5
|
class Context
|
|
6
|
-
attr_reader :
|
|
6
|
+
attr_reader :agentry, :request
|
|
7
7
|
|
|
8
8
|
def initialize(request)
|
|
9
9
|
@request = request
|
|
10
10
|
|
|
11
|
-
@
|
|
11
|
+
@agentry = Agentry.new(
|
|
12
12
|
request.user_agent,
|
|
13
13
|
accept_language: request.env["HTTP_ACCEPT_LANGUAGE"],
|
|
14
14
|
headers: request.env
|
|
15
15
|
)
|
|
16
|
+
@browser = @agentry # browser's name, read by middleware blocks written for it, until 5.0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def browser
|
|
20
|
+
Agentry.deprecate("browser in an Agentry::Middleware block is deprecated and goes away in 5.0: call agentry")
|
|
21
|
+
@browser
|
|
16
22
|
end
|
|
17
23
|
|
|
18
24
|
def redirect_to(path)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "uri"
|
|
4
4
|
require_relative "middleware/context"
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module Agentry
|
|
7
7
|
class Middleware
|
|
8
8
|
# Detect the most common assets.
|
|
9
9
|
ASSETS_REGEX =
|
|
@@ -13,7 +13,7 @@ module Browser
|
|
|
13
13
|
ACCEPT_REGEX = %r{(text/html|\*/\*)}
|
|
14
14
|
|
|
15
15
|
def initialize(app, &block)
|
|
16
|
-
raise ArgumentError, "
|
|
16
|
+
raise ArgumentError, "Agentry::Middleware requires a block" unless block
|
|
17
17
|
|
|
18
18
|
@app = app
|
|
19
19
|
@block = block
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "delegate"
|
|
4
|
+
require "rails"
|
|
5
|
+
require_relative "agentry"
|
|
6
|
+
require_relative "action_controller"
|
|
7
|
+
require_relative "middleware/context/additions"
|
|
8
|
+
|
|
9
|
+
module Agentry
|
|
10
|
+
class Railtie < Rails::Railtie
|
|
11
|
+
class BrowserConfig < SimpleDelegator
|
|
12
|
+
def method_missing(...) # rubocop:disable Style/MissingRespondToMissing -- Delegator's answers for the target
|
|
13
|
+
Agentry.deprecate("config.browser is deprecated and goes away in 5.0: use config.agentry")
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
config.agentry = ActiveSupport::OrderedOptions.new
|
|
19
|
+
config.browser = BrowserConfig.new(config.agentry)
|
|
20
|
+
config.eager_load_namespaces << Agentry
|
|
21
|
+
|
|
22
|
+
# An app that assigned config.browser a new object replaced the wrapper: its options become config.agentry.
|
|
23
|
+
def self.adopt_reassigned_browser_config(config)
|
|
24
|
+
return if config.browser.is_a?(BrowserConfig)
|
|
25
|
+
|
|
26
|
+
Agentry.deprecate("config.browser is deprecated and goes away in 5.0: use config.agentry")
|
|
27
|
+
config.agentry = config.browser
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
config.after_initialize { |app| adopt_reassigned_browser_config(app.config) }
|
|
31
|
+
|
|
32
|
+
initializer "agentry" do
|
|
33
|
+
ActiveSupport.on_load(:action_controller) do
|
|
34
|
+
::ActionController::Base.include(Agentry::ActionController)
|
|
35
|
+
|
|
36
|
+
::ActionController::Metal.include(Agentry::ActionController) if defined?(::ActionController::Metal) # rubocop:disable Layout/LineLength
|
|
37
|
+
|
|
38
|
+
Agentry::Middleware::Context.include(
|
|
39
|
+
Agentry::Middleware::Context::Additions
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "yaml"
|
|
4
|
+
require_relative "agentry"
|
|
5
|
+
|
|
6
|
+
module Agentry
|
|
7
|
+
def self.user_agents
|
|
8
|
+
@user_agents ||= browser_user_agents
|
|
9
|
+
.merge(bot_user_agents)
|
|
10
|
+
.merge(search_engine_user_agents)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.browser_user_agents
|
|
14
|
+
@browser_user_agents ||= YAML.load_file(Agentry.root.join("test/ua.yml"))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.bot_user_agents
|
|
18
|
+
@bot_user_agents ||= YAML.load_file(Agentry.root.join("test/ua_bots.yml"))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.search_engine_user_agents
|
|
22
|
+
@search_engine_user_agents ||= YAML.load_file(
|
|
23
|
+
Agentry.root.join("test/ua_search_engines.yml")
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.[](key)
|
|
28
|
+
user_agents.fetch(key)
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/agentry.rb
CHANGED
data/lib/browser/aliases.rb
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module Browser
|
|
7
|
-
module Aliases
|
|
8
|
-
PLATFORM_ALIASES = %w[
|
|
9
|
-
adobe_air? android? blackberry? chrome_os? firefox_os? ios? ios_app?
|
|
10
|
-
ios_webview? linux? mac? windows10? windows7? windows8? windows8_1?
|
|
11
|
-
windows? windows_mobile? windows_phone? windows_rt?
|
|
12
|
-
windows_touchscreen_desktop? windows_vista? windows_wow64? windows_x64?
|
|
13
|
-
windows_x64_inclusive? windows_xp?
|
|
14
|
-
].freeze
|
|
15
|
-
|
|
16
|
-
DEVICE_ALIASES = %w[
|
|
17
|
-
blackberry_playbook? console? ipad? iphone? ipod_touch? kindle?
|
|
18
|
-
kindle_fire? mobile? nintendo? nintendo_switch? nintendo_wii?
|
|
19
|
-
nintendo_wiiu? playbook? playstation3? playstation4? playstation?
|
|
20
|
-
playstation_vita? ps3? ps4? psp? psp_vita? silk? surface? tablet? tv?
|
|
21
|
-
vita? wii? wiiu? xbox? xbox_360? xbox_one?
|
|
22
|
-
].freeze
|
|
23
|
-
|
|
24
|
-
def self.included(target)
|
|
25
|
-
target.class_eval do
|
|
26
|
-
extend Forwardable
|
|
27
|
-
|
|
28
|
-
def_delegators :platform, *PLATFORM_ALIASES
|
|
29
|
-
def_delegators :device, *DEVICE_ALIASES
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
3
|
+
require_relative "../agentry/aliases"
|
|
4
|
+
require_relative "../agentry/browser_constant"
|