Skip to content

Commit 9bfca19

Browse files
Merge pull request #90 from apivideo/sort-params-in-analytics
Add sort parameters in analytics routes
2 parents d8fcc94 + f24fd86 commit 9bfca19

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All changes to this project will be documented in this file.
33

4+
## [1.4.1] - 2024-09-05
5+
- Add sort parameters in analytics endpoints
6+
47
## [1.4.0] - 2024-07-29
58
- Add new analytics methods
69
- Add livestream complete() method

docs/Api/AnalyticsApi.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Name | Type | Description | Notes
7070
------------- | ------------- | ------------- | -------------
7171
`from` | **\DateTime**| Use this query parameter to define the starting date-time of the period you want analytics for. - If you do not set a value for `from`, the default assigned value is 1 day ago, based on the `to` parameter. - The maximum value is 30 days ago. - The value you provide should follow the ATOM date-time format: `2024-02-05T00:00:00+01:00` | [optional]
7272
`to` | **\DateTime**| Use this query parameter to define the ending date-time of the period you want analytics for. - If you do not set a value for `to`, the default assigned value is `now`. - The value for `to` is a non-inclusive value: the API returns data **before** the date-time that you set. | [optional]
73+
`sortBy` | **string**| Use this parameter to choose which field the API will use to sort the analytics data. These are the available fields to sort by: - `metricValue`: Sorts the results based on the **metric** you selected in your request. - `dimensionValue`: Sorts the results based on the **dimension** you selected in your request. | [optional]
74+
`sortOrder` | **string**| Use this parameter to define the sort order of results. These are the available sort orders: - `asc`: Sorts the results in ascending order: `A to Z` and `0 to 9`. - `desc`: Sorts the results in descending order: `Z to A` and `9 to 0`. | [optional]
7375
`filterBy` | [**FilterBy2**](../Model/.md)| Use this parameter to filter the API's response based on different data dimensions. You can serialize filters in your query to receive more detailed breakdowns of your analytics. - If you do not set a value for `filterBy`, the API returns the full dataset for your project. - The API only accepts the `mediaId` and `mediaType` filters when you call `/data/metrics/play/total` or `/data/buckets/play-total/media-id`. These are the available breakdown dimensions: - `mediaId`: Returns analytics based on the unique identifiers of a video or a live stream. - `mediaType`: Returns analytics based on the type of content. Possible values: `video` and `live-stream`. - `continent`: Returns analytics based on the viewers' continent. The list of supported continents names are based on the [GeoNames public database](https://www.geonames.org/countries/). You must use the ISO-3166 alpha2 format, for example `EU`. Possible values are: `AS`, `AF`, `NA`, `SA`, `AN`, `EU`, `AZ`. - `country`: Returns analytics based on the viewers' country. The list of supported country names are based on the [GeoNames public database](https://www.geonames.org/countries/). You must use the ISO-3166 alpha2 format, for example `FR`. - `deviceType`: Returns analytics based on the type of device used by the viewers. Response values can include: `computer`, `phone`, `tablet`, `tv`, `console`, `wearable`, `unknown`. - `operatingSystem`: Returns analytics based on the operating system used by the viewers. Response values can include `windows`, `mac osx`, `android`, `ios`, `linux`. - `browser`: Returns analytics based on the browser used by the viewers. Response values can include `chrome`, `firefox`, `edge`, `opera`. - `tag`: Returns analytics for videos using this tag. This filter only accepts a single value and is case sensitive. Read more about tagging your videos [here](https://docs.api.video/vod/tags-metadata). | [optional]
7476
`currentPage` | **int**| Choose the number of search results to return per page. Minimum value: 1 | [optional] [default to 1]
7577
`pageSize` | **int**| Results per page. Allowed values 1-100, default is 25. | [optional] [default to 25]
@@ -109,6 +111,8 @@ Name | Type | Description | Notes
109111
`from` | **\DateTime**| Use this query parameter to define the starting date-time of the period you want analytics for. - If you do not set a value for `from`, the default assigned value is 1 day ago, based on the `to` parameter. - The maximum value is 30 days ago. - The value you provide should follow the ATOM date-time format: `2024-02-05T00:00:00+01:00` | [optional]
110112
`to` | **\DateTime**| Use this query parameter to define the ending date-time of the period you want analytics for. - If you do not set a value for `to`, the default assigned value is `now`. - The value for `to` is a non-inclusive value: the API returns data **before** the date-time that you set. | [optional]
111113
`interval` | **string**| Use this query parameter to define how granularity of the data. Possible values: `hour`, `day`. - Default: If no interval specified and the period (different between from and to) ≤ 2 days then hour, otherwise day. - If you do not set a value for `interval`, and the period you set using the `from` and `to` parameters is less than or equals to 2 days, then the default assigned value is `hour`. Otherwise the API sets it to `day`. | [optional]
114+
`sortBy` | **string**| Use this parameter to choose which field the API will use to sort the analytics data. These are the available fields to sort by: - `metricValue`: Sorts the results based on the **metric** you selected in your request. - `emittedAt`: Sorts the results based on the **timestamp** of the event in ATOM date-time format. | [optional]
115+
`sortOrder` | **string**| Use this parameter to define the sort order of results. These are the available sort orders: - `asc`: Sorts the results in ascending order: `A to Z` and `0 to 9`. - `desc`: Sorts the results in descending order: `Z to A` and `9 to 0`. | [optional]
112116
`filterBy` | [**FilterBy2**](../Model/.md)| Use this parameter to filter the API's response based on different data dimensions. You can serialize filters in your query to receive more detailed breakdowns of your analytics. - If you do not set a value for `filterBy`, the API returns the full dataset for your project. - The API only accepts the `mediaId` and `mediaType` filters when you call `/data/metrics/play/total` or `/data/buckets/play-total/media-id`. These are the available breakdown dimensions: - `mediaId`: Returns analytics based on the unique identifiers of a video or a live stream. - `mediaType`: Returns analytics based on the type of content. Possible values: `video` and `live-stream`. - `continent`: Returns analytics based on the viewers' continent. The list of supported continents names are based on the [GeoNames public database](https://www.geonames.org/countries/). You must use the ISO-3166 alpha2 format, for example `EU`. Possible values are: `AS`, `AF`, `NA`, `SA`, `AN`, `EU`, `AZ`. - `country`: Returns analytics based on the viewers' country. The list of supported country names are based on the [GeoNames public database](https://www.geonames.org/countries/). You must use the ISO-3166 alpha2 format, for example `FR`. - `deviceType`: Returns analytics based on the type of device used by the viewers. Response values can include: `computer`, `phone`, `tablet`, `tv`, `console`, `wearable`, `unknown`. - `operatingSystem`: Returns analytics based on the operating system used by the viewers. Response values can include `windows`, `mac osx`, `android`, `ios`, `linux`. - `browser`: Returns analytics based on the browser used by the viewers. Response values can include `chrome`, `firefox`, `edge`, `opera`. - `tag`: Returns analytics for videos using this tag. This filter only accepts a single value and is case sensitive. Read more about tagging your videos [here](https://docs.api.video/vod/tags-metadata). | [optional]
113117
`currentPage` | **int**| Choose the number of search results to return per page. Minimum value: 1 | [optional] [default to 1]
114118
`pageSize` | **int**| Results per page. Allowed values 1-100, default is 25. | [optional] [default to 25]

src/Api/AnalyticsApi.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ private function buildGetMetricsBreakdownRequest(string $metric, string $breakdo
193193
// unbox the parameters from the associative array
194194
$from = array_key_exists('from', $queryParams) ? $queryParams['from'] : null;
195195
$to = array_key_exists('to', $queryParams) ? $queryParams['to'] : null;
196+
$sortBy = array_key_exists('sortBy', $queryParams) ? $queryParams['sortBy'] : null;
197+
$sortOrder = array_key_exists('sortOrder', $queryParams) ? $queryParams['sortOrder'] : null;
196198
$filterBy = array_key_exists('filterBy', $queryParams) ? $queryParams['filterBy'] : null;
197199
$currentPage = array_key_exists('currentPage', $queryParams) ? $queryParams['currentPage'] : 1;
198200
$pageSize = array_key_exists('pageSize', $queryParams) ? $queryParams['pageSize'] : 25;
@@ -233,6 +235,22 @@ private function buildGetMetricsBreakdownRequest(string $metric, string $breakdo
233235
$queryParams['to'] = $to;
234236
}
235237

238+
// sortBy query params
239+
if (is_array($sortBy)) {
240+
$sortBy = ObjectSerializer::serializeCollection($sortBy, 'form', true);
241+
}
242+
if ($sortBy !== null) {
243+
$queryParams['sortBy'] = $sortBy;
244+
}
245+
246+
// sortOrder query params
247+
if (is_array($sortOrder)) {
248+
$sortOrder = ObjectSerializer::serializeCollection($sortOrder, 'form', true);
249+
}
250+
if ($sortOrder !== null) {
251+
$queryParams['sortOrder'] = $sortOrder;
252+
}
253+
236254
// filterBy query params
237255
if ($filterBy !== null) {
238256
if(is_array($filterBy)) {
@@ -320,6 +338,8 @@ private function buildGetMetricsOverTimeRequest(string $metric, array $queryPara
320338
$from = array_key_exists('from', $queryParams) ? $queryParams['from'] : null;
321339
$to = array_key_exists('to', $queryParams) ? $queryParams['to'] : null;
322340
$interval = array_key_exists('interval', $queryParams) ? $queryParams['interval'] : null;
341+
$sortBy = array_key_exists('sortBy', $queryParams) ? $queryParams['sortBy'] : null;
342+
$sortOrder = array_key_exists('sortOrder', $queryParams) ? $queryParams['sortOrder'] : null;
323343
$filterBy = array_key_exists('filterBy', $queryParams) ? $queryParams['filterBy'] : null;
324344
$currentPage = array_key_exists('currentPage', $queryParams) ? $queryParams['currentPage'] : 1;
325345
$pageSize = array_key_exists('pageSize', $queryParams) ? $queryParams['pageSize'] : 25;
@@ -362,6 +382,22 @@ private function buildGetMetricsOverTimeRequest(string $metric, array $queryPara
362382
$queryParams['interval'] = $interval;
363383
}
364384

385+
// sortBy query params
386+
if (is_array($sortBy)) {
387+
$sortBy = ObjectSerializer::serializeCollection($sortBy, 'form', true);
388+
}
389+
if ($sortBy !== null) {
390+
$queryParams['sortBy'] = $sortBy;
391+
}
392+
393+
// sortOrder query params
394+
if (is_array($sortOrder)) {
395+
$sortOrder = ObjectSerializer::serializeCollection($sortOrder, 'form', true);
396+
}
397+
if ($sortOrder !== null) {
398+
$queryParams['sortOrder'] = $sortOrder;
399+
}
400+
365401
// filterBy query params
366402
if ($filterBy !== null) {
367403
if(is_array($filterBy)) {

src/BaseClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function __construct(string $baseUri, ?string $apiKey, ClientInterface $h
7878
$this->originSdkHeaderValue = "";
7979

8080
if ($apiKey) {
81-
$this->authenticator = new Authenticator($this, $apiKey, 'php:1.4.0');
81+
$this->authenticator = new Authenticator($this, $apiKey, 'php:1.4.1');
8282
}
8383
}
8484

@@ -111,7 +111,7 @@ public function request(Request $commandRequest, bool $skipAuthRequest = false):
111111
if($this->originSdkHeaderValue) {
112112
$request = $request->withHeader('AV-Origin-Sdk', $this->originSdkHeaderValue);
113113
}
114-
$request = $request->withHeader('AV-Origin-Client', 'php:1.4.0');
114+
$request = $request->withHeader('AV-Origin-Client', 'php:1.4.1');
115115

116116
return $this->sendRequest($request, $skipAuthRequest);
117117
}

0 commit comments

Comments
 (0)