Build a batch of responses to return to the user
@param array $batch the batch that the response is related to
@param \Httpful\Response $response The response from the API
@return Response
324880
private function buildBatchResponse($batch, $response) {
        $result = [];
        $responseBody = json_decode($response->raw_body, true);
        foreach ($batch as $collection => $events) {
            $eventResults = [];
            $eventResponses = $responseBody[$collection];
            foreach($events as $index => $event) {
                $eventResponse = $eventResponses[$index];
                $eventResult = new Response($eventResponse['success'], $eventResponse['duplicate'], null, $eventResponse['message'], $event);
                array_push($eventResults, $eventResult);
            }
            $result[$collection] = $eventResults;
        }

        $statusCode = $response->code;
        $errorMessage = $response->body->errorMessage;

        return new ResponseBatch($statusCode, $errorMessage, $result);
    }
808342
protected function getBatchResponses(ResponseInterface $response)
    {
        $results = JsonRpc\json_decode((string) $response->getBody(), true);

        return array_map(function (array $result) use ($response) {
            return $this->messageFactory->createResponse(
                $response->getStatusCode(),
                $response->getHeaders(),
                $result
            );
        }, $results);
    }
1109596
def batch(self, methods):
        
        methods = list(methods) # methods can be iterator
        if not methods:
            #accepts also empty list (or generator) - it allows call batch directly with query result (eventually empty)
            return
        queries, callbacks = list(zip(*[m(batch=True) for m in methods]))
        # perform all the operations in one batch
        responses = self.execute("", "POST", requests=queries)
        # perform the callbacks with the response data (updating the existing
        # objets, etc)

        batched_errors = []
        for callback, response in zip(callbacks, responses):
            if "success" in response:
                callback(response["success"])
            else:
                batched_errors.append(response["error"])

        if batched_errors:
            raise core.ParseBatchError(batched_errors)
570713
protected function _processResponse(Response $response): ResponseSet
    {
        $responseData = $response->getData();

        $actions = $this->getActions();

        $bulkResponses = [];

        if (isset($responseData['items']) && \is_array($responseData['items'])) {
            foreach ($responseData['items'] as $key => $item) {
                if (!isset($actions[$key])) {
                    throw new InvalidException('No response found for action #'.$key);
                }

                $action = $actions[$key];

                $opType = \key($item);
                $bulkResponseData = \reset($item);

                if ($action instanceof AbstractDocumentAction) {
                    $data = $action->getData();
                    if ($data instanceof Document && $data->isAutoPopulate()
                        || $this->_client->getConfigValue(['document', 'autoPopulate'], false)
                    ) {
                        if (!$data->hasId() && isset($bulkResponseData['_id'])) {
                            $data->setId($bulkResponseData['_id']);
                        }
                        if (isset($bulkResponseData['_version'])) {
                            $data->setVersion($bulkResponseData['_version']);
                        }
                    }
                }

                $bulkResponses[] = new BulkResponse($bulkResponseData, $action, $opType);
            }
        }

        $bulkResponseSet = new ResponseSet($response, $bulkResponses);

        if ($bulkResponseSet->hasError()) {
            throw new BulkResponseException($bulkResponseSet);
        }

        return $bulkResponseSet;
    }
3522
function BatchCB (response) {
        console.log ("### Batch SMS CallBack --> Status=%j", response);

        if (response.status === 0 || response.status === -4) {
              console.log ("SMS Batch Test done");
              setTimeout (process.exit, 1000);
        }
    }
803721
public function updateBinaryBatch(
        $batchId, Api\MtBatchBinarySmsUpdate $batch
    ) {
        $json = Serialize::binaryBatchUpdate($batch);
        $result = $this->_post($this->_batchUrl($batchId), $json);
        return Deserialize::batchResponse($result);
    }
379614
public function executeBatch(array $headers = null, array $clientOptions = [])
    {
        $requests = $this->getBatchHttpRequests($headers);
        $client = $this->getHttpClient();
        if ($client instanceof AdapterOptionInterface) {
            $httpResponses = $client->executeBatch($requests, $clientOptions);
        } else {
            $httpResponses = $client->executeBatch($requests);
        }

        $responses = [];
        foreach ($httpResponses as $key => $httpResponse) {
            $request = $this->batchRequests[$key];
            $httpRequest = $requests[$key];
            if ($httpResponse instanceof ApiException) {
                $exception = $httpResponse;
                if ($this->getConfig()->getThrowExceptions() ||
                    !$httpResponse->getResponse() instanceof ResponseInterface
                ) {
                    throw $exception;
                }
                $this->logException($httpResponse);
                $httpResponse = $exception->getResponse();
                $responses[$request->getIdentifier()] = new ErrorResponse(
                    $exception,
                    $request,
                    $httpResponse
                );
            } else {
                $responses[$request->getIdentifier()] = $request->buildResponse($httpResponse);
            }
            $this->logDeprecatedRequest($httpResponse, $httpRequest);
        }
        unset($this->batchRequests);
        $this->batchRequests = [];

        return $responses;
    }
