/** * Sends the batch to the CloudSearch API * @param LiftBatch $batch */ public function sendBatch($batch) { $response = $this->send('POST', $batch->convert_to_JSON()); if ($response && 'error' === $response->status) { $this->error_messages = $response->errors; return false; } if (in_array($this->http_interface->getStatusCode(), array(200, 201, 204))) { return $response; } return false; }
public function send_request($operation, $payload = array()) { // Determine signing values $current_time = time(); $timestamp = gmdate(self::DATE_FORMAT_SIGV4, $current_time); // Initialize $this->headers = array(); $this->signed_headers = array(); $this->canonical_headers = array(); $this->query = array('body' => is_array($payload) ? $payload : array()); // $this->query['body']['Action'] = $operation; $this->query['body']['Version'] = $this->api_version; // Do a case-sensitive, natural order sort on the array keys. uksort($this->query['body'], 'strcmp'); // Parse our request. $parsed_url = parse_url($this->endpoint); $host_header = strtolower($parsed_url['host']); // Generate the querystring from $this->query $this->querystring = $this->to_query_string($this->query); // Compose the request. $request_url = $this->endpoint . (isset($parsed_url['path']) ? '' : '/'); $this->querystring = $this->canonical_querystring(); $this->headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'; $this->headers['X-Amz-Date'] = $timestamp; $this->headers['Content-Length'] = strlen($this->querystring); $this->headers['Content-MD5'] = $this->hex_to_base64(md5($this->querystring)); $this->headers['Host'] = $host_header; $this->headers['Accept'] = 'application/json'; // Sort headers uksort($this->headers, 'strnatcasecmp'); // Add headers to request and compute the string to sign foreach ($this->headers as $header_key => $header_value) { // Strip line breaks and remove consecutive spaces. Services collapse whitespace in signature calculation $this->headers[$header_key] = preg_replace('/\\s+/', ' ', trim($header_value)); $this->canonical_headers[] = strtolower($header_key) . ':' . $header_value; $this->signed_headers[] = strtolower($header_key); } $this->headers['Authorization'] = $this->authorization($timestamp); $post = $this->http_interface->post($request_url, $this->canonical_querystring(), $this->headers); $this->error = $post === false ? $this->http_interface->getLastError() : false; $this->status_code = $this->http_interface->getStatusCode(); return $post; }