diff --git a/generated/Api/AppIconBadgesApi.php b/generated/Api/AppIconBadgesApi.php index 5d6b240..5d05df9 100644 --- a/generated/Api/AppIconBadgesApi.php +++ b/generated/Api/AppIconBadgesApi.php @@ -125,7 +125,7 @@ public function getConfig() /** * Operation updateAppIconBadgeCount * - * Set App Icon Badge Count + * Set App Icon Badge * * @param \ActivitySmith\Generated\Model\AppIconBadgeCountUpdateRequest $appIconBadgeCountUpdateRequest appIconBadgeCountUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateAppIconBadgeCount'] to see the possible values for this operation @@ -143,7 +143,7 @@ public function updateAppIconBadgeCount($appIconBadgeCountUpdateRequest, string /** * Operation updateAppIconBadgeCountWithHttpInfo * - * Set App Icon Badge Count + * Set App Icon Badge * * @param \ActivitySmith\Generated\Model\AppIconBadgeCountUpdateRequest $appIconBadgeCountUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateAppIconBadgeCount'] to see the possible values for this operation @@ -477,7 +477,7 @@ public function updateAppIconBadgeCountWithHttpInfo($appIconBadgeCountUpdateRequ /** * Operation updateAppIconBadgeCountAsync * - * Set App Icon Badge Count + * Set App Icon Badge * * @param \ActivitySmith\Generated\Model\AppIconBadgeCountUpdateRequest $appIconBadgeCountUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateAppIconBadgeCount'] to see the possible values for this operation @@ -498,7 +498,7 @@ function ($response) { /** * Operation updateAppIconBadgeCountAsyncWithHttpInfo * - * Set App Icon Badge Count + * Set App Icon Badge * * @param \ActivitySmith\Generated\Model\AppIconBadgeCountUpdateRequest $appIconBadgeCountUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateAppIconBadgeCount'] to see the possible values for this operation diff --git a/generated/Api/MetricsApi.php b/generated/Api/MetricsApi.php index 5ece8b7..d0af67c 100644 --- a/generated/Api/MetricsApi.php +++ b/generated/Api/MetricsApi.php @@ -74,6 +74,9 @@ class MetricsApi 'updateMetricValue' => [ 'application/json', ], + 'upsertMetric' => [ + 'application/json', + ], ]; /** @@ -127,13 +130,13 @@ public function getConfig() * * Update a widget metric value * - * @param string $key Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param string $key Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) * @param \ActivitySmith\Generated\Model\MetricValueUpdateRequest $metricValueUpdateRequest metricValueUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateMetricValue'] 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\MetricValueUpdateResponse|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\RateLimitError + * @return \ActivitySmith\Generated\Model\MetricValueUpdateResponse|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\RateLimitError */ public function updateMetricValue($key, $metricValueUpdateRequest, string $contentType = self::contentTypes['updateMetricValue'][0]) { @@ -146,13 +149,13 @@ public function updateMetricValue($key, $metricValueUpdateRequest, string $conte * * Update a widget metric value * - * @param string $key Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param string $key Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) * @param \ActivitySmith\Generated\Model\MetricValueUpdateRequest $metricValueUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateMetricValue'] 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\MetricValueUpdateResponse|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\RateLimitError, HTTP status code, HTTP response headers (array of strings) + * @return array of \ActivitySmith\Generated\Model\MetricValueUpdateResponse|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\RateLimitError, HTTP status code, HTTP response headers (array of strings) */ public function updateMetricValueWithHttpInfo($key, $metricValueUpdateRequest, string $contentType = self::contentTypes['updateMetricValue'][0]) { @@ -270,6 +273,33 @@ public function updateMetricValueWithHttpInfo($key, $metricValueUpdateRequest, s } } + return [ + ObjectSerializer::deserialize($content, '\ActivitySmith\Generated\Model\MetricError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 409: + if ('\ActivitySmith\Generated\Model\MetricError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\MetricError' !== '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\MetricError', []), $response->getStatusCode(), @@ -358,6 +388,14 @@ public function updateMetricValueWithHttpInfo($key, $metricValueUpdateRequest, s ); $e->setResponseObject($data); break; + case 409: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\MetricError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; case 429: $data = ObjectSerializer::deserialize( $e->getResponseBody(), @@ -376,7 +414,7 @@ public function updateMetricValueWithHttpInfo($key, $metricValueUpdateRequest, s * * Update a widget metric value * - * @param string $key Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param string $key Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) * @param \ActivitySmith\Generated\Model\MetricValueUpdateRequest $metricValueUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateMetricValue'] to see the possible values for this operation * @@ -398,7 +436,7 @@ function ($response) { * * Update a widget metric value * - * @param string $key Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param string $key Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) * @param \ActivitySmith\Generated\Model\MetricValueUpdateRequest $metricValueUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateMetricValue'] to see the possible values for this operation * @@ -449,7 +487,7 @@ function ($exception) { /** * Create request for operation 'updateMetricValue' * - * @param string $key Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param string $key Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) * @param \ActivitySmith\Generated\Model\MetricValueUpdateRequest $metricValueUpdateRequest (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateMetricValue'] to see the possible values for this operation * @@ -566,6 +604,479 @@ public function updateMetricValueRequest($key, $metricValueUpdateRequest, string ); } + /** + * Operation upsertMetric + * + * Create or update a widget metric + * + * @param string $key Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param \ActivitySmith\Generated\Model\MetricUpsertRequest $metricUpsertRequest metricUpsertRequest (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['upsertMetric'] 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\MetricResponse|\ActivitySmith\Generated\Model\MetricResponse|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\RateLimitError + */ + public function upsertMetric($key, $metricUpsertRequest = null, string $contentType = self::contentTypes['upsertMetric'][0]) + { + list($response) = $this->upsertMetricWithHttpInfo($key, $metricUpsertRequest, $contentType); + return $response; + } + + /** + * Operation upsertMetricWithHttpInfo + * + * Create or update a widget metric + * + * @param string $key Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param \ActivitySmith\Generated\Model\MetricUpsertRequest $metricUpsertRequest (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['upsertMetric'] 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\MetricResponse|\ActivitySmith\Generated\Model\MetricResponse|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\MetricError|\ActivitySmith\Generated\Model\RateLimitError, HTTP status code, HTTP response headers (array of strings) + */ + public function upsertMetricWithHttpInfo($key, $metricUpsertRequest = null, string $contentType = self::contentTypes['upsertMetric'][0]) + { + $request = $this->upsertMetricRequest($key, $metricUpsertRequest, $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\MetricResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\MetricResponse' !== '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\MetricResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 201: + if ('\ActivitySmith\Generated\Model\MetricResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\MetricResponse' !== '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\MetricResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 400: + if ('\ActivitySmith\Generated\Model\MetricError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\MetricError' !== '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\MetricError', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 409: + if ('\ActivitySmith\Generated\Model\MetricError' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\ActivitySmith\Generated\Model\MetricError' !== '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\MetricError', []), + $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\MetricResponse'; + 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\MetricResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 201: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\MetricResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\MetricError', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 409: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\ActivitySmith\Generated\Model\MetricError', + $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 upsertMetricAsync + * + * Create or update a widget metric + * + * @param string $key Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param \ActivitySmith\Generated\Model\MetricUpsertRequest $metricUpsertRequest (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['upsertMetric'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function upsertMetricAsync($key, $metricUpsertRequest = null, string $contentType = self::contentTypes['upsertMetric'][0]) + { + return $this->upsertMetricAsyncWithHttpInfo($key, $metricUpsertRequest, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation upsertMetricAsyncWithHttpInfo + * + * Create or update a widget metric + * + * @param string $key Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param \ActivitySmith\Generated\Model\MetricUpsertRequest $metricUpsertRequest (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['upsertMetric'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function upsertMetricAsyncWithHttpInfo($key, $metricUpsertRequest = null, string $contentType = self::contentTypes['upsertMetric'][0]) + { + $returnType = '\ActivitySmith\Generated\Model\MetricResponse'; + $request = $this->upsertMetricRequest($key, $metricUpsertRequest, $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 'upsertMetric' + * + * @param string $key Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. (required) + * @param \ActivitySmith\Generated\Model\MetricUpsertRequest $metricUpsertRequest (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['upsertMetric'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function upsertMetricRequest($key, $metricUpsertRequest = null, string $contentType = self::contentTypes['upsertMetric'][0]) + { + + // verify the required parameter 'key' is set + if ($key === null || (is_array($key) && count($key) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $key when calling upsertMetric' + ); + } + if (strlen($key) > 64) { + throw new \InvalidArgumentException('invalid length for "$key" when calling MetricsApi.upsertMetric, must be smaller than or equal to 64.'); + } + if (strlen($key) < 1) { + throw new \InvalidArgumentException('invalid length for "$key" when calling MetricsApi.upsertMetric, must be bigger than or equal to 1.'); + } + if (!preg_match("/^[a-z0-9][a-z0-9_.-]{0,63}$/", $key)) { + throw new \InvalidArgumentException("invalid value for \"key\" when calling MetricsApi.upsertMetric, must conform to the pattern /^[a-z0-9][a-z0-9_.-]{0,63}$/."); + } + + + + $resourcePath = '/metrics/{key}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($key !== null) { + $resourcePath = str_replace( + '{' . 'key' . '}', + ObjectSerializer::toPathValue($key), + $resourcePath + ); + } + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($metricUpsertRequest)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($metricUpsertRequest)); + } else { + $httpBody = $metricUpsertRequest; + } + } elseif (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( + 'PUT', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Create http client option * diff --git a/generated/Model/AppIconBadgeCountUpdateResponse.php b/generated/Model/AppIconBadgeCountUpdateResponse.php index 022db8d..030daee 100644 --- a/generated/Model/AppIconBadgeCountUpdateResponse.php +++ b/generated/Model/AppIconBadgeCountUpdateResponse.php @@ -460,7 +460,7 @@ public function getDevicesUpdated() /** * Sets devicesUpdated * - * @param int $devicesUpdated Number of devices whose App Icon Badge Count was updated. + * @param int $devicesUpdated Number of devices whose App Icon Badge was updated. * * @return self */ diff --git a/generated/Model/Metric.php b/generated/Model/Metric.php new file mode 100644 index 0000000..67ab146 --- /dev/null +++ b/generated/Model/Metric.php @@ -0,0 +1,884 @@ + + */ +class Metric implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'Metric'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'publicId' => 'string', + 'key' => 'string', + 'label' => 'string', + 'format' => 'string', + 'currencyCode' => 'string', + 'unit' => 'string', + 'unitSpacing' => 'string', + 'latestValue' => 'mixed', + 'latestValueAt' => '\DateTime', + '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 = [ + 'publicId' => null, + 'key' => null, + 'label' => null, + 'format' => null, + 'currencyCode' => null, + 'unit' => null, + 'unitSpacing' => null, + 'latestValue' => null, + 'latestValueAt' => 'date-time', + 'createdAt' => 'date-time', + 'updatedAt' => 'date-time' + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'publicId' => false, + 'key' => false, + 'label' => false, + 'format' => false, + 'currencyCode' => true, + 'unit' => true, + 'unitSpacing' => false, + 'latestValue' => true, + 'latestValueAt' => true, + 'createdAt' => false, + 'updatedAt' => 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 = [ + 'publicId' => 'public_id', + 'key' => 'key', + 'label' => 'label', + 'format' => 'format', + 'currencyCode' => 'currency_code', + 'unit' => 'unit', + 'unitSpacing' => 'unit_spacing', + 'latestValue' => 'latest_value', + 'latestValueAt' => 'latest_value_at', + 'createdAt' => 'created_at', + 'updatedAt' => 'updated_at' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'publicId' => 'setPublicId', + 'key' => 'setKey', + 'label' => 'setLabel', + 'format' => 'setFormat', + 'currencyCode' => 'setCurrencyCode', + 'unit' => 'setUnit', + 'unitSpacing' => 'setUnitSpacing', + 'latestValue' => 'setLatestValue', + 'latestValueAt' => 'setLatestValueAt', + 'createdAt' => 'setCreatedAt', + 'updatedAt' => 'setUpdatedAt' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'publicId' => 'getPublicId', + 'key' => 'getKey', + 'label' => 'getLabel', + 'format' => 'getFormat', + 'currencyCode' => 'getCurrencyCode', + 'unit' => 'getUnit', + 'unitSpacing' => 'getUnitSpacing', + 'latestValue' => 'getLatestValue', + 'latestValueAt' => 'getLatestValueAt', + '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; + } + + public const FORMAT_NUMBER = 'number'; + public const FORMAT_CURRENCY = 'currency'; + public const FORMAT_PERCENT = 'percent'; + public const FORMAT_UNIT = 'unit'; + public const FORMAT_STRING = 'string'; + public const UNIT_SPACING_NONE = 'none'; + public const UNIT_SPACING_SPACE = 'space'; + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getFormatAllowableValues() + { + return [ + self::FORMAT_NUMBER, + self::FORMAT_CURRENCY, + self::FORMAT_PERCENT, + self::FORMAT_UNIT, + self::FORMAT_STRING, + ]; + } + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getUnitSpacingAllowableValues() + { + return [ + self::UNIT_SPACING_NONE, + self::UNIT_SPACING_SPACE, + ]; + } + + /** + * 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('publicId', $data ?? [], null); + $this->setIfExists('key', $data ?? [], null); + $this->setIfExists('label', $data ?? [], null); + $this->setIfExists('format', $data ?? [], null); + $this->setIfExists('currencyCode', $data ?? [], null); + $this->setIfExists('unit', $data ?? [], null); + $this->setIfExists('unitSpacing', $data ?? [], null); + $this->setIfExists('latestValue', $data ?? [], null); + $this->setIfExists('latestValueAt', $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['publicId'] === null) { + $invalidProperties[] = "'publicId' can't be null"; + } + if ($this->container['key'] === null) { + $invalidProperties[] = "'key' can't be null"; + } + if ($this->container['label'] === null) { + $invalidProperties[] = "'label' can't be null"; + } + if ($this->container['format'] === null) { + $invalidProperties[] = "'format' can't be null"; + } + $allowedValues = $this->getFormatAllowableValues(); + if (!is_null($this->container['format']) && !in_array($this->container['format'], $allowedValues, true)) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'format', must be one of '%s'", + $this->container['format'], + implode("', '", $allowedValues) + ); + } + + if ($this->container['currencyCode'] === null) { + $invalidProperties[] = "'currencyCode' can't be null"; + } + if ($this->container['unit'] === null) { + $invalidProperties[] = "'unit' can't be null"; + } + if ($this->container['unitSpacing'] === null) { + $invalidProperties[] = "'unitSpacing' can't be null"; + } + $allowedValues = $this->getUnitSpacingAllowableValues(); + if (!is_null($this->container['unitSpacing']) && !in_array($this->container['unitSpacing'], $allowedValues, true)) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'unitSpacing', must be one of '%s'", + $this->container['unitSpacing'], + implode("', '", $allowedValues) + ); + } + + if ($this->container['latestValue'] === null) { + $invalidProperties[] = "'latestValue' can't be null"; + } + if ($this->container['latestValueAt'] === null) { + $invalidProperties[] = "'latestValueAt' 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 publicId + * + * @return string + */ + public function getPublicId() + { + return $this->container['publicId']; + } + + /** + * Sets publicId + * + * @param string $publicId publicId + * + * @return self + */ + public function setPublicId($publicId) + { + if (is_null($publicId)) { + throw new \InvalidArgumentException('non-nullable publicId cannot be null'); + } + $this->container['publicId'] = $publicId; + + return $this; + } + + /** + * Gets key + * + * @return string + */ + public function getKey() + { + return $this->container['key']; + } + + /** + * Sets key + * + * @param string $key key + * + * @return self + */ + public function setKey($key) + { + if (is_null($key)) { + throw new \InvalidArgumentException('non-nullable key cannot be null'); + } + $this->container['key'] = $key; + + return $this; + } + + /** + * Gets label + * + * @return string + */ + public function getLabel() + { + return $this->container['label']; + } + + /** + * Sets label + * + * @param string $label label + * + * @return self + */ + public function setLabel($label) + { + if (is_null($label)) { + throw new \InvalidArgumentException('non-nullable label cannot be null'); + } + $this->container['label'] = $label; + + return $this; + } + + /** + * Gets format + * + * @return string + */ + public function getFormat() + { + return $this->container['format']; + } + + /** + * Sets format + * + * @param string $format format + * + * @return self + */ + public function setFormat($format) + { + if (is_null($format)) { + throw new \InvalidArgumentException('non-nullable format cannot be null'); + } + $allowedValues = $this->getFormatAllowableValues(); + if (!in_array($format, $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'format', must be one of '%s'", + $format, + implode("', '", $allowedValues) + ) + ); + } + $this->container['format'] = $format; + + return $this; + } + + /** + * Gets currencyCode + * + * @return string + */ + public function getCurrencyCode() + { + return $this->container['currencyCode']; + } + + /** + * Sets currencyCode + * + * @param string $currencyCode currencyCode + * + * @return self + */ + public function setCurrencyCode($currencyCode) + { + if (is_null($currencyCode)) { + array_push($this->openAPINullablesSetToNull, 'currencyCode'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('currencyCode', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['currencyCode'] = $currencyCode; + + return $this; + } + + /** + * Gets unit + * + * @return string + */ + public function getUnit() + { + return $this->container['unit']; + } + + /** + * Sets unit + * + * @param string $unit unit + * + * @return self + */ + public function setUnit($unit) + { + if (is_null($unit)) { + array_push($this->openAPINullablesSetToNull, 'unit'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('unit', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['unit'] = $unit; + + return $this; + } + + /** + * Gets unitSpacing + * + * @return string + */ + public function getUnitSpacing() + { + return $this->container['unitSpacing']; + } + + /** + * Sets unitSpacing + * + * @param string $unitSpacing unitSpacing + * + * @return self + */ + public function setUnitSpacing($unitSpacing) + { + if (is_null($unitSpacing)) { + throw new \InvalidArgumentException('non-nullable unitSpacing cannot be null'); + } + $allowedValues = $this->getUnitSpacingAllowableValues(); + if (!in_array($unitSpacing, $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'unitSpacing', must be one of '%s'", + $unitSpacing, + implode("', '", $allowedValues) + ) + ); + } + $this->container['unitSpacing'] = $unitSpacing; + + return $this; + } + + /** + * Gets latestValue + * + * @return mixed + */ + public function getLatestValue() + { + return $this->container['latestValue']; + } + + /** + * Sets latestValue + * + * @param mixed $latestValue latestValue + * + * @return self + */ + public function setLatestValue($latestValue) + { + if (is_null($latestValue)) { + array_push($this->openAPINullablesSetToNull, 'latestValue'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('latestValue', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['latestValue'] = $latestValue; + + return $this; + } + + /** + * Gets latestValueAt + * + * @return \DateTime + */ + public function getLatestValueAt() + { + return $this->container['latestValueAt']; + } + + /** + * Sets latestValueAt + * + * @param \DateTime $latestValueAt latestValueAt + * + * @return self + */ + public function setLatestValueAt($latestValueAt) + { + if (is_null($latestValueAt)) { + array_push($this->openAPINullablesSetToNull, 'latestValueAt'); + } else { + $nullablesSetToNull = $this->getOpenAPINullablesSetToNull(); + $index = array_search('latestValueAt', $nullablesSetToNull); + if ($index !== FALSE) { + unset($nullablesSetToNull[$index]); + $this->setOpenAPINullablesSetToNull($nullablesSetToNull); + } + } + $this->container['latestValueAt'] = $latestValueAt; + + return $this; + } + + /** + * Gets createdAt + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->container['createdAt']; + } + + /** + * Sets createdAt + * + * @param \DateTime $createdAt createdAt + * + * @return self + */ + public function setCreatedAt($createdAt) + { + if (is_null($createdAt)) { + throw new \InvalidArgumentException('non-nullable createdAt cannot be null'); + } + $this->container['createdAt'] = $createdAt; + + return $this; + } + + /** + * Gets updatedAt + * + * @return \DateTime + */ + public function getUpdatedAt() + { + return $this->container['updatedAt']; + } + + /** + * Sets updatedAt + * + * @param \DateTime $updatedAt updatedAt + * + * @return self + */ + public function setUpdatedAt($updatedAt) + { + if (is_null($updatedAt)) { + throw new \InvalidArgumentException('non-nullable updatedAt cannot be null'); + } + $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/MetricResponse.php b/generated/Model/MetricResponse.php new file mode 100644 index 0000000..d57d7f6 --- /dev/null +++ b/generated/Model/MetricResponse.php @@ -0,0 +1,412 @@ + + */ +class MetricResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'MetricResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'metric' => '\ActivitySmith\Generated\Model\Metric' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'metric' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'metric' => 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 = [ + 'metric' => 'metric' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'metric' => 'setMetric' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'metric' => 'getMetric' + ]; + + /** + * 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('metric', $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['metric'] === null) { + $invalidProperties[] = "'metric' 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 metric + * + * @return \ActivitySmith\Generated\Model\Metric + */ + public function getMetric() + { + return $this->container['metric']; + } + + /** + * Sets metric + * + * @param \ActivitySmith\Generated\Model\Metric $metric metric + * + * @return self + */ + public function setMetric($metric) + { + if (is_null($metric)) { + throw new \InvalidArgumentException('non-nullable metric cannot be null'); + } + $this->container['metric'] = $metric; + + 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/MetricUpsertRequest.php b/generated/Model/MetricUpsertRequest.php new file mode 100644 index 0000000..7bcea52 --- /dev/null +++ b/generated/Model/MetricUpsertRequest.php @@ -0,0 +1,652 @@ + + */ +class MetricUpsertRequest implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'MetricUpsertRequest'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'label' => 'string', + 'format' => 'string', + 'currencyCode' => 'string', + 'unit' => 'string', + 'unitSpacing' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'label' => null, + 'format' => null, + 'currencyCode' => null, + 'unit' => null, + 'unitSpacing' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'label' => false, + 'format' => false, + 'currencyCode' => false, + 'unit' => false, + 'unitSpacing' => 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 = [ + 'label' => 'label', + 'format' => 'format', + 'currencyCode' => 'currency_code', + 'unit' => 'unit', + 'unitSpacing' => 'unit_spacing' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'label' => 'setLabel', + 'format' => 'setFormat', + 'currencyCode' => 'setCurrencyCode', + 'unit' => 'setUnit', + 'unitSpacing' => 'setUnitSpacing' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'label' => 'getLabel', + 'format' => 'getFormat', + 'currencyCode' => 'getCurrencyCode', + 'unit' => 'getUnit', + 'unitSpacing' => 'getUnitSpacing' + ]; + + /** + * 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 FORMAT_NUMBER = 'number'; + public const FORMAT_CURRENCY = 'currency'; + public const FORMAT_PERCENT = 'percent'; + public const FORMAT_UNIT = 'unit'; + public const FORMAT_STRING = 'string'; + public const UNIT_SPACING_NONE = 'none'; + public const UNIT_SPACING_SPACE = 'space'; + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getFormatAllowableValues() + { + return [ + self::FORMAT_NUMBER, + self::FORMAT_CURRENCY, + self::FORMAT_PERCENT, + self::FORMAT_UNIT, + self::FORMAT_STRING, + ]; + } + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getUnitSpacingAllowableValues() + { + return [ + self::UNIT_SPACING_NONE, + self::UNIT_SPACING_SPACE, + ]; + } + + /** + * 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('label', $data ?? [], null); + $this->setIfExists('format', $data ?? [], null); + $this->setIfExists('currencyCode', $data ?? [], null); + $this->setIfExists('unit', $data ?? [], null); + $this->setIfExists('unitSpacing', $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 (!is_null($this->container['label']) && (mb_strlen($this->container['label']) > 80)) { + $invalidProperties[] = "invalid value for 'label', the character length must be smaller than or equal to 80."; + } + + if (!is_null($this->container['label']) && (mb_strlen($this->container['label']) < 1)) { + $invalidProperties[] = "invalid value for 'label', the character length must be bigger than or equal to 1."; + } + + $allowedValues = $this->getFormatAllowableValues(); + if (!is_null($this->container['format']) && !in_array($this->container['format'], $allowedValues, true)) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'format', must be one of '%s'", + $this->container['format'], + implode("', '", $allowedValues) + ); + } + + if (!is_null($this->container['currencyCode']) && !preg_match("/^[A-Za-z]{3}$/", $this->container['currencyCode'])) { + $invalidProperties[] = "invalid value for 'currencyCode', must be conform to the pattern /^[A-Za-z]{3}$/."; + } + + if (!is_null($this->container['unit']) && (mb_strlen($this->container['unit']) > 16)) { + $invalidProperties[] = "invalid value for 'unit', the character length must be smaller than or equal to 16."; + } + + $allowedValues = $this->getUnitSpacingAllowableValues(); + if (!is_null($this->container['unitSpacing']) && !in_array($this->container['unitSpacing'], $allowedValues, true)) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'unitSpacing', must be one of '%s'", + $this->container['unitSpacing'], + 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 label + * + * @return string|null + */ + public function getLabel() + { + return $this->container['label']; + } + + /** + * Sets label + * + * @param string|null $label Name shown on the widget. + * + * @return self + */ + public function setLabel($label) + { + if (is_null($label)) { + throw new \InvalidArgumentException('non-nullable label cannot be null'); + } + if ((mb_strlen($label) > 80)) { + throw new \InvalidArgumentException('invalid length for $label when calling MetricUpsertRequest., must be smaller than or equal to 80.'); + } + if ((mb_strlen($label) < 1)) { + throw new \InvalidArgumentException('invalid length for $label when calling MetricUpsertRequest., must be bigger than or equal to 1.'); + } + + $this->container['label'] = $label; + + return $this; + } + + /** + * Gets format + * + * @return string|null + */ + public function getFormat() + { + return $this->container['format']; + } + + /** + * Sets format + * + * @param string|null $format How widgets display the value: number (1,234), currency (requires currency_code), percent (send 99.9 to show 99.9%), unit (a number with a unit suffix, such as 120 ms), or string (text up to 64 characters). Defaults to number for a new metric. + * + * @return self + */ + public function setFormat($format) + { + if (is_null($format)) { + throw new \InvalidArgumentException('non-nullable format cannot be null'); + } + $allowedValues = $this->getFormatAllowableValues(); + if (!in_array($format, $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'format', must be one of '%s'", + $format, + implode("', '", $allowedValues) + ) + ); + } + $this->container['format'] = $format; + + return $this; + } + + /** + * Gets currencyCode + * + * @return string|null + */ + public function getCurrencyCode() + { + return $this->container['currencyCode']; + } + + /** + * Sets currencyCode + * + * @param string|null $currencyCode 3-letter ISO 4217 currency code, such as USD. Required for the currency format. + * + * @return self + */ + public function setCurrencyCode($currencyCode) + { + if (is_null($currencyCode)) { + throw new \InvalidArgumentException('non-nullable currencyCode cannot be null'); + } + + if ((!preg_match("/^[A-Za-z]{3}$/", ObjectSerializer::toString($currencyCode)))) { + throw new \InvalidArgumentException("invalid value for \$currencyCode when calling MetricUpsertRequest., must conform to the pattern /^[A-Za-z]{3}$/."); + } + + $this->container['currencyCode'] = $currencyCode; + + return $this; + } + + /** + * Gets unit + * + * @return string|null + */ + public function getUnit() + { + return $this->container['unit']; + } + + /** + * Sets unit + * + * @param string|null $unit Unit suffix for the unit format, such as ms or GB. + * + * @return self + */ + public function setUnit($unit) + { + if (is_null($unit)) { + throw new \InvalidArgumentException('non-nullable unit cannot be null'); + } + if ((mb_strlen($unit) > 16)) { + throw new \InvalidArgumentException('invalid length for $unit when calling MetricUpsertRequest., must be smaller than or equal to 16.'); + } + + $this->container['unit'] = $unit; + + return $this; + } + + /** + * Gets unitSpacing + * + * @return string|null + */ + public function getUnitSpacing() + { + return $this->container['unitSpacing']; + } + + /** + * Sets unitSpacing + * + * @param string|null $unitSpacing For the unit format: none shows 120ms, space shows 120 ms. + * + * @return self + */ + public function setUnitSpacing($unitSpacing) + { + if (is_null($unitSpacing)) { + throw new \InvalidArgumentException('non-nullable unitSpacing cannot be null'); + } + $allowedValues = $this->getUnitSpacingAllowableValues(); + if (!in_array($unitSpacing, $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'unitSpacing', must be one of '%s'", + $unitSpacing, + implode("', '", $allowedValues) + ) + ); + } + $this->container['unitSpacing'] = $unitSpacing; + + 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/MetricValueUpdateResponse.php b/generated/Model/MetricValueUpdateResponse.php index dd6bfba..cfe17d0 100644 --- a/generated/Model/MetricValueUpdateResponse.php +++ b/generated/Model/MetricValueUpdateResponse.php @@ -57,7 +57,8 @@ class MetricValueUpdateResponse implements ModelInterface, ArrayAccess, \JsonSer * @var string[] */ protected static $openAPITypes = [ - 'success' => 'bool' + 'success' => 'bool', + 'created' => 'bool' ]; /** @@ -68,7 +69,8 @@ class MetricValueUpdateResponse implements ModelInterface, ArrayAccess, \JsonSer * @psalm-var array */ protected static $openAPIFormats = [ - 'success' => null + 'success' => null, + 'created' => null ]; /** @@ -77,7 +79,8 @@ class MetricValueUpdateResponse implements ModelInterface, ArrayAccess, \JsonSer * @var boolean[] */ protected static array $openAPINullables = [ - 'success' => false + 'success' => false, + 'created' => false ]; /** @@ -166,7 +169,8 @@ public function isNullableSetToNull(string $property): bool * @var string[] */ protected static $attributeMap = [ - 'success' => 'success' + 'success' => 'success', + 'created' => 'created' ]; /** @@ -175,7 +179,8 @@ public function isNullableSetToNull(string $property): bool * @var string[] */ protected static $setters = [ - 'success' => 'setSuccess' + 'success' => 'setSuccess', + 'created' => 'setCreated' ]; /** @@ -184,7 +189,8 @@ public function isNullableSetToNull(string $property): bool * @var string[] */ protected static $getters = [ - 'success' => 'getSuccess' + 'success' => 'getSuccess', + 'created' => 'getCreated' ]; /** @@ -245,6 +251,7 @@ public function getModelName() public function __construct(array $data = null) { $this->setIfExists('success', $data ?? [], null); + $this->setIfExists('created', $data ?? [], null); } /** @@ -318,6 +325,33 @@ public function setSuccess($success) return $this; } + + /** + * Gets created + * + * @return bool|null + */ + public function getCreated() + { + return $this->container['created']; + } + + /** + * Sets created + * + * @param bool|null $created true when this request created the metric because no metric used the key yet. + * + * @return self + */ + public function setCreated($created) + { + if (is_null($created)) { + throw new \InvalidArgumentException('non-nullable created cannot be null'); + } + $this->container['created'] = $created; + + return $this; + } /** * Returns true if offset exists. False otherwise. * diff --git a/generated/openapi-source.json b/generated/openapi-source.json index 8c9c874..498433c 100644 --- a/generated/openapi-source.json +++ b/generated/openapi-source.json @@ -1,6 +1,6 @@ { "repository": "ActivitySmithHQ/activitysmith-backend", - "commit": "ab7064d65ad2097e3b57dc435c10b4f80a0ee27e", + "commit": "7bf9c3d88459fe3f122810979a45da0a1e6fd2d6", "path": "openapi.json", - "sha256": "f0548e423e06f90169dae8d935b08f78291e9dbf95d4ae591e6d10d8eb269448" + "sha256": "6987f90b106e28a0ab8058f43309e7a9f045c7c54d27ce90bbdd5966c3f99f7a" } diff --git a/src/Metrics.php b/src/Metrics.php index f0b6e50..1c45d0f 100644 --- a/src/Metrics.php +++ b/src/Metrics.php @@ -21,7 +21,48 @@ public function update(mixed $key, mixed $valueOrRequest, mixed $timestamp = nul ); } - // Backward-compatible generated-style alias. + /** + * Creates the metric, or updates the fields sent for an existing one. + * Omitted fields keep their current values, so it is safe to call on every start. + */ + public function create( + string $key, + mixed $definition = null, + ?string $label = null, + ?string $format = null, + ?string $currencyCode = null, + ?string $unit = null, + ?string $unitSpacing = null + ): mixed { + $request = $definition; + $fields = array_filter([ + 'label' => $label, + 'format' => $format, + 'currency_code' => $currencyCode, + 'unit' => $unit, + 'unit_spacing' => $unitSpacing, + ], static fn (mixed $value): bool => $value !== null); + + if ($fields !== []) { + $request = [...(is_array($definition) ? $definition : []), ...$fields]; + } + + return $this->api->upsertMetric( + $key, + $request === [] ? null : $request, + MetricsApi::contentTypes['upsertMetric'][0] + ); + } + + // Backward-compatible generated-style aliases. + public function upsertMetric( + mixed $key, + mixed $metricUpsertRequest = null, + string $contentType = MetricsApi::contentTypes['upsertMetric'][0] + ): mixed { + return $this->api->upsertMetric($key, $metricUpsertRequest, $contentType); + } + public function updateMetricValue( mixed $key, mixed $metricValueUpdateRequest, diff --git a/tests/MetricsTest.php b/tests/MetricsTest.php new file mode 100644 index 0000000..f0bc593 --- /dev/null +++ b/tests/MetricsTest.php @@ -0,0 +1,76 @@ + 'MRR', 'format' => 'currency', 'currency_code' => 'USD']; + + foreach (['named', 'array', 'alias'] as $form) { + $history = []; + $stack = HandlerStack::create(new MockHandler([new Response(201, ['Content-Type' => 'application/json'], self::METRIC_RESPONSE)])); + $stack->push(Middleware::history($history)); + $metrics = new Metrics(new MetricsApi(new Client(['handler' => $stack]))); + + if ($form === 'named') { + $response = $metrics->create('mrr', label: 'MRR', format: 'currency', currencyCode: 'USD'); + } elseif ($form === 'array') { + $response = $metrics->create('mrr', $expected); + } else { + $response = $metrics->upsertMetric('mrr', $expected); + } + + $request = $history[0]['request']; + $this->assertSame('PUT', $request->getMethod()); + $this->assertStringEndsWith('/metrics/mrr', $request->getUri()->getPath()); + $this->assertEquals($expected, json_decode((string) $request->getBody(), true)); + $this->assertSame('USD', $response->getMetric()->getCurrencyCode()); + $this->assertNull($response->getMetric()->getUnit()); + } + } + + public function testCreateWithDefaultsSendsNoDefinition(): void + { + $history = []; + $stack = HandlerStack::create(new MockHandler([new Response(201, ['Content-Type' => 'application/json'], self::METRIC_RESPONSE)])); + $stack->push(Middleware::history($history)); + $metrics = new Metrics(new MetricsApi(new Client(['handler' => $stack]))); + + $metrics->create('deploy.success_rate'); + + $request = $history[0]['request']; + $this->assertSame('PUT', $request->getMethod()); + $this->assertStringEndsWith('/metrics/deploy.success_rate', $request->getUri()->getPath()); + $this->assertSame('', (string) $request->getBody()); + } + + public function testCreateMergesNamedFieldsOverArray(): void + { + $history = []; + $stack = HandlerStack::create(new MockHandler([new Response(200, ['Content-Type' => 'application/json'], self::METRIC_RESPONSE)])); + $stack->push(Middleware::history($history)); + $metrics = new Metrics(new MetricsApi(new Client(['handler' => $stack]))); + + $metrics->create('latency', ['format' => 'unit', 'unit' => 'ms'], unitSpacing: 'space'); + + $this->assertEquals( + ['format' => 'unit', 'unit' => 'ms', 'unit_spacing' => 'space'], + json_decode((string) $history[0]['request']->getBody(), true) + ); + } +}