591857
def process_response(self, request, response):
        """"""
        batcher = PrioritizedBatcher.global_instance()
        if batcher.is_started:
            # May not be started due to strange middleware behavior on first request.
            batcher.commit()

        return response
785035
public function deconstructBatchResponseBody(string $batchResponseBody, string $boundary): array
    {
        $connector         = $this->request->client->connector;
        $batchObjects      = [];
        $batchResponseBody = rtrim($batchResponseBody, '--' . $boundary . '--');

        $batchParts = explode('--' . $boundary . $connector::HTTP_EOL, $batchResponseBody);
        array_shift($batchParts);
        $i                   = 0;
        $batchObjectTemplate = new static();

        foreach ($batchParts as &$batchPart) {
            /** @var $batchPart HttpResponse */
            $batchPartHeaders = static::splitBatchPart($batchPart);
            $batchObject      = clone $batchObjectTemplate;
            $batchObject->buildBatch($batchPartHeaders[1]);
            //            $batchArangoHeader  = explode(PHP_EOL, $batchPartHeaders[0]);
            $batchArangoHeaderArray = $this->getHeaderArray($batchPartHeaders[0]);
            if (array_key_exists('Content-Id', $batchArangoHeaderArray)) {
                $batchObject->batchContentId = $batchArangoHeaderArray['Content-Id'][0];
            }
            $batchObjects[] = $batchObject;
            $i++;
        }

        return $batchObjects;
    }
1130948
public function call(Request $request, Response $response) : Response {

		return call_user_func($this->callable, $request, $response, $this->slugs);

	}
933681
protected function respond($success, $response)
    {
        if (Arr::get($response, 'object') !== 'list') {
            $success = (!array_key_exists('error', $response));

            return $this->mapResponse($success, $response);
        }

        $responses = [];

        foreach ($response['data'] as $responds) {
            $success = (!array_key_exists('error', $responds));

            $responses[] = $this->mapResponse($success, $responds);
        }

        return $responses;
    }
741806
public function createBinaryBatch(Api\MtBatchBinarySmsCreate $batch)
    {
        $json = Serialize::binaryBatch($batch);
        $result = $this->_post($this->_url('/batches'), $json);
        return Deserialize::batchResponse($result);
    }
1333320
private function _buildResponse($response)
    {
        $sections = explode("\r\n\r\n", $response, 2);
        $body = isset($sections[1]) ? $sections[1] : NULL;
        $headers = array();
        $headerlines = explode("\n", $sections[0]);

        // process status
        list($http, $code, $message) = explode(' ', $headerlines[0], 3);

        // process headers
        foreach (array_slice($headerlines, 1) as $headerline) {
            $headers[] = HeaderField::fromString($headerline);
        }

        $response = new Response($code, $headers, $body);

        return $response;
    }
877000
private function buildResults(Response $response): array
    {
        $data = $response->getData();
        $results = [];

        if (!isset($data['hits']['hits'])) {
            return $results;
        }

        foreach ($data['hits']['hits'] as $hit) {
            $results[] = new Result($hit);
        }

        return $results;
    }
991517
private function processResponse(Response $response)
    {
        $response = $response->getBody()->getContents();
        $response = json_decode($response, true);

        return $response;
    }
63602
protected function respond($response)
    {
        if (!isset($response[0])) {
            $success = !(array_key_exists('type', $response) && $response['type'] == 'error')
                && !(array_key_exists('status', $response) && $response['status'] == 'error');

            return $this->mapResponse($success, $response);
        }

        $responses = [];

        foreach ($response as $responds) {
            $success = !(array_key_exists('type', $response) && $response['type'] == 'error')
                && !(array_key_exists('status', $response) && $response['status'] == 'error');

            $responses[] = $this->mapResponse($success, $responds);
        }

        return $responses;
    }
1007273
public static function respond(Response $response)
    {
        $next = function () use ($response) {
            return $response;
        };

        (new static())->handle(Request::capture(), $next)->send();

        exit;
    }