diff --git a/CHANGELOG.md b/CHANGELOG.md index 91abd88..6411c28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.15.0 + +Adds Push Notification dismissal. Pass a notification ID to `notifications->dismiss` to clear a Push Notification you already sent from the Lock Screen and Notification Center. History keeps it. Also adds `metrics->create` to create a Lock Screen Widget metric and set its label and format, such as currency or percent, and `devices->list` to list the iPhones and iPads paired to your account. + ## 1.14.0 Adds the ability to replace a Push Notification you already sent with a new one. diff --git a/generated/Api/DevicesApi.php b/generated/Api/DevicesApi.php new file mode 100644 index 0000000..618be76 --- /dev/null +++ b/generated/Api/DevicesApi.php @@ -0,0 +1,558 @@ + [ + 'application/json', + ], + ]; + + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null, + $hostIndex = 0 + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation listAccountDevices + * + * List paired devices + * + * @param int $limit Maximum devices to return, 1 to 100. Defaults to 100. (optional, default to 100) + * @param int $offset Devices to skip. Use meta.next_offset from the previous page. (optional, default to 0) + * @param bool $includeInactive Include devices that can no longer receive deliveries, such as unpaired phones. (optional, default to false) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listAccountDevices'] to see the possible values for this operation + * + * @throws \ActivitySmith\Generated\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return \ActivitySmith\Generated\Model\AccountDeviceListResponse|\ActivitySmith\Generated\Model\ForbiddenError|\ActivitySmith\Generated\Model\RateLimitError + */ + public function listAccountDevices($limit = 100, $offset = 0, $includeInactive = false, string $contentType = self::contentTypes['listAccountDevices'][0]) + { + list($response) = $this->listAccountDevicesWithHttpInfo($limit, $offset, $includeInactive, $contentType); + return $response; + } + + /** + * Operation listAccountDevicesWithHttpInfo + * + * List paired devices + * + * @param int $limit Maximum devices to return, 1 to 100. Defaults to 100. (optional, default to 100) + * @param int $offset Devices to skip. Use meta.next_offset from the previous page. (optional, default to 0) + * @param bool $includeInactive Include devices that can no longer receive deliveries, such as unpaired phones. (optional, default to false) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listAccountDevices'] to see the possible values for this operation + * + * @throws \ActivitySmith\Generated\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of \ActivitySmith\Generated\Model\AccountDeviceListResponse|\ActivitySmith\Generated\Model\ForbiddenError|\ActivitySmith\Generated\Model\RateLimitError, HTTP status code, HTTP response headers (array of strings) + */ + public function listAccountDevicesWithHttpInfo($limit = 100, $offset = 0, $includeInactive = false, string $contentType = self::contentTypes['listAccountDevices'][0]) + { + $request = $this->listAccountDevicesRequest($limit, $offset, $includeInactive, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('\ActivitySmith\Generated\Model\AccountDeviceListResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\AccountDeviceListResponse' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\AccountDeviceListResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 403: + if ('\ActivitySmith\Generated\Model\ForbiddenError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\ForbiddenError' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\ForbiddenError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 429: + if ('\ActivitySmith\Generated\Model\RateLimitError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\RateLimitError' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\RateLimitError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = '\ActivitySmith\Generated\Model\AccountDeviceListResponse'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\AccountDeviceListResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\ForbiddenError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\RateLimitError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation listAccountDevicesAsync + * + * List paired devices + * + * @param int $limit Maximum devices to return, 1 to 100. Defaults to 100. (optional, default to 100) + * @param int $offset Devices to skip. Use meta.next_offset from the previous page. (optional, default to 0) + * @param bool $includeInactive Include devices that can no longer receive deliveries, such as unpaired phones. (optional, default to false) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listAccountDevices'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function listAccountDevicesAsync($limit = 100, $offset = 0, $includeInactive = false, string $contentType = self::contentTypes['listAccountDevices'][0]) + { + return $this->listAccountDevicesAsyncWithHttpInfo($limit, $offset, $includeInactive, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation listAccountDevicesAsyncWithHttpInfo + * + * List paired devices + * + * @param int $limit Maximum devices to return, 1 to 100. Defaults to 100. (optional, default to 100) + * @param int $offset Devices to skip. Use meta.next_offset from the previous page. (optional, default to 0) + * @param bool $includeInactive Include devices that can no longer receive deliveries, such as unpaired phones. (optional, default to false) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listAccountDevices'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function listAccountDevicesAsyncWithHttpInfo($limit = 100, $offset = 0, $includeInactive = false, string $contentType = self::contentTypes['listAccountDevices'][0]) + { + $returnType = '\ActivitySmith\Generated\Model\AccountDeviceListResponse'; + $request = $this->listAccountDevicesRequest($limit, $offset, $includeInactive, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'listAccountDevices' + * + * @param int $limit Maximum devices to return, 1 to 100. Defaults to 100. (optional, default to 100) + * @param int $offset Devices to skip. Use meta.next_offset from the previous page. (optional, default to 0) + * @param bool $includeInactive Include devices that can no longer receive deliveries, such as unpaired phones. (optional, default to false) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listAccountDevices'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function listAccountDevicesRequest($limit = 100, $offset = 0, $includeInactive = false, string $contentType = self::contentTypes['listAccountDevices'][0]) + { + + if ($limit !== null && $limit > 100) { + throw new \InvalidArgumentException('invalid value for "$limit" when calling DevicesApi.listAccountDevices, must be smaller than or equal to 100.'); + } + if ($limit !== null && $limit < 1) { + throw new \InvalidArgumentException('invalid value for "$limit" when calling DevicesApi.listAccountDevices, must be bigger than or equal to 1.'); + } + + if ($offset !== null && $offset < 0) { + throw new \InvalidArgumentException('invalid value for "$offset" when calling DevicesApi.listAccountDevices, must be bigger than or equal to 0.'); + } + + + + $resourcePath = '/account/devices'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $limit, + 'limit', // param base name + 'integer', // openApiType + 'form', // style + true, // explode + false // required + ) ?? []); + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $offset, + 'offset', // param base name + 'integer', // openApiType + 'form', // style + true, // explode + false // required + ) ?? []); + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $includeInactive, + 'include_inactive', // param base name + 'boolean', // openApiType + 'form', // style + true, // explode + false // required + ) ?? []); + + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + // this endpoint requires Bearer (API Key) authentication (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'GET', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/generated/Api/PushNotificationsApi.php b/generated/Api/PushNotificationsApi.php index 2af0edd..dee6252 100644 --- a/generated/Api/PushNotificationsApi.php +++ b/generated/Api/PushNotificationsApi.php @@ -71,6 +71,9 @@ class PushNotificationsApi /** @var string[] $contentTypes **/ public const contentTypes = [ + 'dismissPushNotification' => [ + 'application/json', + ], 'replacePushNotification' => [ 'application/json', ], @@ -125,6 +128,495 @@ public function getConfig() return $this->config; } + /** + * Operation dismissPushNotification + * + * Dismiss a push notification + * + * @param string $notificationId The `notification_id` returned when the Push Notification was sent. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['dismissPushNotification'] to see the possible values for this operation + * + * @throws \ActivitySmith\Generated\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return \ActivitySmith\Generated\Model\PushNotificationDismissResponse|\ActivitySmith\Generated\Model\BillingBlockedError|\ActivitySmith\Generated\Model\ForbiddenError|\ActivitySmith\Generated\Model\NotFoundError|\ActivitySmith\Generated\Model\NotFoundError|\ActivitySmith\Generated\Model\SendPushNotification429Response + */ + public function dismissPushNotification($notificationId, string $contentType = self::contentTypes['dismissPushNotification'][0]) + { + list($response) = $this->dismissPushNotificationWithHttpInfo($notificationId, $contentType); + return $response; + } + + /** + * Operation dismissPushNotificationWithHttpInfo + * + * Dismiss a push notification + * + * @param string $notificationId The `notification_id` returned when the Push Notification was sent. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['dismissPushNotification'] to see the possible values for this operation + * + * @throws \ActivitySmith\Generated\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of \ActivitySmith\Generated\Model\PushNotificationDismissResponse|\ActivitySmith\Generated\Model\BillingBlockedError|\ActivitySmith\Generated\Model\ForbiddenError|\ActivitySmith\Generated\Model\NotFoundError|\ActivitySmith\Generated\Model\NotFoundError|\ActivitySmith\Generated\Model\SendPushNotification429Response, HTTP status code, HTTP response headers (array of strings) + */ + public function dismissPushNotificationWithHttpInfo($notificationId, string $contentType = self::contentTypes['dismissPushNotification'][0]) + { + $request = $this->dismissPushNotificationRequest($notificationId, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('\ActivitySmith\Generated\Model\PushNotificationDismissResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\PushNotificationDismissResponse' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\PushNotificationDismissResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 402: + if ('\ActivitySmith\Generated\Model\BillingBlockedError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\BillingBlockedError' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\BillingBlockedError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 403: + if ('\ActivitySmith\Generated\Model\ForbiddenError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\ForbiddenError' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\ForbiddenError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 404: + if ('\ActivitySmith\Generated\Model\NotFoundError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\NotFoundError' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\NotFoundError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 409: + if ('\ActivitySmith\Generated\Model\NotFoundError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\NotFoundError' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\NotFoundError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 429: + if ('\ActivitySmith\Generated\Model\SendPushNotification429Response' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\SendPushNotification429Response' !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\SendPushNotification429Response', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = '\ActivitySmith\Generated\Model\PushNotificationDismissResponse'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\PushNotificationDismissResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 402: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\BillingBlockedError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\ForbiddenError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\NotFoundError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 409: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\NotFoundError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\SendPushNotification429Response', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation dismissPushNotificationAsync + * + * Dismiss a push notification + * + * @param string $notificationId The `notification_id` returned when the Push Notification was sent. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['dismissPushNotification'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function dismissPushNotificationAsync($notificationId, string $contentType = self::contentTypes['dismissPushNotification'][0]) + { + return $this->dismissPushNotificationAsyncWithHttpInfo($notificationId, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation dismissPushNotificationAsyncWithHttpInfo + * + * Dismiss a push notification + * + * @param string $notificationId The `notification_id` returned when the Push Notification was sent. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['dismissPushNotification'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function dismissPushNotificationAsyncWithHttpInfo($notificationId, string $contentType = self::contentTypes['dismissPushNotification'][0]) + { + $returnType = '\ActivitySmith\Generated\Model\PushNotificationDismissResponse'; + $request = $this->dismissPushNotificationRequest($notificationId, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'dismissPushNotification' + * + * @param string $notificationId The `notification_id` returned when the Push Notification was sent. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['dismissPushNotification'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function dismissPushNotificationRequest($notificationId, string $contentType = self::contentTypes['dismissPushNotification'][0]) + { + + // verify the required parameter 'notificationId' is set + if ($notificationId === null || (is_array($notificationId) && count($notificationId) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $notificationId when calling dismissPushNotification' + ); + } + if (strlen($notificationId) < 1) { + throw new \InvalidArgumentException('invalid length for "$notificationId" when calling PushNotificationsApi.dismissPushNotification, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/push-notification/{notification_id}/dismiss'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($notificationId !== null) { + $resourcePath = str_replace( + '{' . 'notification_id' . '}', + ObjectSerializer::toPathValue($notificationId), + $resourcePath + ); + } + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + // this endpoint requires Bearer (API Key) authentication (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation replacePushNotification * diff --git a/generated/Model/AccountDevice.php b/generated/Model/AccountDevice.php new file mode 100644 index 0000000..27c1d27 --- /dev/null +++ b/generated/Model/AccountDevice.php @@ -0,0 +1,832 @@ + + */ +class AccountDevice implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'AccountDevice'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'userEmail' => 'string', + 'deviceId' => 'string', + 'deviceType' => 'string', + 'isActive' => 'bool', + 'tokenStatus' => 'array', + 'appVersion' => 'string', + 'deviceName' => 'string', + 'systemName' => 'string', + 'systemVersion' => 'string', + 'createdAt' => '\DateTime', + 'updatedAt' => '\DateTime' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'userEmail' => null, + 'deviceId' => null, + 'deviceType' => null, + 'isActive' => null, + 'tokenStatus' => null, + 'appVersion' => null, + 'deviceName' => null, + 'systemName' => null, + 'systemVersion' => null, + 'createdAt' => 'date-time', + 'updatedAt' => 'date-time' + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'userEmail' => false, + 'deviceId' => false, + 'deviceType' => true, + 'isActive' => false, + 'tokenStatus' => false, + 'appVersion' => true, + 'deviceName' => true, + 'systemName' => true, + 'systemVersion' => true, + 'createdAt' => true, + 'updatedAt' => true + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'userEmail' => 'user_email', + 'deviceId' => 'device_id', + 'deviceType' => 'device_type', + 'isActive' => 'is_active', + 'tokenStatus' => 'token_status', + 'appVersion' => 'app_version', + 'deviceName' => 'device_name', + 'systemName' => 'system_name', + 'systemVersion' => 'system_version', + 'createdAt' => 'created_at', + 'updatedAt' => 'updated_at' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'userEmail' => 'setUserEmail', + 'deviceId' => 'setDeviceId', + 'deviceType' => 'setDeviceType', + 'isActive' => 'setIsActive', + 'tokenStatus' => 'setTokenStatus', + 'appVersion' => 'setAppVersion', + 'deviceName' => 'setDeviceName', + 'systemName' => 'setSystemName', + 'systemVersion' => 'setSystemVersion', + 'createdAt' => 'setCreatedAt', + 'updatedAt' => 'setUpdatedAt' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'userEmail' => 'getUserEmail', + 'deviceId' => 'getDeviceId', + 'deviceType' => 'getDeviceType', + 'isActive' => 'getIsActive', + 'tokenStatus' => 'getTokenStatus', + 'appVersion' => 'getAppVersion', + 'deviceName' => 'getDeviceName', + 'systemName' => 'getSystemName', + 'systemVersion' => 'getSystemVersion', + 'createdAt' => 'getCreatedAt', + 'updatedAt' => 'getUpdatedAt' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('userEmail', $data ?? [], null); + $this->setIfExists('deviceId', $data ?? [], null); + $this->setIfExists('deviceType', $data ?? [], null); + $this->setIfExists('isActive', $data ?? [], null); + $this->setIfExists('tokenStatus', $data ?? [], null); + $this->setIfExists('appVersion', $data ?? [], null); + $this->setIfExists('deviceName', $data ?? [], null); + $this->setIfExists('systemName', $data ?? [], null); + $this->setIfExists('systemVersion', $data ?? [], null); + $this->setIfExists('createdAt', $data ?? [], null); + $this->setIfExists('updatedAt', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['userEmail'] === null) { + $invalidProperties[] = "'userEmail' can't be null"; + } + if ($this->container['deviceId'] === null) { + $invalidProperties[] = "'deviceId' can't be null"; + } + if ($this->container['deviceType'] === null) { + $invalidProperties[] = "'deviceType' can't be null"; + } + if ($this->container['isActive'] === null) { + $invalidProperties[] = "'isActive' can't be null"; + } + if ($this->container['tokenStatus'] === null) { + $invalidProperties[] = "'tokenStatus' can't be null"; + } + if ($this->container['appVersion'] === null) { + $invalidProperties[] = "'appVersion' can't be null"; + } + if ($this->container['deviceName'] === null) { + $invalidProperties[] = "'deviceName' can't be null"; + } + if ($this->container['systemName'] === null) { + $invalidProperties[] = "'systemName' can't be null"; + } + if ($this->container['systemVersion'] === null) { + $invalidProperties[] = "'systemVersion' can't be null"; + } + if ($this->container['createdAt'] === null) { + $invalidProperties[] = "'createdAt' can't be null"; + } + if ($this->container['updatedAt'] === null) { + $invalidProperties[] = "'updatedAt' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets userEmail + * + * @return string + */ + public function getUserEmail() + { + return $this->container['userEmail']; + } + + /** + * Sets userEmail + * + * @param string $userEmail Email of the account member who paired the device. + * + * @return self + */ + public function setUserEmail($userEmail) + { + if (is_null($userEmail)) { + throw new \InvalidArgumentException('non-nullable userEmail cannot be null'); + } + $this->container['userEmail'] = $userEmail; + + return $this; + } + + /** + * Gets deviceId + * + * @return string + */ + public function getDeviceId() + { + return $this->container['deviceId']; + } + + /** + * Sets deviceId + * + * @param string $deviceId Device ID. Use it to assign the device to Channels. + * + * @return self + */ + public function setDeviceId($deviceId) + { + if (is_null($deviceId)) { + throw new \InvalidArgumentException('non-nullable deviceId cannot be null'); + } + $this->container['deviceId'] = $deviceId; + + return $this; + } + + /** + * Gets deviceType + * + * @return string + */ + public function getDeviceType() + { + return $this->container['deviceType']; + } + + /** + * Sets deviceType + * + * @param string $deviceType Device platform, such as ios. iPhones and iPads both report ios; use system_name to tell them apart. + * + * @return self + */ + public function setDeviceType($deviceType) + { + if (is_null($deviceType)) { + array_push($this->openAPINullablesSetToNull, 'deviceType'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('deviceType', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['deviceType'] = $deviceType; + + return $this; + } + + /** + * Gets isActive + * + * @return bool + */ + public function getIsActive() + { + return $this->container['isActive']; + } + + /** + * Sets isActive + * + * @param bool $isActive True when the device can receive Push Notifications or Live Activities. + * + * @return self + */ + public function setIsActive($isActive) + { + if (is_null($isActive)) { + throw new \InvalidArgumentException('non-nullable isActive cannot be null'); + } + $this->container['isActive'] = $isActive; + + return $this; + } + + /** + * Gets tokenStatus + * + * @return array + */ + public function getTokenStatus() + { + return $this->container['tokenStatus']; + } + + /** + * Sets tokenStatus + * + * @param array $tokenStatus Whether each delivery token is active, keyed by token type (push, start_live_activity). + * + * @return self + */ + public function setTokenStatus($tokenStatus) + { + if (is_null($tokenStatus)) { + throw new \InvalidArgumentException('non-nullable tokenStatus cannot be null'); + } + $this->container['tokenStatus'] = $tokenStatus; + + return $this; + } + + /** + * Gets appVersion + * + * @return string + */ + public function getAppVersion() + { + return $this->container['appVersion']; + } + + /** + * Sets appVersion + * + * @param string $appVersion ActivitySmith app version on the device. + * + * @return self + */ + public function setAppVersion($appVersion) + { + if (is_null($appVersion)) { + array_push($this->openAPINullablesSetToNull, 'appVersion'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('appVersion', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['appVersion'] = $appVersion; + + return $this; + } + + /** + * Gets deviceName + * + * @return string + */ + public function getDeviceName() + { + return $this->container['deviceName']; + } + + /** + * Sets deviceName + * + * @param string $deviceName Device name set on the device. + * + * @return self + */ + public function setDeviceName($deviceName) + { + if (is_null($deviceName)) { + array_push($this->openAPINullablesSetToNull, 'deviceName'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('deviceName', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['deviceName'] = $deviceName; + + return $this; + } + + /** + * Gets systemName + * + * @return string + */ + public function getSystemName() + { + return $this->container['systemName']; + } + + /** + * Sets systemName + * + * @param string $systemName Operating system name, such as iOS or iPadOS. + * + * @return self + */ + public function setSystemName($systemName) + { + if (is_null($systemName)) { + array_push($this->openAPINullablesSetToNull, 'systemName'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('systemName', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['systemName'] = $systemName; + + return $this; + } + + /** + * Gets systemVersion + * + * @return string + */ + public function getSystemVersion() + { + return $this->container['systemVersion']; + } + + /** + * Sets systemVersion + * + * @param string $systemVersion Operating system version. + * + * @return self + */ + public function setSystemVersion($systemVersion) + { + if (is_null($systemVersion)) { + array_push($this->openAPINullablesSetToNull, 'systemVersion'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('systemVersion', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['systemVersion'] = $systemVersion; + + return $this; + } + + /** + * Gets createdAt + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->container['createdAt']; + } + + /** + * Sets createdAt + * + * @param \DateTime $createdAt When the device was first paired. + * + * @return self + */ + public function setCreatedAt($createdAt) + { + if (is_null($createdAt)) { + array_push($this->openAPINullablesSetToNull, 'createdAt'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('createdAt', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['createdAt'] = $createdAt; + + return $this; + } + + /** + * Gets updatedAt + * + * @return \DateTime + */ + public function getUpdatedAt() + { + return $this->container['updatedAt']; + } + + /** + * Sets updatedAt + * + * @param \DateTime $updatedAt When the device last updated its pairing. + * + * @return self + */ + public function setUpdatedAt($updatedAt) + { + if (is_null($updatedAt)) { + array_push($this->openAPINullablesSetToNull, 'updatedAt'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('updatedAt', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['updatedAt'] = $updatedAt; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/generated/Model/AccountDeviceListResponse.php b/generated/Model/AccountDeviceListResponse.php new file mode 100644 index 0000000..b402ab6 --- /dev/null +++ b/generated/Model/AccountDeviceListResponse.php @@ -0,0 +1,449 @@ + + */ +class AccountDeviceListResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'AccountDeviceListResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'devices' => '\ActivitySmith\Generated\Model\AccountDevice[]', + 'meta' => '\ActivitySmith\Generated\Model\AccountDeviceListResponseMeta' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'devices' => null, + 'meta' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'devices' => false, + 'meta' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'devices' => 'devices', + 'meta' => 'meta' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'devices' => 'setDevices', + 'meta' => 'setMeta' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'devices' => 'getDevices', + 'meta' => 'getMeta' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('devices', $data ?? [], null); + $this->setIfExists('meta', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['devices'] === null) { + $invalidProperties[] = "'devices' can't be null"; + } + if ($this->container['meta'] === null) { + $invalidProperties[] = "'meta' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets devices + * + * @return \ActivitySmith\Generated\Model\AccountDevice[] + */ + public function getDevices() + { + return $this->container['devices']; + } + + /** + * Sets devices + * + * @param \ActivitySmith\Generated\Model\AccountDevice[] $devices devices + * + * @return self + */ + public function setDevices($devices) + { + if (is_null($devices)) { + throw new \InvalidArgumentException('non-nullable devices cannot be null'); + } + $this->container['devices'] = $devices; + + return $this; + } + + /** + * Gets meta + * + * @return \ActivitySmith\Generated\Model\AccountDeviceListResponseMeta + */ + public function getMeta() + { + return $this->container['meta']; + } + + /** + * Sets meta + * + * @param \ActivitySmith\Generated\Model\AccountDeviceListResponseMeta $meta meta + * + * @return self + */ + public function setMeta($meta) + { + if (is_null($meta)) { + throw new \InvalidArgumentException('non-nullable meta cannot be null'); + } + $this->container['meta'] = $meta; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/generated/Model/AccountDeviceListResponseMeta.php b/generated/Model/AccountDeviceListResponseMeta.php new file mode 100644 index 0000000..01b2a33 --- /dev/null +++ b/generated/Model/AccountDeviceListResponseMeta.php @@ -0,0 +1,604 @@ + + */ +class AccountDeviceListResponseMeta implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'AccountDeviceListResponse_meta'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'total' => 'int', + 'limit' => 'int', + 'offset' => 'int', + 'hasMore' => 'bool', + 'nextOffset' => 'int', + 'includeInactive' => 'bool' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'total' => null, + 'limit' => null, + 'offset' => null, + 'hasMore' => null, + 'nextOffset' => null, + 'includeInactive' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'total' => false, + 'limit' => false, + 'offset' => false, + 'hasMore' => false, + 'nextOffset' => true, + 'includeInactive' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'total' => 'total', + 'limit' => 'limit', + 'offset' => 'offset', + 'hasMore' => 'has_more', + 'nextOffset' => 'next_offset', + 'includeInactive' => 'include_inactive' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'total' => 'setTotal', + 'limit' => 'setLimit', + 'offset' => 'setOffset', + 'hasMore' => 'setHasMore', + 'nextOffset' => 'setNextOffset', + 'includeInactive' => 'setIncludeInactive' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'total' => 'getTotal', + 'limit' => 'getLimit', + 'offset' => 'getOffset', + 'hasMore' => 'getHasMore', + 'nextOffset' => 'getNextOffset', + 'includeInactive' => 'getIncludeInactive' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('total', $data ?? [], null); + $this->setIfExists('limit', $data ?? [], null); + $this->setIfExists('offset', $data ?? [], null); + $this->setIfExists('hasMore', $data ?? [], null); + $this->setIfExists('nextOffset', $data ?? [], null); + $this->setIfExists('includeInactive', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['total'] === null) { + $invalidProperties[] = "'total' can't be null"; + } + if ($this->container['limit'] === null) { + $invalidProperties[] = "'limit' can't be null"; + } + if ($this->container['offset'] === null) { + $invalidProperties[] = "'offset' can't be null"; + } + if ($this->container['hasMore'] === null) { + $invalidProperties[] = "'hasMore' can't be null"; + } + if ($this->container['nextOffset'] === null) { + $invalidProperties[] = "'nextOffset' can't be null"; + } + if ($this->container['includeInactive'] === null) { + $invalidProperties[] = "'includeInactive' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets total + * + * @return int + */ + public function getTotal() + { + return $this->container['total']; + } + + /** + * Sets total + * + * @param int $total Devices matching the filter. + * + * @return self + */ + public function setTotal($total) + { + if (is_null($total)) { + throw new \InvalidArgumentException('non-nullable total cannot be null'); + } + $this->container['total'] = $total; + + return $this; + } + + /** + * Gets limit + * + * @return int + */ + public function getLimit() + { + return $this->container['limit']; + } + + /** + * Sets limit + * + * @param int $limit limit + * + * @return self + */ + public function setLimit($limit) + { + if (is_null($limit)) { + throw new \InvalidArgumentException('non-nullable limit cannot be null'); + } + $this->container['limit'] = $limit; + + return $this; + } + + /** + * Gets offset + * + * @return int + */ + public function getOffset() + { + return $this->container['offset']; + } + + /** + * Sets offset + * + * @param int $offset offset + * + * @return self + */ + public function setOffset($offset) + { + if (is_null($offset)) { + throw new \InvalidArgumentException('non-nullable offset cannot be null'); + } + $this->container['offset'] = $offset; + + return $this; + } + + /** + * Gets hasMore + * + * @return bool + */ + public function getHasMore() + { + return $this->container['hasMore']; + } + + /** + * Sets hasMore + * + * @param bool $hasMore hasMore + * + * @return self + */ + public function setHasMore($hasMore) + { + if (is_null($hasMore)) { + throw new \InvalidArgumentException('non-nullable hasMore cannot be null'); + } + $this->container['hasMore'] = $hasMore; + + return $this; + } + + /** + * Gets nextOffset + * + * @return int + */ + public function getNextOffset() + { + return $this->container['nextOffset']; + } + + /** + * Sets nextOffset + * + * @param int $nextOffset Offset for the next page, or null on the last page. + * + * @return self + */ + public function setNextOffset($nextOffset) + { + if (is_null($nextOffset)) { + array_push($this->openAPINullablesSetToNull, 'nextOffset'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('nextOffset', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['nextOffset'] = $nextOffset; + + return $this; + } + + /** + * Gets includeInactive + * + * @return bool + */ + public function getIncludeInactive() + { + return $this->container['includeInactive']; + } + + /** + * Sets includeInactive + * + * @param bool $includeInactive includeInactive + * + * @return self + */ + public function setIncludeInactive($includeInactive) + { + if (is_null($includeInactive)) { + throw new \InvalidArgumentException('non-nullable includeInactive cannot be null'); + } + $this->container['includeInactive'] = $includeInactive; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/generated/Model/PushNotificationDismissResponse.php b/generated/Model/PushNotificationDismissResponse.php new file mode 100644 index 0000000..ff567ed --- /dev/null +++ b/generated/Model/PushNotificationDismissResponse.php @@ -0,0 +1,487 @@ + + */ +class PushNotificationDismissResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'PushNotificationDismissResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'success' => 'bool', + 'notificationId' => 'string', + 'dismissedAt' => '\DateTime' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'success' => null, + 'notificationId' => null, + 'dismissedAt' => 'date-time' + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'success' => false, + 'notificationId' => false, + 'dismissedAt' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'success' => 'success', + 'notificationId' => 'notification_id', + 'dismissedAt' => 'dismissed_at' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'success' => 'setSuccess', + 'notificationId' => 'setNotificationId', + 'dismissedAt' => 'setDismissedAt' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'success' => 'getSuccess', + 'notificationId' => 'getNotificationId', + 'dismissedAt' => 'getDismissedAt' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('success', $data ?? [], null); + $this->setIfExists('notificationId', $data ?? [], null); + $this->setIfExists('dismissedAt', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['success'] === null) { + $invalidProperties[] = "'success' can't be null"; + } + if ($this->container['notificationId'] === null) { + $invalidProperties[] = "'notificationId' can't be null"; + } + if ($this->container['dismissedAt'] === null) { + $invalidProperties[] = "'dismissedAt' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets success + * + * @return bool + */ + public function getSuccess() + { + return $this->container['success']; + } + + /** + * Sets success + * + * @param bool $success True when the dismissal is recorded. + * + * @return self + */ + public function setSuccess($success) + { + if (is_null($success)) { + throw new \InvalidArgumentException('non-nullable success cannot be null'); + } + $this->container['success'] = $success; + + return $this; + } + + /** + * Gets notificationId + * + * @return string + */ + public function getNotificationId() + { + return $this->container['notificationId']; + } + + /** + * Sets notificationId + * + * @param string $notificationId ID of the dismissed Push Notification. + * + * @return self + */ + public function setNotificationId($notificationId) + { + if (is_null($notificationId)) { + throw new \InvalidArgumentException('non-nullable notificationId cannot be null'); + } + $this->container['notificationId'] = $notificationId; + + return $this; + } + + /** + * Gets dismissedAt + * + * @return \DateTime + */ + public function getDismissedAt() + { + return $this->container['dismissedAt']; + } + + /** + * Sets dismissedAt + * + * @param \DateTime $dismissedAt When the notification was first dismissed. Repeat calls return the same time. + * + * @return self + */ + public function setDismissedAt($dismissedAt) + { + if (is_null($dismissedAt)) { + throw new \InvalidArgumentException('non-nullable dismissedAt cannot be null'); + } + $this->container['dismissedAt'] = $dismissedAt; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/generated/openapi-source.json b/generated/openapi-source.json index 498433c..6f55ecd 100644 --- a/generated/openapi-source.json +++ b/generated/openapi-source.json @@ -1,6 +1,6 @@ { "repository": "ActivitySmithHQ/activitysmith-backend", - "commit": "7bf9c3d88459fe3f122810979a45da0a1e6fd2d6", + "commit": "278d980633d4b1fc735ca96948fdd8ff8fd27642", "path": "openapi.json", - "sha256": "6987f90b106e28a0ab8058f43309e7a9f045c7c54d27ce90bbdd5966c3f99f7a" + "sha256": "0dbbba13bf497eceea4de0759943481a6e085cdf9a9a5445a60cf2b27457de40" } diff --git a/src/ActivitySmith.php b/src/ActivitySmith.php index 8dd4fd8..c7bfdd7 100644 --- a/src/ActivitySmith.php +++ b/src/ActivitySmith.php @@ -17,6 +17,7 @@ final class ActivitySmith private const LIVE_API_CLASS = 'ActivitySmith\\Generated\\Api\\LiveActivitiesApi'; private const METRICS_API_CLASS = 'ActivitySmith\\Generated\\Api\\MetricsApi'; private const APP_ICON_BADGES_API_CLASS = 'ActivitySmith\\Generated\\Api\\AppIconBadgesApi'; + private const DEVICES_API_CLASS = 'ActivitySmith\\Generated\\Api\\DevicesApi'; private const SDK_HEADER_NAME = 'X-ActivitySmith-SDK'; /** @var Notifications */ @@ -28,6 +29,9 @@ final class ActivitySmith /** @var Metrics */ public $metrics; + /** @var Devices */ + public $devices; + private $appIconBadges; public function __construct(string $apiKey) @@ -43,10 +47,13 @@ public function __construct(string $apiKey) $liveApiClass = self::LIVE_API_CLASS; $metricsApiClass = self::METRICS_API_CLASS; $appIconBadgesApiClass = self::APP_ICON_BADGES_API_CLASS; + $devicesApiClass = self::DEVICES_API_CLASS; $configuration = $configurationClass::getDefaultConfiguration(); $configuration->setAccessToken($apiKey); $configuration->setUserAgent('activitysmith-php/' . Version::VERSION); + // The API reads boolean query parameters as "true" / "false", not 1 / 0. + $configuration->setBooleanFormatForQueryString($configurationClass::BOOLEAN_FORMAT_STRING); $stack = HandlerStack::create(); $stack->push(Middleware::mapRequest( @@ -60,6 +67,7 @@ public function __construct(string $apiKey) $this->notifications = new Notifications(new $pushApiClass($httpClient, $configuration)); $this->liveActivities = new LiveActivities(new $liveApiClass($httpClient, $configuration)); $this->metrics = new Metrics(new $metricsApiClass($httpClient, $configuration)); + $this->devices = new Devices(new $devicesApiClass($httpClient, $configuration)); $this->appIconBadges = new $appIconBadgesApiClass($httpClient, $configuration); } @@ -85,6 +93,7 @@ private function assertGeneratedClientIsPresent(): void || !class_exists(self::LIVE_API_CLASS) || !class_exists(self::METRICS_API_CLASS) || !class_exists(self::APP_ICON_BADGES_API_CLASS) + || !class_exists(self::DEVICES_API_CLASS) ) { throw new RuntimeException( 'Generated PHP client not found. Run SDK regeneration so /generated contains OpenAPI output.' diff --git a/src/Devices.php b/src/Devices.php new file mode 100644 index 0000000..4b548d4 --- /dev/null +++ b/src/Devices.php @@ -0,0 +1,58 @@ +api->listAccountDevices( + $limit, + $offset, + self::booleanQueryValue($includeInactive) + ); + } + + // Generated-style alias. + public function listAccountDevices( + ?int $limit = null, + ?int $offset = null, + ?bool $includeInactive = null, + string $contentType = DevicesApi::contentTypes['listAccountDevices'][0] + ): mixed { + return $this->api->listAccountDevices( + $limit, + $offset, + self::booleanQueryValue($includeInactive), + $contentType + ); + } + + public function __call(string $name, array $arguments): mixed + { + return $this->api->{$name}(...$arguments); + } + + // The API reads include_inactive as the literal string "true". The generated + // client sends booleans as 1/0 by default, so pass the string form directly. + private static function booleanQueryValue(?bool $value): ?string + { + if ($value === null) { + return null; + } + + return $value ? 'true' : 'false'; + } +} diff --git a/src/Notifications.php b/src/Notifications.php index 84c12ec..6d2aded 100644 --- a/src/Notifications.php +++ b/src/Notifications.php @@ -154,6 +154,23 @@ public function replacePushNotification( return $this->api->replacePushNotification($notificationId, $normalized, $contentType); } + /** + * Clears a sent Push Notification from the Lock Screen and Notification Center, + * using the notification_id returned by send(). History keeps it. + */ + public function dismiss(string $notificationId): mixed + { + return $this->api->dismissPushNotification($notificationId); + } + + // Generated-style alias. + public function dismissPushNotification( + string $notificationId, + string $contentType = PushNotificationsApi::contentTypes['dismissPushNotification'][0] + ): mixed { + return $this->api->dismissPushNotification($notificationId, $contentType); + } + public function __call(string $name, array $arguments): mixed { return $this->api->{$name}(...$arguments); diff --git a/src/Version.php b/src/Version.php index b91ad28..ae04bd9 100644 --- a/src/Version.php +++ b/src/Version.php @@ -6,7 +6,7 @@ final class Version { - public const VERSION = '1.14.0'; + public const VERSION = '1.15.0'; private function __construct() { diff --git a/tests/DevicesAndDismissTest.php b/tests/DevicesAndDismissTest.php new file mode 100644 index 0000000..7afbaaa --- /dev/null +++ b/tests/DevicesAndDismissTest.php @@ -0,0 +1,212 @@ + $responses + * @param array> $history + */ + private static function mockClient(array $responses, array &$history): Client + { + $stack = HandlerStack::create(new MockHandler($responses)); + $stack->push(Middleware::history($history)); + + return new Client(['handler' => $stack]); + } + + private static function json(string $body, int $status = 200): Response + { + return new Response($status, ['Content-Type' => 'application/json'], $body); + } + + /** + * @return array + */ + private static function query(\Psr\Http\Message\RequestInterface $request): array + { + parse_str($request->getUri()->getQuery(), $query); + + return $query; + } + + public function testDismissSendsPostAndReturnsParsedBody(): void + { + foreach (['dismiss', 'dismissPushNotification'] as $method) { + $history = []; + $notifications = new Notifications(new PushNotificationsApi( + self::mockClient([self::json(self::DISMISS_RESPONSE)], $history) + )); + + $response = $notifications->{$method}(self::NOTIFICATION_ID); + + $this->assertCount(1, $history); + $request = $history[0]['request']; + $this->assertSame('POST', $request->getMethod()); + $this->assertStringEndsWith( + '/push-notification/' . self::NOTIFICATION_ID . '/dismiss', + $request->getUri()->getPath() + ); + $this->assertSame('', $request->getUri()->getQuery()); + $this->assertInstanceOf(PushNotificationDismissResponse::class, $response); + $this->assertTrue($response->getSuccess()); + $this->assertSame(self::NOTIFICATION_ID, $response->getNotificationId()); + $this->assertSame('2026-11-07T09:05:00+00:00', $response->getDismissedAt()->format(DATE_ATOM)); + } + } + + public function testDevicesListSendsGetWithoutQuery(): void + { + foreach (['list', 'listAccountDevices'] as $method) { + $history = []; + $devices = new Devices(new DevicesApi( + self::mockClient([self::json(self::DEVICES_RESPONSE)], $history) + )); + + $response = $devices->{$method}(); + + $this->assertCount(1, $history); + $request = $history[0]['request']; + $this->assertSame('GET', $request->getMethod()); + $this->assertStringEndsWith('/account/devices', $request->getUri()->getPath()); + $this->assertSame('', $request->getUri()->getQuery()); + $this->assertInstanceOf(AccountDeviceListResponse::class, $response); + $this->assertCount(1, $response->getDevices()); + $this->assertSame('iPhone', $response->getDevices()[0]->getDeviceName()); + $this->assertSame(1, $response->getMeta()->getTotal()); + } + } + + public function testDevicesListSendsQueryParameters(): void + { + foreach (['list', 'listAccountDevices'] as $method) { + $history = []; + $devices = new Devices(new DevicesApi( + self::mockClient([ + self::json(self::DEVICES_RESPONSE), + self::json(self::DEVICES_RESPONSE), + ], $history) + )); + + $devices->{$method}(limit: 10, includeInactive: true); + $devices->{$method}(offset: 20, includeInactive: false); + + $this->assertSame('GET', $history[0]['request']->getMethod()); + $this->assertSame( + ['limit' => '10', 'include_inactive' => 'true'], + self::query($history[0]['request']) + ); + $this->assertSame( + ['offset' => '20', 'include_inactive' => 'false'], + self::query($history[1]['request']) + ); + } + } + + public function testClientWiresDevicesResource(): void + { + $client = new ActivitySmith('test'); + + $this->assertInstanceOf(Devices::class, $client->devices); + } + + public function testDocExamplesRunAgainstMockedClient(): void + { + $history = []; + $http = self::mockClient([ + self::json(self::SEND_RESPONSE), + self::json(self::DISMISS_RESPONSE), + self::json(self::DEVICES_RESPONSE), + self::json(self::DEVICES_RESPONSE), + self::json(self::METRIC_RESPONSE, 201), + self::json(self::METRIC_VALUE_RESPONSE), + ], $history); + + $activitysmith = new ActivitySmith('test-api-key'); + foreach (['notifications', 'devices', 'metrics'] as $resource) { + $api = (new \ReflectionProperty($activitysmith->{$resource}, 'api'))->getValue($activitysmith->{$resource}); + (new \ReflectionProperty($api, 'client'))->setValue($api, $http); + } + + ob_start(); + try { + // Doc examples, verbatim. + $sent = $activitysmith->notifications->send(title: '🙋 Agent needs your input', message: 'Approve the database migration?'); + $activitysmith->notifications->dismiss($sent->getNotificationId()); + $result = $activitysmith->devices->list(); + foreach ($result->getDevices() as $device) { echo $device->getDeviceName() . ' ' . $device->getSystemName() . PHP_EOL; } + $activitysmith->devices->list(includeInactive: true); + $activitysmith->metrics->create('mrr', label: 'MRR', format: 'currency', currencyCode: 'USD'); + $activitysmith->metrics->update('mrr', 12450); + } finally { + $output = ob_get_clean(); + } + + $this->assertSame('iPhone iOS' . PHP_EOL, $output); + $this->assertCount(6, $history); + + $requests = array_map(static fn (array $entry) => $entry['request'], $history); + foreach ($requests as $request) { + $this->assertSame('Bearer test-api-key', $request->getHeaderLine('Authorization')); + } + + [$send, $dismiss, $list, $listInactive, $create, $update] = $requests; + + $this->assertSame('POST', $send->getMethod()); + $this->assertStringEndsWith('/push-notification', $send->getUri()->getPath()); + $this->assertSame( + ['title' => '🙋 Agent needs your input', 'message' => 'Approve the database migration?'], + json_decode((string) $send->getBody(), true) + ); + + $this->assertSame('POST', $dismiss->getMethod()); + $this->assertStringEndsWith('/push-notification/' . self::NOTIFICATION_ID . '/dismiss', $dismiss->getUri()->getPath()); + + $this->assertSame('GET', $list->getMethod()); + $this->assertStringEndsWith('/account/devices', $list->getUri()->getPath()); + $this->assertSame('', $list->getUri()->getQuery()); + + $this->assertSame('GET', $listInactive->getMethod()); + $this->assertSame(['include_inactive' => 'true'], self::query($listInactive)); + + $this->assertSame('PUT', $create->getMethod()); + $this->assertStringEndsWith('/metrics/mrr', $create->getUri()->getPath()); + $this->assertEquals( + ['label' => 'MRR', 'format' => 'currency', 'currency_code' => 'USD'], + json_decode((string) $create->getBody(), true) + ); + + $this->assertSame('POST', $update->getMethod()); + $this->assertStringEndsWith('/metrics/mrr/value', $update->getUri()->getPath()); + $this->assertSame(['value' => 12450], json_decode((string) $update->getBody(), true)); + } +} diff --git a/tests/SmokeTest.php b/tests/SmokeTest.php index aea7276..25dcf83 100644 --- a/tests/SmokeTest.php +++ b/tests/SmokeTest.php @@ -22,6 +22,7 @@ public function testClientConstructsWhenGeneratedCodeIsPresent(): void $this->assertNotNull($client->liveActivities); $this->assertTrue(method_exists($client->notifications, 'send')); $this->assertTrue(method_exists($client->notifications, 'replace')); + $this->assertTrue(method_exists($client->notifications, 'dismiss')); $this->assertTrue(method_exists($client->liveActivities, 'start')); $this->assertTrue(method_exists($client->liveActivities, 'update')); $this->assertTrue(method_exists($client->liveActivities, 'end')); @@ -29,6 +30,9 @@ public function testClientConstructsWhenGeneratedCodeIsPresent(): void $this->assertTrue(method_exists($client->liveActivities, 'endStream')); $this->assertNotNull($client->metrics); $this->assertTrue(method_exists($client->metrics, 'update')); - $this->assertSame('1.14.0', Version::VERSION); + $this->assertTrue(method_exists($client->metrics, 'create')); + $this->assertNotNull($client->devices); + $this->assertTrue(method_exists($client->devices, 'list')); + $this->assertSame('1.15.0', Version::VERSION); } }