/** * Returns an array of data usage objects * * @param int $dataProviderId * @param |DateTime $from * @param |DateTime $to * @param array $groupBy * @param int $limit * @param int $offset * * @throws Exception\ApiException if the API call fails * * @return array */ public function get($dataProviderId, $from, $to, $groupBy, $limit = 1000, $offset = 0) { // Endpoint URI $uri = 'v1/reports/datausage'; $options = ['query' => ['dataProviderId' => $dataProviderId, 'from' => $from->format('c'), 'to' => $to->format('c'), 'groupBy' => $groupBy, 'limit' => $limit, 'offset' => $offset]]; $usage = []; try { $data = null; // try to get from cache if ($this->cache) { $data = $this->cache->get($this->cachePrefix, $uri, $options); } // load from API if (!$data) { $data = $this->httpClient->get($uri, $options)->getBody()->getContents(); if ($this->cache and $data) { $this->cache->put($this->cachePrefix, $uri, $options, $data); } } $usage = json_decode($data); } catch (ClientException $e) { $response = $e->getResponse(); $responseBody = $response->getBody()->getContents(); $responseCode = $response->getStatusCode(); throw new Exception\ApiException($responseBody, $responseCode); } return $usage; }
/** * Returns an array of audience objects * * @param int $dataProviderId * @param |DateTime $from * @param |DateTime $to * @param array $groupBy * * @throws Exception\ApiException if the API call fails * * @return DataProviderAudience[] */ public function get($dataProviderId, $from, $to, $groupBy) { // Endpoint URI $uri = 'v1/dataproviders/' . $dataProviderId . '/audience'; $options = ['query' => ['from' => $from->format('c'), 'to' => $to->format('c'), 'groupBy' => $groupBy]]; $dataProviderAudiences = []; try { $data = null; // try to get from cache if ($this->cache) { $data = $this->cache->get($this->cachePrefix, $uri, $options); } // load from API if (!$data) { $data = $this->httpClient->get($uri, $options)->getBody()->getContents(); if ($this->cache and $data) { $this->cache->put($this->cachePrefix, $uri, $options, $data); } } $classArray = json_decode($data); foreach ($classArray as $class) { $dataProviderAudiences[] = DataProviderAudienceHydrator::fromStdClass($class); } } catch (ClientException $e) { $response = $e->getResponse(); $responseBody = $response->getBody()->getContents(); $responseCode = $response->getStatusCode(); throw new Exception\ApiException($responseBody, $responseCode); } return $dataProviderAudiences; }
/** * Delete a category * * @param Category $category * * @throws Exception\ApiException if the API call fails * * @return Category */ public function delete(Category $category) { // Endpoint URI $uri = sprintf('v1/categories/%d', $category->getId()); try { $response = $this->httpClient->delete($uri); if ($this->cache) { $this->cache->invalidate($this->cachePrefix); } return true; } catch (ClientException $e) { $response = $e->getResponse(); $responseBody = $response->getBody()->getContents(); $responseCode = $response->getStatusCode(); throw Exception\ApiException::translate($responseBody, $responseCode); } }