diff --git a/AdvisoryNotifications/metadata/V1/Service.php b/AdvisoryNotifications/metadata/V1/Service.php index bd8b37ee4588..1b9b2b5507e0 100644 Binary files a/AdvisoryNotifications/metadata/V1/Service.php and b/AdvisoryNotifications/metadata/V1/Service.php differ diff --git a/AdvisoryNotifications/samples/V1/AdvisoryNotificationsServiceClient/get_settings.php b/AdvisoryNotifications/samples/V1/AdvisoryNotificationsServiceClient/get_settings.php new file mode 100644 index 000000000000..a73cd9812f06 --- /dev/null +++ b/AdvisoryNotifications/samples/V1/AdvisoryNotificationsServiceClient/get_settings.php @@ -0,0 +1,73 @@ +setName($formattedName); + + // Call the API and handle any network failures. + try { + /** @var Settings $response */ + $response = $advisoryNotificationsServiceClient->getSettings($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedName = AdvisoryNotificationsServiceClient::settingsName('[ORGANIZATION]', '[LOCATION]'); + + get_settings_sample($formattedName); +} +// [END advisorynotifications_v1_generated_AdvisoryNotificationsService_GetSettings_sync] diff --git a/AdvisoryNotifications/samples/V1/AdvisoryNotificationsServiceClient/update_settings.php b/AdvisoryNotifications/samples/V1/AdvisoryNotificationsServiceClient/update_settings.php new file mode 100644 index 000000000000..0367ac99f11f --- /dev/null +++ b/AdvisoryNotifications/samples/V1/AdvisoryNotificationsServiceClient/update_settings.php @@ -0,0 +1,77 @@ +setNotificationSettings($settingsNotificationSettings) + ->setEtag($settingsEtag); + $request = (new UpdateSettingsRequest()) + ->setSettings($settings); + + // Call the API and handle any network failures. + try { + /** @var Settings $response */ + $response = $advisoryNotificationsServiceClient->updateSettings($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $settingsEtag = '[ETAG]'; + + update_settings_sample($settingsEtag); +} +// [END advisorynotifications_v1_generated_AdvisoryNotificationsService_UpdateSettings_sync] diff --git a/AdvisoryNotifications/src/V1/Client/BaseClient/AdvisoryNotificationsServiceBaseClient.php b/AdvisoryNotifications/src/V1/Client/BaseClient/AdvisoryNotificationsServiceBaseClient.php index a3bc677620c9..0a0537d384f8 100644 --- a/AdvisoryNotifications/src/V1/Client/BaseClient/AdvisoryNotificationsServiceBaseClient.php +++ b/AdvisoryNotifications/src/V1/Client/BaseClient/AdvisoryNotificationsServiceBaseClient.php @@ -34,8 +34,11 @@ use Google\ApiCore\ValidationException; use Google\Auth\FetchAuthTokenInterface; use Google\Cloud\AdvisoryNotifications\V1\GetNotificationRequest; +use Google\Cloud\AdvisoryNotifications\V1\GetSettingsRequest; use Google\Cloud\AdvisoryNotifications\V1\ListNotificationsRequest; use Google\Cloud\AdvisoryNotifications\V1\Notification; +use Google\Cloud\AdvisoryNotifications\V1\Settings; +use Google\Cloud\AdvisoryNotifications\V1\UpdateSettingsRequest; use GuzzleHttp\Promise\PromiseInterface; /** @@ -58,7 +61,9 @@ * @internal * * @method PromiseInterface getNotificationAsync(GetNotificationRequest $request, array $optionalArgs = []) + * @method PromiseInterface getSettingsAsync(GetSettingsRequest $request, array $optionalArgs = []) * @method PromiseInterface listNotificationsAsync(ListNotificationsRequest $request, array $optionalArgs = []) + * @method PromiseInterface updateSettingsAsync(UpdateSettingsRequest $request, array $optionalArgs = []) */ abstract class AdvisoryNotificationsServiceBaseClient { @@ -137,12 +142,30 @@ public static function notificationName(string $organization, string $location, ]); } + /** + * Formats a string containing the fully-qualified path to represent a settings + * resource. + * + * @param string $organization + * @param string $location + * + * @return string The formatted settings resource. + */ + public static function settingsName(string $organization, string $location): string + { + return self::getPathTemplate('settings')->render([ + 'organization' => $organization, + 'location' => $location, + ]); + } + /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: * Template: Pattern * - location: organizations/{organization}/locations/{location} * - notification: organizations/{organization}/locations/{location}/notifications/{notification} + * - settings: organizations/{organization}/locations/{location}/settings * * The optional $template argument can be supplied to specify a particular pattern, * and must match one of the templates listed above. If no $template argument is @@ -259,6 +282,32 @@ public function getNotification(GetNotificationRequest $request, array $callOpti return $this->startApiCall('GetNotification', $request, $callOptions)->wait(); } + /** + * Get notification settings. + * + * The async variant is {@see self::getSettingsAsync()} . + * + * @example samples/V1/AdvisoryNotificationsServiceClient/get_settings.php + * + * @param GetSettingsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Settings + * + * @throws ApiException Thrown if the API call fails. + */ + public function getSettings(GetSettingsRequest $request, array $callOptions = []): Settings + { + return $this->startApiCall('GetSettings', $request, $callOptions)->wait(); + } + /** * Lists notifications under a given parent. * @@ -284,4 +333,30 @@ public function listNotifications(ListNotificationsRequest $request, array $call { return $this->startApiCall('ListNotifications', $request, $callOptions); } + + /** + * Update notification settings. + * + * The async variant is {@see self::updateSettingsAsync()} . + * + * @example samples/V1/AdvisoryNotificationsServiceClient/update_settings.php + * + * @param UpdateSettingsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Settings + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateSettings(UpdateSettingsRequest $request, array $callOptions = []): Settings + { + return $this->startApiCall('UpdateSettings', $request, $callOptions)->wait(); + } } diff --git a/AdvisoryNotifications/src/V1/Gapic/AdvisoryNotificationsServiceGapicClient.php b/AdvisoryNotifications/src/V1/Gapic/AdvisoryNotificationsServiceGapicClient.php index cc22e31a4320..18559a7e9493 100644 --- a/AdvisoryNotifications/src/V1/Gapic/AdvisoryNotificationsServiceGapicClient.php +++ b/AdvisoryNotifications/src/V1/Gapic/AdvisoryNotificationsServiceGapicClient.php @@ -34,9 +34,12 @@ use Google\ApiCore\ValidationException; use Google\Auth\FetchAuthTokenInterface; use Google\Cloud\AdvisoryNotifications\V1\GetNotificationRequest; +use Google\Cloud\AdvisoryNotifications\V1\GetSettingsRequest; use Google\Cloud\AdvisoryNotifications\V1\ListNotificationsRequest; use Google\Cloud\AdvisoryNotifications\V1\ListNotificationsResponse; use Google\Cloud\AdvisoryNotifications\V1\Notification; +use Google\Cloud\AdvisoryNotifications\V1\Settings; +use Google\Cloud\AdvisoryNotifications\V1\UpdateSettingsRequest; /** * Service Description: Service to manage Security and Privacy Notifications. @@ -88,6 +91,8 @@ class AdvisoryNotificationsServiceGapicClient private static $notificationNameTemplate; + private static $settingsNameTemplate; + private static $pathTemplateMap; private static function getClientDefaults() @@ -140,12 +145,24 @@ private static function getNotificationNameTemplate() return self::$notificationNameTemplate; } + private static function getSettingsNameTemplate() + { + if (self::$settingsNameTemplate == null) { + self::$settingsNameTemplate = new PathTemplate( + 'organizations/{organization}/locations/{location}/settings' + ); + } + + return self::$settingsNameTemplate; + } + private static function getPathTemplateMap() { if (self::$pathTemplateMap == null) { self::$pathTemplateMap = [ 'location' => self::getLocationNameTemplate(), 'notification' => self::getNotificationNameTemplate(), + 'settings' => self::getSettingsNameTemplate(), ]; } @@ -191,12 +208,30 @@ public static function notificationName( ]); } + /** + * Formats a string containing the fully-qualified path to represent a settings + * resource. + * + * @param string $organization + * @param string $location + * + * @return string The formatted settings resource. + */ + public static function settingsName($organization, $location) + { + return self::getSettingsNameTemplate()->render([ + 'organization' => $organization, + 'location' => $location, + ]); + } + /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: * Template: Pattern * - location: organizations/{organization}/locations/{location} * - notification: organizations/{organization}/locations/{location}/notifications/{notification} + * - settings: organizations/{organization}/locations/{location}/settings * * The optional $template argument can be supplied to specify a particular pattern, * and must match one of the templates listed above. If no $template argument is @@ -357,6 +392,56 @@ public function getNotification($name, array $optionalArgs = []) )->wait(); } + /** + * Get notification settings. + * + * Sample code: + * ``` + * $advisoryNotificationsServiceClient = new AdvisoryNotificationsServiceClient(); + * try { + * $formattedName = $advisoryNotificationsServiceClient->settingsName('[ORGANIZATION]', '[LOCATION]'); + * $response = $advisoryNotificationsServiceClient->getSettings($formattedName); + * } finally { + * $advisoryNotificationsServiceClient->close(); + * } + * ``` + * + * @param string $name Required. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\AdvisoryNotifications\V1\Settings + * + * @throws ApiException if the remote call fails + */ + public function getSettings($name, array $optionalArgs = []) + { + $request = new GetSettingsRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'GetSettings', + Settings::class, + $optionalArgs, + $request + )->wait(); + } + /** * Lists notifications under a given parent. * @@ -452,4 +537,52 @@ public function listNotifications($parent, array $optionalArgs = []) $request ); } + + /** + * Update notification settings. + * + * Sample code: + * ``` + * $advisoryNotificationsServiceClient = new AdvisoryNotificationsServiceClient(); + * try { + * $settings = new Settings(); + * $response = $advisoryNotificationsServiceClient->updateSettings($settings); + * } finally { + * $advisoryNotificationsServiceClient->close(); + * } + * ``` + * + * @param Settings $settings Required. New settings. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\AdvisoryNotifications\V1\Settings + * + * @throws ApiException if the remote call fails + */ + public function updateSettings($settings, array $optionalArgs = []) + { + $request = new UpdateSettingsRequest(); + $requestParamHeaders = []; + $request->setSettings($settings); + $requestParamHeaders['settings.name'] = $settings->getName(); + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'UpdateSettings', + Settings::class, + $optionalArgs, + $request + )->wait(); + } } diff --git a/AdvisoryNotifications/src/V1/GetSettingsRequest.php b/AdvisoryNotifications/src/V1/GetSettingsRequest.php new file mode 100644 index 000000000000..ca213364ae8e --- /dev/null +++ b/AdvisoryNotifications/src/V1/GetSettingsRequest.php @@ -0,0 +1,91 @@ +google.cloud.advisorynotifications.v1.GetSettingsRequest + */ +class GetSettingsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $name = ''; + + /** + * @param string $name Required. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. Please see + * {@see AdvisoryNotificationsServiceClient::settingsName()} for help formatting this field. + * + * @return \Google\Cloud\AdvisoryNotifications\V1\GetSettingsRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Advisorynotifications\V1\Service::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/AdvisoryNotifications/src/V1/NotificationSettings.php b/AdvisoryNotifications/src/V1/NotificationSettings.php new file mode 100644 index 000000000000..c360141cdf67 --- /dev/null +++ b/AdvisoryNotifications/src/V1/NotificationSettings.php @@ -0,0 +1,67 @@ +google.cloud.advisorynotifications.v1.NotificationSettings + */ +class NotificationSettings extends \Google\Protobuf\Internal\Message +{ + /** + * Whether the associated NotificationType is enabled. + * + * Generated from protobuf field bool enabled = 1; + */ + protected $enabled = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $enabled + * Whether the associated NotificationType is enabled. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Advisorynotifications\V1\Service::initOnce(); + parent::__construct($data); + } + + /** + * Whether the associated NotificationType is enabled. + * + * Generated from protobuf field bool enabled = 1; + * @return bool + */ + public function getEnabled() + { + return $this->enabled; + } + + /** + * Whether the associated NotificationType is enabled. + * + * Generated from protobuf field bool enabled = 1; + * @param bool $var + * @return $this + */ + public function setEnabled($var) + { + GPBUtil::checkBool($var); + $this->enabled = $var; + + return $this; + } + +} + diff --git a/AdvisoryNotifications/src/V1/Settings.php b/AdvisoryNotifications/src/V1/Settings.php new file mode 100644 index 000000000000..70baa8b3ef7c --- /dev/null +++ b/AdvisoryNotifications/src/V1/Settings.php @@ -0,0 +1,163 @@ +google.cloud.advisorynotifications.v1.Settings + */ +class Settings extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $name = ''; + /** + * Required. Map of each notification type and its settings to get/set all + * settings at once. The server will validate the value for each notification + * type. + * + * Generated from protobuf field map notification_settings = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $notification_settings; + /** + * Required. Fingerprint for optimistic concurrency returned in Get requests. + * Must be provided for Update requests. If the value provided does not match + * the value known to the server, ABORTED will be thrown, and the client + * should retry the read-modify-write cycle. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = REQUIRED]; + */ + protected $etag = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Output only. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * @type array|\Google\Protobuf\Internal\MapField $notification_settings + * Required. Map of each notification type and its settings to get/set all + * settings at once. The server will validate the value for each notification + * type. + * @type string $etag + * Required. Fingerprint for optimistic concurrency returned in Get requests. + * Must be provided for Update requests. If the value provided does not match + * the value known to the server, ABORTED will be thrown, and the client + * should retry the read-modify-write cycle. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Advisorynotifications\V1\Service::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Output only. The resource name of the settings to retrieve. + * Format: + * organizations/{organization}/locations/{location}/settings. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Required. Map of each notification type and its settings to get/set all + * settings at once. The server will validate the value for each notification + * type. + * + * Generated from protobuf field map notification_settings = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Protobuf\Internal\MapField + */ + public function getNotificationSettings() + { + return $this->notification_settings; + } + + /** + * Required. Map of each notification type and its settings to get/set all + * settings at once. The server will validate the value for each notification + * type. + * + * Generated from protobuf field map notification_settings = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setNotificationSettings($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\AdvisoryNotifications\V1\NotificationSettings::class); + $this->notification_settings = $arr; + + return $this; + } + + /** + * Required. Fingerprint for optimistic concurrency returned in Get requests. + * Must be provided for Update requests. If the value provided does not match + * the value known to the server, ABORTED will be thrown, and the client + * should retry the read-modify-write cycle. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * Required. Fingerprint for optimistic concurrency returned in Get requests. + * Must be provided for Update requests. If the value provided does not match + * the value known to the server, ABORTED will be thrown, and the client + * should retry the read-modify-write cycle. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setEtag($var) + { + GPBUtil::checkString($var, True); + $this->etag = $var; + + return $this; + } + +} + diff --git a/AdvisoryNotifications/src/V1/UpdateSettingsRequest.php b/AdvisoryNotifications/src/V1/UpdateSettingsRequest.php new file mode 100644 index 000000000000..ac58bb44826a --- /dev/null +++ b/AdvisoryNotifications/src/V1/UpdateSettingsRequest.php @@ -0,0 +1,90 @@ +google.cloud.advisorynotifications.v1.UpdateSettingsRequest + */ +class UpdateSettingsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. New settings. + * + * Generated from protobuf field .google.cloud.advisorynotifications.v1.Settings settings = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + protected $settings = null; + + /** + * @param \Google\Cloud\AdvisoryNotifications\V1\Settings $settings Required. New settings. + * + * @return \Google\Cloud\AdvisoryNotifications\V1\UpdateSettingsRequest + * + * @experimental + */ + public static function build(\Google\Cloud\AdvisoryNotifications\V1\Settings $settings): self + { + return (new self()) + ->setSettings($settings); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\AdvisoryNotifications\V1\Settings $settings + * Required. New settings. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Advisorynotifications\V1\Service::initOnce(); + parent::__construct($data); + } + + /** + * Required. New settings. + * + * Generated from protobuf field .google.cloud.advisorynotifications.v1.Settings settings = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\AdvisoryNotifications\V1\Settings|null + */ + public function getSettings() + { + return $this->settings; + } + + public function hasSettings() + { + return isset($this->settings); + } + + public function clearSettings() + { + unset($this->settings); + } + + /** + * Required. New settings. + * + * Generated from protobuf field .google.cloud.advisorynotifications.v1.Settings settings = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\AdvisoryNotifications\V1\Settings $var + * @return $this + */ + public function setSettings($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AdvisoryNotifications\V1\Settings::class); + $this->settings = $var; + + return $this; + } + +} + diff --git a/AdvisoryNotifications/src/V1/gapic_metadata.json b/AdvisoryNotifications/src/V1/gapic_metadata.json index 93abc9405f87..ff46c6a425f8 100644 --- a/AdvisoryNotifications/src/V1/gapic_metadata.json +++ b/AdvisoryNotifications/src/V1/gapic_metadata.json @@ -15,10 +15,20 @@ "getNotification" ] }, + "GetSettings": { + "methods": [ + "getSettings" + ] + }, "ListNotifications": { "methods": [ "listNotifications" ] + }, + "UpdateSettings": { + "methods": [ + "updateSettings" + ] } } } diff --git a/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_client_config.json b/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_client_config.json index c2d18a61b95c..73a44f467731 100644 --- a/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_client_config.json +++ b/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_client_config.json @@ -33,10 +33,20 @@ "retry_codes_name": "retry_policy_1_codes", "retry_params_name": "retry_policy_1_params" }, + "GetSettings": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "ListNotifications": { "timeout_millis": 60000, "retry_codes_name": "retry_policy_1_codes", "retry_params_name": "retry_policy_1_params" + }, + "UpdateSettings": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" } } } diff --git a/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_descriptor_config.php b/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_descriptor_config.php index 3c3e51ad4e2a..550c8936d515 100644 --- a/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_descriptor_config.php +++ b/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_descriptor_config.php @@ -15,6 +15,18 @@ ], ], ], + 'GetSettings' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\AdvisoryNotifications\V1\Settings', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListNotifications' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -35,9 +47,23 @@ ], ], ], + 'UpdateSettings' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\AdvisoryNotifications\V1\Settings', + 'headerParams' => [ + [ + 'keyName' => 'settings.name', + 'fieldAccessors' => [ + 'getSettings', + 'getName', + ], + ], + ], + ], 'templateMap' => [ 'location' => 'organizations/{organization}/locations/{location}', 'notification' => 'organizations/{organization}/locations/{location}/notifications/{notification}', + 'settings' => 'organizations/{organization}/locations/{location}/settings', ], ], ], diff --git a/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_rest_client_config.php b/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_rest_client_config.php index 2419459515bf..d623ce46e74b 100644 --- a/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_rest_client_config.php +++ b/AdvisoryNotifications/src/V1/resources/advisory_notifications_service_rest_client_config.php @@ -14,6 +14,17 @@ ], ], ], + 'GetSettings' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=organizations/*/locations/*/settings}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'ListNotifications' => [ 'method' => 'get', 'uriTemplate' => '/v1/{parent=organizations/*/locations/*}/notifications', @@ -25,6 +36,19 @@ ], ], ], + 'UpdateSettings' => [ + 'method' => 'patch', + 'uriTemplate' => '/v1/{settings.name=organizations/*/locations/*/settings}', + 'body' => 'settings', + 'placeholders' => [ + 'settings.name' => [ + 'getters' => [ + 'getSettings', + 'getName', + ], + ], + ], + ], ], ], 'numericEnums' => true, diff --git a/AdvisoryNotifications/tests/Unit/V1/AdvisoryNotificationsServiceClientTest.php b/AdvisoryNotifications/tests/Unit/V1/AdvisoryNotificationsServiceClientTest.php index 03c50b525c25..6989a92dbcb7 100644 --- a/AdvisoryNotifications/tests/Unit/V1/AdvisoryNotificationsServiceClientTest.php +++ b/AdvisoryNotifications/tests/Unit/V1/AdvisoryNotificationsServiceClientTest.php @@ -29,6 +29,8 @@ use Google\Cloud\AdvisoryNotifications\V1\AdvisoryNotificationsServiceClient; use Google\Cloud\AdvisoryNotifications\V1\ListNotificationsResponse; use Google\Cloud\AdvisoryNotifications\V1\Notification; +use Google\Cloud\AdvisoryNotifications\V1\NotificationSettings; +use Google\Cloud\AdvisoryNotifications\V1\Settings; use Google\Rpc\Code; use stdClass; @@ -120,6 +122,68 @@ public function getNotificationExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function getSettingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $etag = 'etag3123477'; + $expectedResponse = new Settings(); + $expectedResponse->setName($name2); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->settingsName('[ORGANIZATION]', '[LOCATION]'); + $response = $gapicClient->getSettings($formattedName); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.advisorynotifications.v1.AdvisoryNotificationsService/GetSettings', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSettingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->settingsName('[ORGANIZATION]', '[LOCATION]'); + try { + $gapicClient->getSettings($formattedName); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function listNotificationsTest() { @@ -189,4 +253,80 @@ public function listNotificationsExceptionTest() $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); } + + /** @test */ + public function updateSettingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $etag = 'etag3123477'; + $expectedResponse = new Settings(); + $expectedResponse->setName($name); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $settings = new Settings(); + $notificationSettingsValue = new NotificationSettings(); + $settingsNotificationSettings = [ + 'notificationSettingsKey' => $notificationSettingsValue, + ]; + $settings->setNotificationSettings($settingsNotificationSettings); + $settingsEtag = 'settingsEtag533925848'; + $settings->setEtag($settingsEtag); + $response = $gapicClient->updateSettings($settings); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.advisorynotifications.v1.AdvisoryNotificationsService/UpdateSettings', $actualFuncCall); + $actualValue = $actualRequestObject->getSettings(); + $this->assertProtobufEquals($settings, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateSettingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $settings = new Settings(); + $notificationSettingsValue = new NotificationSettings(); + $settingsNotificationSettings = [ + 'notificationSettingsKey' => $notificationSettingsValue, + ]; + $settings->setNotificationSettings($settingsNotificationSettings); + $settingsEtag = 'settingsEtag533925848'; + $settings->setEtag($settingsEtag); + try { + $gapicClient->updateSettings($settings); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } } diff --git a/AdvisoryNotifications/tests/Unit/V1/Client/AdvisoryNotificationsServiceClientTest.php b/AdvisoryNotifications/tests/Unit/V1/Client/AdvisoryNotificationsServiceClientTest.php index de8c2cbffbb5..c2174baa744f 100644 --- a/AdvisoryNotifications/tests/Unit/V1/Client/AdvisoryNotificationsServiceClientTest.php +++ b/AdvisoryNotifications/tests/Unit/V1/Client/AdvisoryNotificationsServiceClientTest.php @@ -28,9 +28,13 @@ use Google\ApiCore\Testing\MockTransport; use Google\Cloud\AdvisoryNotifications\V1\Client\AdvisoryNotificationsServiceClient; use Google\Cloud\AdvisoryNotifications\V1\GetNotificationRequest; +use Google\Cloud\AdvisoryNotifications\V1\GetSettingsRequest; use Google\Cloud\AdvisoryNotifications\V1\ListNotificationsRequest; use Google\Cloud\AdvisoryNotifications\V1\ListNotificationsResponse; use Google\Cloud\AdvisoryNotifications\V1\Notification; +use Google\Cloud\AdvisoryNotifications\V1\NotificationSettings; +use Google\Cloud\AdvisoryNotifications\V1\Settings; +use Google\Cloud\AdvisoryNotifications\V1\UpdateSettingsRequest; use Google\Rpc\Code; use stdClass; @@ -126,6 +130,72 @@ public function getNotificationExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function getSettingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $etag = 'etag3123477'; + $expectedResponse = new Settings(); + $expectedResponse->setName($name2); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->settingsName('[ORGANIZATION]', '[LOCATION]'); + $request = (new GetSettingsRequest()) + ->setName($formattedName); + $response = $gapicClient->getSettings($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.advisorynotifications.v1.AdvisoryNotificationsService/GetSettings', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSettingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->settingsName('[ORGANIZATION]', '[LOCATION]'); + $request = (new GetSettingsRequest()) + ->setName($formattedName); + try { + $gapicClient->getSettings($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function listNotificationsTest() { @@ -200,6 +270,86 @@ public function listNotificationsExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function updateSettingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $etag = 'etag3123477'; + $expectedResponse = new Settings(); + $expectedResponse->setName($name); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $settings = new Settings(); + $notificationSettingsValue = new NotificationSettings(); + $settingsNotificationSettings = [ + 'notificationSettingsKey' => $notificationSettingsValue, + ]; + $settings->setNotificationSettings($settingsNotificationSettings); + $settingsEtag = 'settingsEtag533925848'; + $settings->setEtag($settingsEtag); + $request = (new UpdateSettingsRequest()) + ->setSettings($settings); + $response = $gapicClient->updateSettings($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.advisorynotifications.v1.AdvisoryNotificationsService/UpdateSettings', $actualFuncCall); + $actualValue = $actualRequestObject->getSettings(); + $this->assertProtobufEquals($settings, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateSettingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $settings = new Settings(); + $notificationSettingsValue = new NotificationSettings(); + $settingsNotificationSettings = [ + 'notificationSettingsKey' => $notificationSettingsValue, + ]; + $settings->setNotificationSettings($settingsNotificationSettings); + $settingsEtag = 'settingsEtag533925848'; + $settings->setEtag($settingsEtag); + $request = (new UpdateSettingsRequest()) + ->setSettings($settings); + try { + $gapicClient->updateSettings($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function getNotificationAsyncTest() {