Class: Ferrum::Network::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/ferrum/network/exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, id) ⇒ Exchange

Initializes the network exchange.

Parameters:

  • page (Page)
  • id (String)


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

#errorError?

The error object.

Returns:



29
30
31
# File 'lib/ferrum/network/exchange.rb', line 29

def error
  @error
end

#idObject (readonly)

ID of the request.

Returns:

  • String



9
10
11
# File 'lib/ferrum/network/exchange.rb', line 9

def id
  @id
end

#intercepted_requestInterceptedRequest?

The intercepted request.

Returns:



14
15
16
# File 'lib/ferrum/network/exchange.rb', line 14

def intercepted_request
  @intercepted_request
end

#requestRequest?

The request object.

Returns:



19
20
21
# File 'lib/ferrum/network/exchange.rb', line 19

def request
  @request
end

#responseResponse?

The response object.

Returns:



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


81
82
83
# File 'lib/ferrum/network/exchange.rb', line 81

def finished?
  blocked? || response&.loaded? || !error.nil? || ping?
end

#inspectString

Inspects the network exchange.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


99
100
101
# File 'lib/ferrum/network/exchange.rb', line 99

def intercepted?
  !intercepted_request.nil?
end

Determines if the network exchange was caused by a page navigation event.

Parameters:

  • frame_id (String)

Returns:

  • (Boolean)


53
54
55
# File 'lib/ferrum/network/exchange.rb', line 53

def navigation_request?(frame_id)
  request&.type?(:document) && request&.frame_id == frame_id
end

#pending?Boolean

Determines if the network exchange is still not finished.

Returns:

  • (Boolean)


90
91
92
# File 'lib/ferrum/network/exchange.rb', line 90

def pending?
  !finished?
end

#ping?Boolean

Determines if the exchange is ping.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


117
118
119
# File 'lib/ferrum/network/exchange.rb', line 117

def redirect?
  response&.redirect?
end

#to_aArray

Converts the network exchange into a request, response, and error tuple.

Returns:

  • (Array)


144
145
146
# File 'lib/ferrum/network/exchange.rb', line 144

def to_a
  [request, response, error]
end

#urlString?

Returns request’s URL.

Returns:

  • (String, nil)


135
136
137
# File 'lib/ferrum/network/exchange.rb', line 135

def url
  request&.url
end

#xhr?Boolean

Determines if the exchange is XHR.

Returns:

  • (Boolean)


108
109
110
# File 'lib/ferrum/network/exchange.rb', line 108

def xhr?
  !!request&.xhr?
end