/** * @param Command $command * @param Response $response * * @return mixed * @throws WixHiveException */ public static function process(Command $command, Response $response) { if (isset($response->getResponseData()->errorCode)) { $message = isset($response->getResponseData()->message) ? $response->getResponseData()->message : "No message"; throw new WixHiveException($message, $response->getResponseData()->errorCode); } return $command->getResponseProcessor()->process($response); }
/** * @param Command $command * @param ResponseInterface $response * * @return mixed * @throws WixHiveException */ public static function process(Command $command, ResponseInterface $response) { $responseData = json_decode((string) $response->getBody()); if (isset($responseData->errorCode)) { $message = isset($responseData->message) ? $responseData->message : "No message"; throw new WixHiveException($message, $responseData->errorCode); } return $command->getResponseProcessor()->process($responseData); }
/** * @param Command $command * @param string $userSessionToken * * @return Model object * @throws WixHiveException */ public function execute(Command $command, $userSessionToken = null) { $date = new \DateTime("now", new \DateTimeZone("UTC")); $getParams = ["version" => self::API_VERSION]; if ($userSessionToken !== null) { $getParams['userSessionToken'] = $userSessionToken; } // prepare the request based on the command $headers = ["x-wix-application-id" => $this->applicationId, "x-wix-instance-id" => $this->instanceId, "x-wix-timestamp" => $date->format(Signature::TIME_FORMAT), "x-wix-signature" => Signature::sign($this->applicationId, $this->secretKey, $this->instanceId, $userSessionToken, Command::WIXHIVE_VERSION, self::API_VERSION, $command->getCommand(), $command->getBody(), $command->getHttpMethod(), $date), "Content-Type" => "application/json", "Expect" => ""]; $wixHiveRequest = new Request($command->getEndpointUrl($getParams), $command->getHttpMethod(), $headers, $command->getBody()); // trigger the request to the WixHive API $response = (new Connector())->execute($wixHiveRequest); // process received response from WixHive API return ResponseProcessor::process($command, $response); }