diff --git a/docs/Api/DefaultApi.md b/docs/Api/DefaultApi.md index 44dd1db..63c1e18 100644 --- a/docs/Api/DefaultApi.md +++ b/docs/Api/DefaultApi.md @@ -32,6 +32,7 @@ Method | HTTP request | Description [**getNotificationHistory()**](DefaultApi.md#getNotificationHistory) | **POST** /notifications/{notification_id}/history | Notification History [**getNotifications()**](DefaultApi.md#getNotifications) | **GET** /notifications | View notifications [**getOutcomes()**](DefaultApi.md#getOutcomes) | **GET** /apps/{app_id}/outcomes | View Outcomes +[**getSegment()**](DefaultApi.md#getSegment) | **GET** /apps/{app_id}/segments/{segment_id} | View Segment [**getSegments()**](DefaultApi.md#getSegments) | **GET** /apps/{app_id}/segments | Get Segments [**getUser()**](DefaultApi.md#getUser) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id} | [**rotateApiKey()**](DefaultApi.md#rotateApiKey) | **POST** /apps/{app_id}/auth/tokens/{token_id}/rotate | Rotate API key @@ -2182,6 +2183,79 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](https://github.com/OneSignal/onesignal-php-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-php-api) +## `getSegment()` + +```php +getSegment($app_id, $segment_id, $include_segment_detail): \onesignal\client\model\GetSegmentSuccessResponse +``` + +View Segment + +Retrieve details for a single segment by its ID, including subscriber count and optionally segment metadata and filters. + +### Example + +```php +setRestApiKeyToken('YOUR_REST_API_KEY') + ->setOrganizationApiKeyToken('YOUR_ORGANIZATION_API_KEY'); + + + +$apiInstance = new onesignal\client\Api\DefaultApi( + // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. + // This is optional, `GuzzleHttp\Client` will be used as default. + new GuzzleHttp\Client(), + $config +); +$app_id = 'YOUR_APP_ID'; // string | The OneSignal App ID for your app. Available in Keys & IDs. +$segment_id = 'd6c5a3e1-9f17-44a1-9d10-7c0e4a2b1c8e'; // string | The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. +$include_segment_detail = true; // bool | Set to true to include segment metadata and filters in the response. + +try { + $result = $apiInstance->getSegment($app_id, $segment_id, $include_segment_detail); + print_r($result); +} catch (\onesignal\client\ApiException $e) { + echo 'Exception when calling DefaultApi->getSegment: ', $e->getMessage(), PHP_EOL; + echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; + echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; +} catch (\Exception $e) { + echo 'Exception when calling DefaultApi->getSegment: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **app_id** | **string**| The OneSignal App ID for your app. Available in Keys & IDs. | + **segment_id** | **string**| The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. | + **include_segment_detail** | **bool**| Set to true to include segment metadata and filters in the response. | [optional] + +### Return type + +[**\onesignal\client\model\GetSegmentSuccessResponse**](../Model/GetSegmentSuccessResponse.md) + +### Authorization + +[rest_api_key](https://github.com/OneSignal/onesignal-php-api#configuration) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](https://github.com/OneSignal/onesignal-php-api#full-api-reference) +[[Back to README]](https://github.com/OneSignal/onesignal-php-api) + ## `getSegments()` ```php diff --git a/docs/Model/GetSegmentSuccessResponse.md b/docs/Model/GetSegmentSuccessResponse.md new file mode 100644 index 0000000..d18e36e --- /dev/null +++ b/docs/Model/GetSegmentSuccessResponse.md @@ -0,0 +1,10 @@ +# # GetSegmentSuccessResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**subscriber_count** | **int** | The number of subscribers matching this segment. | [optional] +**payload** | [**\onesignal\client\model\SegmentDetails**](SegmentDetails.md) | | [optional] + +[[Back to API list]](https://github.com/OneSignal/onesignal-php-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-php-api) diff --git a/docs/Model/SegmentDetails.md b/docs/Model/SegmentDetails.md new file mode 100644 index 0000000..b1434f8 --- /dev/null +++ b/docs/Model/SegmentDetails.md @@ -0,0 +1,14 @@ +# # SegmentDetails + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **string** | The unique identifier for the segment (UUID v4). | [optional] +**name** | **string** | The segment name. | [optional] +**description** | **string** | Human-readable description for the segment. `null` when unset. Maximum 255 characters. | [optional] +**created_at** | **int** | Unix timestamp when the segment was created. | [optional] +**source** | **string** | The source of the segment. | [optional] +**filters** | [**\onesignal\client\model\FilterExpression[]**](FilterExpression.md) | Array of filter and operator objects defining the segment criteria. Uses the same format as the Create Segment API, so filters can be directly used to recreate or update the segment. | [optional] + +[[Back to API list]](https://github.com/OneSignal/onesignal-php-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-php-api) diff --git a/lib/api/DefaultApi.php b/lib/api/DefaultApi.php index 1795a63..0b7ad3e 100644 --- a/lib/api/DefaultApi.php +++ b/lib/api/DefaultApi.php @@ -10481,6 +10481,402 @@ public function getOutcomesRequest($app_id, $outcome_names, $outcome_names2 = nu ); } + /** + * Operation getSegment + * + * View Segment + * + * @param string $app_id The OneSignal App ID for your app. Available in Keys & IDs. (required) + * @param string $segment_id The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. (required) + * @param bool $include_segment_detail Set to true to include segment metadata and filters in the response. (optional) + * + * @throws \onesignal\client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \onesignal\client\model\GetSegmentSuccessResponse|\onesignal\client\model\GenericError|\onesignal\client\model\GenericError|\onesignal\client\model\RateLimitError|\onesignal\client\model\GenericError + */ + public function getSegment($app_id, $segment_id, $include_segment_detail = null) + { + list($response) = $this->getSegmentWithHttpInfo($app_id, $segment_id, $include_segment_detail); + return $response; + } + + /** + * Operation getSegmentWithHttpInfo + * + * View Segment + * + * @param string $app_id The OneSignal App ID for your app. Available in Keys & IDs. (required) + * @param string $segment_id The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. (required) + * @param bool $include_segment_detail Set to true to include segment metadata and filters in the response. (optional) + * + * @throws \onesignal\client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \onesignal\client\model\GetSegmentSuccessResponse|\onesignal\client\model\GenericError|\onesignal\client\model\GenericError|\onesignal\client\model\RateLimitError|\onesignal\client\model\GenericError, HTTP status code, HTTP response headers (array of strings) + */ + public function getSegmentWithHttpInfo($app_id, $segment_id, $include_segment_detail = null) + { + $request = $this->getSegmentRequest($app_id, $segment_id, $include_segment_detail); + + 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 ('\onesignal\client\model\GetSegmentSuccessResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\onesignal\client\model\GetSegmentSuccessResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\onesignal\client\model\GetSegmentSuccessResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 400: + if ('\onesignal\client\model\GenericError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\onesignal\client\model\GenericError' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\onesignal\client\model\GenericError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 404: + if ('\onesignal\client\model\GenericError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\onesignal\client\model\GenericError' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\onesignal\client\model\GenericError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 429: + if ('\onesignal\client\model\RateLimitError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\onesignal\client\model\RateLimitError' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\onesignal\client\model\RateLimitError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = '\onesignal\client\model\GetSegmentSuccessResponse'; + 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() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\onesignal\client\model\GetSegmentSuccessResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\onesignal\client\model\GenericError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\onesignal\client\model\GenericError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\onesignal\client\model\RateLimitError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + default: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\onesignal\client\model\GenericError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getSegmentAsync + * + * View Segment + * + * @param string $app_id The OneSignal App ID for your app. Available in Keys & IDs. (required) + * @param string $segment_id The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. (required) + * @param bool $include_segment_detail Set to true to include segment metadata and filters in the response. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getSegmentAsync($app_id, $segment_id, $include_segment_detail = null) + { + return $this->getSegmentAsyncWithHttpInfo($app_id, $segment_id, $include_segment_detail) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getSegmentAsyncWithHttpInfo + * + * View Segment + * + * @param string $app_id The OneSignal App ID for your app. Available in Keys & IDs. (required) + * @param string $segment_id The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. (required) + * @param bool $include_segment_detail Set to true to include segment metadata and filters in the response. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getSegmentAsyncWithHttpInfo($app_id, $segment_id, $include_segment_detail = null) + { + $returnType = '\onesignal\client\model\GetSegmentSuccessResponse'; + $request = $this->getSegmentRequest($app_id, $segment_id, $include_segment_detail); + + 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 'getSegment' + * + * @param string $app_id The OneSignal App ID for your app. Available in Keys & IDs. (required) + * @param string $segment_id The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. (required) + * @param bool $include_segment_detail Set to true to include segment metadata and filters in the response. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getSegmentRequest($app_id, $segment_id, $include_segment_detail = null) + { + // verify the required parameter 'app_id' is set + if ($app_id === null || (is_array($app_id) && count($app_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $app_id when calling getSegment' + ); + } + // verify the required parameter 'segment_id' is set + if ($segment_id === null || (is_array($segment_id) && count($segment_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $segment_id when calling getSegment' + ); + } + + $resourcePath = '/apps/{app_id}/segments/{segment_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $include_segment_detail, + 'include-segment-detail', // param base name + 'boolean', // openApiType + 'form', // style + true, // explode + false // required + ) ?? []); + + + // path params + if ($app_id !== null) { + $resourcePath = str_replace( + '{' . 'app_id' . '}', + ObjectSerializer::toPathValue($app_id), + $resourcePath + ); + } + // path params + if ($segment_id !== null) { + $resourcePath = str_replace( + '{' . 'segment_id' . '}', + ObjectSerializer::toPathValue($segment_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // 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 ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + if (!empty($this->config->getRestApiKeyToken())) { + $headers['Authorization'] = 'Key ' . $this->config->getRestApiKeyToken(); + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + // Adding the telemetry header + $defaultHeaders['OS-Usage-Data'] = 'kind=sdk, sdk-name=onesignal-php, version=5.10.0'; + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation getSegments * diff --git a/lib/model/GetSegmentSuccessResponse.php b/lib/model/GetSegmentSuccessResponse.php new file mode 100644 index 0000000..478ec26 --- /dev/null +++ b/lib/model/GetSegmentSuccessResponse.php @@ -0,0 +1,353 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class GetSegmentSuccessResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'GetSegmentSuccessResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'subscriber_count' => 'int', + 'payload' => '\onesignal\client\model\SegmentDetails' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'subscriber_count' => null, + 'payload' => null + ]; + + /** + * 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 attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'subscriber_count' => 'subscriber_count', + 'payload' => 'payload' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'subscriber_count' => 'setSubscriberCount', + 'payload' => 'setPayload' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'subscriber_count' => 'getSubscriberCount', + 'payload' => 'getPayload' + ]; + + /** + * 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->container['subscriber_count'] = $data['subscriber_count'] ?? null; + $this->container['payload'] = $data['payload'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + 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 subscriber_count + * + * @return int|null + */ + public function getSubscriberCount() + { + return $this->container['subscriber_count']; + } + + /** + * Sets subscriber_count + * + * @param int|null $subscriber_count The number of subscribers matching this segment. + * + * @return self + */ + public function setSubscriberCount($subscriber_count) + { + $this->container['subscriber_count'] = $subscriber_count; + + return $this; + } + + /** + * Gets payload + * + * @return \onesignal\client\model\SegmentDetails|null + */ + public function getPayload() + { + return $this->container['payload']; + } + + /** + * Sets payload + * + * @param \onesignal\client\model\SegmentDetails|null $payload payload + * + * @return self + */ + public function setPayload($payload) + { + $this->container['payload'] = $payload; + + 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/lib/model/SegmentDetails.php b/lib/model/SegmentDetails.php new file mode 100644 index 0000000..3b7d75c --- /dev/null +++ b/lib/model/SegmentDetails.php @@ -0,0 +1,510 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class SegmentDetails implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'SegmentDetails'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'id' => 'string', + 'name' => 'string', + 'description' => 'string', + 'created_at' => 'int', + 'source' => 'string', + 'filters' => '\onesignal\client\model\FilterExpression[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'id' => null, + 'name' => null, + 'description' => null, + 'created_at' => null, + 'source' => null, + 'filters' => null + ]; + + /** + * 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 attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'id' => 'id', + 'name' => 'name', + 'description' => 'description', + 'created_at' => 'created_at', + 'source' => 'source', + 'filters' => 'filters' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'id' => 'setId', + 'name' => 'setName', + 'description' => 'setDescription', + 'created_at' => 'setCreatedAt', + 'source' => 'setSource', + 'filters' => 'setFilters' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'id' => 'getId', + 'name' => 'getName', + 'description' => 'getDescription', + 'created_at' => 'getCreatedAt', + 'source' => 'getSource', + 'filters' => 'getFilters' + ]; + + /** + * 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; + } + + public const SOURCE__DEFAULT = 'default'; + public const SOURCE_CUSTOM = 'custom'; + public const SOURCE_QUICKSTART = 'quickstart'; + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getSourceAllowableValues() + { + return [ + self::SOURCE__DEFAULT, + self::SOURCE_CUSTOM, + self::SOURCE_QUICKSTART, + ]; + } + + /** + * 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->container['id'] = $data['id'] ?? null; + $this->container['name'] = $data['name'] ?? null; + $this->container['description'] = $data['description'] ?? null; + $this->container['created_at'] = $data['created_at'] ?? null; + $this->container['source'] = $data['source'] ?? null; + $this->container['filters'] = $data['filters'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + $allowedValues = $this->getSourceAllowableValues(); + if (!is_null($this->container['source']) && !in_array($this->container['source'], $allowedValues, true)) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'source', must be one of '%s'", + $this->container['source'], + implode("', '", $allowedValues) + ); + } + + 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 id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id The unique identifier for the segment (UUID v4). + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets name + * + * @return string|null + */ + public function getName() + { + return $this->container['name']; + } + + /** + * Sets name + * + * @param string|null $name The segment name. + * + * @return self + */ + public function setName($name) + { + $this->container['name'] = $name; + + return $this; + } + + /** + * Gets description + * + * @return string|null + */ + public function getDescription() + { + return $this->container['description']; + } + + /** + * Sets description + * + * @param string|null $description Human-readable description for the segment. `null` when unset. Maximum 255 characters. + * + * @return self + */ + public function setDescription($description) + { + $this->container['description'] = $description; + + return $this; + } + + /** + * Gets created_at + * + * @return int|null + */ + public function getCreatedAt() + { + return $this->container['created_at']; + } + + /** + * Sets created_at + * + * @param int|null $created_at Unix timestamp when the segment was created. + * + * @return self + */ + public function setCreatedAt($created_at) + { + $this->container['created_at'] = $created_at; + + return $this; + } + + /** + * Gets source + * + * @return string|null + */ + public function getSource() + { + return $this->container['source']; + } + + /** + * Sets source + * + * @param string|null $source The source of the segment. + * + * @return self + */ + public function setSource($source) + { + $allowedValues = $this->getSourceAllowableValues(); + if (!is_null($source) && !in_array($source, $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'source', must be one of '%s'", + $source, + implode("', '", $allowedValues) + ) + ); + } + $this->container['source'] = $source; + + return $this; + } + + /** + * Gets filters + * + * @return \onesignal\client\model\FilterExpression[]|null + */ + public function getFilters() + { + return $this->container['filters']; + } + + /** + * Sets filters + * + * @param \onesignal\client\model\FilterExpression[]|null $filters Array of filter and operator objects defining the segment criteria. Uses the same format as the Create Segment API, so filters can be directly used to recreate or update the segment. + * + * @return self + */ + public function setFilters($filters) + { + $this->container['filters'] = $filters; + + 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)); + } +} + +