Class: Html2rss::RequestService
- Inherits:
-
Object
- Object
- Html2rss::RequestService
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/html2rss/request_service.rb,
lib/html2rss/request_service/budget.rb,
lib/html2rss/request_service/policy.rb,
lib/html2rss/request_service/context.rb,
lib/html2rss/request_service/response.rb,
lib/html2rss/request_service/strategy.rb,
lib/html2rss/request_service/network_guard.rb,
lib/html2rss/request_service/response_guard.rb,
lib/html2rss/request_service/blocked_surface.rb,
lib/html2rss/request_service/faraday_strategy.rb,
lib/html2rss/request_service/puppet_commander.rb,
lib/html2rss/request_service/botasaurus_contract.rb,
lib/html2rss/request_service/botasaurus_strategy.rb,
lib/html2rss/request_service/local_file_strategy.rb,
lib/html2rss/request_service/browserless_strategy.rb,
lib/html2rss/request_service/puppet_commander/preload_runner.rb,
lib/html2rss/request_service/puppet_commander/navigation_guards.rb
Overview
Requests website URLs to retrieve their HTML for further processing. Provides concrete transport strategies (e.g. Faraday, Browserless).
Feed-level :auto is not registered here — FeedPipeline::StrategyPlan resolves
it to a concrete strategy (or FeedPipeline::AutoFallback chain) before execute.
Defined Under Namespace
Modules: BlockedSurface Classes: BlockedSurfaceDetected, BotasaurusConfigurationError, BotasaurusConnectionFailed, BotasaurusContract, BotasaurusStrategy, BrowserlessConfigurationError, BrowserlessConnectionFailed, BrowserlessStrategy, Budget, Context, CrossOriginFollowUpDenied, FaradayStrategy, InteractionBudgetExceeded, InvalidUrl, LocalFileStrategy, NetworkGuard, Policy, PrivateNetworkDenied, PuppetCommander, RequestBudgetExceeded, RequestTimedOut, Response, ResponseGuard, ResponseTooLarge, Strategy, UnknownStrategy, UnsupportedResponseContentType, UnsupportedUrlScheme
Instance Attribute Summary collapse
-
#default_strategy_name ⇒ Symbol
The default strategy name.
Instance Method Summary collapse
-
#execute(ctx, strategy: default_strategy_name) ⇒ Response
Executes the request using the specified strategy.
-
#initialize ⇒ RequestService
constructor
A new instance of RequestService.
-
#register_strategy(name, strategy_class) ⇒ Class
Registers a new strategy.
-
#strategy_names ⇒ Array<String>
The names of the registered strategies.
-
#strategy_registered?(name) ⇒ Boolean
Checks if a strategy is registered.
-
#unregister_strategy(name) ⇒ Boolean
Unregisters a strategy.
Constructor Details
#initialize ⇒ RequestService
Returns a new instance of RequestService.
61 62 63 64 65 66 67 68 69 |
# File 'lib/html2rss/request_service.rb', line 61 def initialize @strategies = { faraday: FaradayStrategy, botasaurus: BotasaurusStrategy, browserless: BrowserlessStrategy, local_file: LocalFileStrategy } @default_strategy_name = :faraday end |
Instance Attribute Details
#default_strategy_name ⇒ Symbol
Returns the default strategy name.
72 73 74 |
# File 'lib/html2rss/request_service.rb', line 72 def default_strategy_name @default_strategy_name end |
Instance Method Details
#execute(ctx, strategy: default_strategy_name) ⇒ Response
Executes the request using the specified strategy.
129 130 131 132 133 134 135 136 |
# File 'lib/html2rss/request_service.rb', line 129 def execute(ctx, strategy: default_strategy_name) strategy_class = @strategies.fetch(strategy.to_sym) do raise UnknownStrategy, "The strategy '#{strategy}' is not known. Available strategies: #{strategy_names.join(', ')}" end strategy_class.new(ctx).execute end |
#register_strategy(name, strategy_class) ⇒ Class
Registers a new strategy.
94 95 96 97 98 99 100 |
# File 'lib/html2rss/request_service.rb', line 94 def register_strategy(name, strategy_class) unless strategy_class.is_a?(Class) raise ArgumentError, "Expected a Class for strategy, got #{strategy_class.class}" end @strategies[name.to_sym] = strategy_class end |
#strategy_names ⇒ Array<String>
Returns the names of the registered strategies.
86 |
# File 'lib/html2rss/request_service.rb', line 86 def strategy_names = @strategies.keys.map(&:to_s) |
#strategy_registered?(name) ⇒ Boolean
Checks if a strategy is registered.
106 107 108 |
# File 'lib/html2rss/request_service.rb', line 106 def strategy_registered?(name) @strategies.key?(name.to_sym) end |
#unregister_strategy(name) ⇒ Boolean
Unregisters a strategy.
115 116 117 118 119 120 |
# File 'lib/html2rss/request_service.rb', line 115 def unregister_strategy(name) # rubocop:disable Naming/PredicateMethod name_sym = name.to_sym raise ArgumentError, 'Cannot unregister the default strategy.' if name_sym == @default_strategy_name !!@strategies.delete(name_sym) end |