/**
  * @test
  */
 public function hydratorWillReturnSegmentObject()
 {
     $stdClass = new \stdClass();
     $stdClass->id = 10;
     $stdClass->dataProviderId = 10000;
     $stdClass->status = 'active';
     $stdClass->categoryId = 20000;
     $stdClass->refId = 'test';
     $stdClass->fee = 0.7;
     $stdClass->ttl = 3600;
     $stdClass->name = 'Test';
     $stdClass->audience = true;
     $stdClass->audienceBySources = [];
     $stdClass->audienceByUserIdentityType = [];
     $stdClass->isExtended = true;
     $stdClass->frequency = 5;
     $stdClass->isCrossDevice = true;
     $stdClass->hasDataUsagePermissions = true;
     $stdClass->createdAt = '2015-10-10';
     $stdClass->updatedAt = '2015-10-10';
     $segment = SegmentHydrator::fromStdClass($stdClass);
     $this->assertInstanceOf(Segment::class, $segment);
 }
 /**
  * Update a category
  *
  * @param Segment $segment
  *
  * @throws Exception\EntityInvalidException if the API returns a validation error
  * @throws Exception\ApiException if the API call fails
  *
  * @return Segment
  */
 public function update(Segment $segment)
 {
     // Endpoint URI
     $uri = sprintf('v1/segments/%d', $segment->getId());
     $options = ['json' => $segment];
     try {
         $data = $this->httpClient->put($uri, $options)->getBody()->getContents();
         $segment = SegmentHydrator::fromStdClass(json_decode($data));
         if ($this->cache and $data) {
             $this->cache->invalidate($this->cachePrefix);
             $this->cache->put($this->cachePrefix, $uri . '/' . $segment->getId(), [], $data);
         }
         return $segment;
     } catch (ClientException $e) {
         $response = $e->getResponse();
         $responseBody = $response->getBody()->getContents();
         $responseCode = $response->getStatusCode();
         $error = json_decode($responseBody);
         if (property_exists($error, 'modelState')) {
             // validation error
             throw Exception\EntityInvalidException::invalid($responseBody, $responseCode, $error->modelState);
         } else {
             // general error
             throw Exception\ApiException::translate($responseBody, $responseCode);
         }
     }
 }