Class: Html2rss::RequestService::PuppetCommander
- Inherits:
-
Object
- Object
- Html2rss::RequestService::PuppetCommander
- Defined in:
- lib/html2rss/request_service/puppet_commander.rb
Overview
Commands the Puppeteer Browser to the website and builds the Response.
Instance Method Summary collapse
- #body(page) ⇒ Object
- #call ⇒ Response
-
#initialize(ctx, browser, skip_request_resources: %w[stylesheet image media font].to_set, referer: [ctx.url.scheme, ctx.url.host].join('://')) ⇒ PuppetCommander
constructor
A new instance of PuppetCommander.
- #navigate_to_destination(page, url) ⇒ Object
- #new_page ⇒ Puppeteer::Page
Constructor Details
#initialize(ctx, browser, skip_request_resources: %w[stylesheet image media font].to_set, referer: [ctx.url.scheme, ctx.url.host].join('://')) ⇒ PuppetCommander
Returns a new instance of PuppetCommander.
12 13 14 15 16 17 18 19 20 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 12 def initialize(ctx, browser, skip_request_resources: %w[stylesheet image media font].to_set, referer: [ctx.url.scheme, ctx.url.host].join('://')) @ctx = ctx @browser = browser @skip_request_resources = skip_request_resources @referer = referer end |
Instance Method Details
#body(page) ⇒ Object
54 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 54 def body(page) = page.content |
#call ⇒ Response
23 24 25 26 27 28 29 30 31 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 23 def call page = new_page response = navigate_to_destination(page, ctx.url) Response.new(body: body(page), headers: response.headers) ensure page&.close end |
#navigate_to_destination(page, url) ⇒ Object
50 51 52 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 50 def navigate_to_destination(page, url) page.goto(url, wait_until: 'networkidle0', referer:) end |
#new_page ⇒ Puppeteer::Page
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 36 def new_page page = browser.new_page page.extra_http_headers = ctx.headers return page if skip_request_resources.empty? page.request_interception = true page.on('request') do |request| skip_request_resources.member?(request.resource_type) ? request.abort : request.continue end page end |