/** * */ public function create() { $requestOptions = new RequestOptions(); $requestOptions->addPostParams(['name' => $this->name, 'email' => $this->email, 'password' => $this->password]); if (!isset($this->id)) { throw new \Exception("Parameter 'id' is required. It is a GET parameter."); } return PhrestSDK::getResponse(self::METHOD_PUT, sprintf($this->path, $this->id), $requestOptions); }
/** * Makes a cURL HTTP request to the API and returns the response * todo this needs to also handle PUT, POST, DELETE * * @param string $method * @param $path * @param RequestOptions $options * * @throws \Exception * @return string */ private function getHTTPResponse($method, $path, RequestOptions $options = null) { $client = new Client(); // Build body $body = new PostBody(); if ($options) { foreach ($options->getPostParams() as $name => $value) { $body->setField($name, $value); } } // Prepare the request $request = new Request($method, $this->url . $path, [], $body, []); // Get response $response = $client->send($request); $body = json_decode($response->getBody()); if (isset($body->data)) { return $body->data; } else { throw new \Exception('Error calling ' . $method . ' to: ' . $path); } }
/** * */ public function create() { $requestOptions = new RequestOptions(); $requestOptions->addPostParams(['name' => $this->name, 'email' => $this->email, 'password' => $this->password]); return PhrestSDK::getResponse(self::METHOD_POST, $this->path, $requestOptions); }