Пример #1
0
 /**
  *
  */
 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);
 }
Пример #2
0
 /**
  * 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);
     }
 }
Пример #3
0
 /**
  *
  */
 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);
 }