/** * Send a service request. * * @param string $method The action type constant (optional, default is GET) * @param array $parameters Query parameters to add to endpoint (optional, default is none) * @param string $body Body of request (optional, default is null) * * @return HTTPMessage HTTP object containing request and response details */ public function send($method, $parameters = array(), $body = null) { $url = $this->endpoint; if (!empty($parameters)) { if (strpos($url, '?') === false) { $sep = '?'; } else { $sep = '&'; } foreach ($parameters as $name => $value) { $url .= $sep . urlencode($name) . '=' . urlencode($value); $sep = '&'; } } if (!$this->unsigned) { $header = ToolProvider\ToolConsumer::addSignature($url, $this->consumer->getKey(), $this->consumer->secret, $body, $method, $this->mediaType); } else { $header = null; } // Connect to tool consumer $http = new HTTPMessage($url, $method, $body, $header); // Parse JSON response if ($http->send() && !empty($http->response)) { $http->responseJson = json_decode($http->response); $http->ok = !is_null($http->responseJson); } return $http; }
/** * Perform a service request * * @param object $service Service object to be executed * @param string $method HTTP action * @param string $format Media type * @param mixed $data Array of parameters or body string * * @return HTTPMessage HTTP object containing request and response details */ public function doServiceRequest($service, $method, $format, $data) { $header = ToolConsumer::addSignature($service->endpoint, $this->getKey(), $this->secret, $data, $method, $format); // Connect to tool consumer $http = new HTTPMessage($service->endpoint, $method, $data, $header); // Parse JSON response if ($http->send() && !empty($http->response)) { $http->responseJson = json_decode($http->response); $http->ok = !is_null($http->responseJson); } return $http; }
/** * Override ToolConsumer::doServiceRequest() to simulate sending/receiving data to and from the tool consumer. * * @param object $service * @param string $method * @param string $format * @param mixed $data * @return HTTPMessage */ public function doServiceRequest($service, $method, $format, $data) { $response = (object) ['tool_proxy_guid' => 1]; $header = ToolConsumer::addSignature($service->endpoint, $this->getKey(), $this->secret, $data, $method, $format); $http = new HTTPMessage($service->endpoint, $method, $data, $header); if ($this->success) { $http->responseJson = $response; $http->ok = true; $http->status = 201; } return $http; }