Class: Ferrum::Network::Exchange
- Inherits:
-
Object
- Object
- Ferrum::Network::Exchange
- Defined in:
- lib/ferrum/network/exchange.rb
Instance Attribute Summary collapse
-
#error ⇒ Error?
The error object.
-
#id ⇒ Object
readonly
ID of the request.
-
#intercepted_request ⇒ InterceptedRequest?
The intercepted request.
-
#request ⇒ Request?
The request object.
-
#response ⇒ Response?
The response object.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Determines if the network exchange has a request.
-
#blocked? ⇒ Boolean
Determines if the request was intercepted and blocked.
-
#finished? ⇒ Boolean
Determines if the request was blocked, a response was returned, or if an error occurred.
-
#initialize(page, id) ⇒ Exchange
constructor
Initializes the network exchange.
-
#inspect ⇒ String
Inspects the network exchange.
-
#intercepted? ⇒ Boolean
Determines if the exchange’s request was intercepted.
-
#navigation_request?(frame_id) ⇒ Boolean
Determines if the network exchange was caused by a page navigation event.
-
#pending? ⇒ Boolean
Determines if the network exchange is still not finished.
-
#ping? ⇒ Boolean
Determines if the exchange is ping.
-
#redirect? ⇒ Boolean
Determines if the exchange is a redirect.
-
#to_a ⇒ Array
Converts the network exchange into a request, response, and error tuple.
-
#url ⇒ String?
Returns request’s URL.
-
#xhr? ⇒ Boolean
Determines if the exchange is XHR.
Constructor Details
#initialize(page, id) ⇒ Exchange
Initializes the network exchange.
38 39 40 41 42 43 |
# File 'lib/ferrum/network/exchange.rb', line 38 def initialize(page, id) @id = id @page = page @intercepted_request = nil @request = @response = @error = nil end |
Instance Attribute Details
#error ⇒ Error?
The error object.
29 30 31 |
# File 'lib/ferrum/network/exchange.rb', line 29 def error @error end |
#id ⇒ Object (readonly)
ID of the request.
9 10 11 |
# File 'lib/ferrum/network/exchange.rb', line 9 def id @id end |
#intercepted_request ⇒ InterceptedRequest?
The intercepted request.
14 15 16 |
# File 'lib/ferrum/network/exchange.rb', line 14 def intercepted_request @intercepted_request end |
#request ⇒ Request?
The request object.
19 20 21 |
# File 'lib/ferrum/network/exchange.rb', line 19 def request @request end |
#response ⇒ Response?
The response object.
24 25 26 |
# File 'lib/ferrum/network/exchange.rb', line 24 def response @response end |
Instance Method Details
#blank? ⇒ Boolean
Determines if the network exchange has a request.
62 63 64 |
# File 'lib/ferrum/network/exchange.rb', line 62 def blank? !request end |
#blocked? ⇒ Boolean
Determines if the request was intercepted and blocked.
71 72 73 |
# File 'lib/ferrum/network/exchange.rb', line 71 def blocked? intercepted? && intercepted_request.status?(:aborted) end |
#finished? ⇒ Boolean
Determines if the request was blocked, a response was returned, or if an error occurred.
81 82 83 |
# File 'lib/ferrum/network/exchange.rb', line 81 def finished? blocked? || response&.loaded? || !error.nil? || ping? end |
#inspect ⇒ String
Inspects the network exchange.
153 154 155 156 157 158 159 160 |
# File 'lib/ferrum/network/exchange.rb', line 153 def inspect "#<#{self.class} " \ "@id=#{@id.inspect} " \ "@intercepted_request=#{@intercepted_request.inspect} " \ "@request=#{@request.inspect} " \ "@response=#{@response.inspect} " \ "@error=#{@error.inspect}>" end |
#intercepted? ⇒ Boolean
Determines if the exchange’s request was intercepted.
99 100 101 |
# File 'lib/ferrum/network/exchange.rb', line 99 def intercepted? !intercepted_request.nil? end |
#navigation_request?(frame_id) ⇒ Boolean
Determines if the network exchange was caused by a page navigation event.
53 54 55 |
# File 'lib/ferrum/network/exchange.rb', line 53 def (frame_id) request&.type?(:document) && request&.frame_id == frame_id end |
#pending? ⇒ Boolean
Determines if the network exchange is still not finished.
90 91 92 |
# File 'lib/ferrum/network/exchange.rb', line 90 def pending? !finished? end |
#ping? ⇒ Boolean
Determines if the exchange is ping.
126 127 128 |
# File 'lib/ferrum/network/exchange.rb', line 126 def ping? !!request&.ping? end |
#redirect? ⇒ Boolean
Determines if the exchange is a redirect.
117 118 119 |
# File 'lib/ferrum/network/exchange.rb', line 117 def redirect? response&.redirect? end |
#to_a ⇒ Array
Converts the network exchange into a request, response, and error tuple.
144 145 146 |
# File 'lib/ferrum/network/exchange.rb', line 144 def to_a [request, response, error] end |
#url ⇒ String?
Returns request’s URL.
135 136 137 |
# File 'lib/ferrum/network/exchange.rb', line 135 def url request&.url end |
#xhr? ⇒ Boolean
Determines if the exchange is XHR.
108 109 110 |
# File 'lib/ferrum/network/exchange.rb', line 108 def xhr? !!request&.xhr? end |