예제 #1
0
 /**
  * @param Segment $segment
  *
  * @return RepositoryResponse
  * @throws RepositoryException
  */
 public function add(Segment $segment)
 {
     $compiledUrl = $this->baseUrl . $segment->getMemberId();
     $payload = ['segment' => $segment->toArray()];
     $response = $this->client->request('POST', $compiledUrl, ['body' => json_encode($payload)]);
     $repositoryResponse = RepositoryResponse::fromResponse($response);
     if ($repositoryResponse->isSuccessful()) {
         $stream = $response->getBody();
         $responseContent = json_decode($stream->getContents(), true);
         $stream->rewind();
         if (!isset($responseContent['response']['segment']['id'])) {
             throw RepositoryException::wrongFormat(serialize($responseContent));
         }
         $segment->setId($responseContent['response']['segment']['id']);
     }
     return $repositoryResponse;
 }