Method: Lightstreamer::PostRequest.execute_multiple

Defined in:
lib/lightstreamer/post_request.rb

.execute_multiple(url, bodies) ⇒ Array<LightstreamerError, nil>

Sends a POST request to the specified Lightstreamer URL that concatenates multiple individual POST request bodies into one to avoid sending lots of individual requests. The return value is an array with one entry per body and indicates the error state returned by the server for that body’s request, or ‘nil` if no error occurred.

Parameters:

  • url (String)

    The URL to send the POST request to.

  • bodies (Array<String>)

    The individual POST request bodies that are to be sent together in one request. These should be created with #request_body.

Returns:

  • (Array<LightstreamerError, nil>)

    The execution result of each of the passed bodies. If an entry is ‘nil` then no error occurred when executing that body.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lightstreamer/post_request.rb', line 29

def execute_multiple(url, bodies)
  response = Excon.post url, body: bodies.join("\r\n"), expects: 200, connect_timeout: 15

  response_lines = response.body.split("\n").map(&:strip)

  errors = []
  errors << parse_error(response_lines) until response_lines.empty?

  raise LightstreamerError if errors.size != bodies.size

  errors
rescue Excon::Error => e
  raise Errors::ConnectionError, e.message
end