1<?php 2/* 3 * Copyright 2014 Google Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 * use this file except in compliance with the License. You may obtain a copy of 7 * the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 * License for the specific language governing permissions and limitations under 15 * the License. 16 */ 17 18namespace Google\Service\Pubsub\Resource; 19 20use Google\Service\Pubsub\AcknowledgeRequest; 21use Google\Service\Pubsub\DetachSubscriptionResponse; 22use Google\Service\Pubsub\ListSubscriptionsResponse; 23use Google\Service\Pubsub\ModifyAckDeadlineRequest; 24use Google\Service\Pubsub\ModifyPushConfigRequest; 25use Google\Service\Pubsub\Policy; 26use Google\Service\Pubsub\PubsubEmpty; 27use Google\Service\Pubsub\PullRequest; 28use Google\Service\Pubsub\PullResponse; 29use Google\Service\Pubsub\SeekRequest; 30use Google\Service\Pubsub\SeekResponse; 31use Google\Service\Pubsub\SetIamPolicyRequest; 32use Google\Service\Pubsub\Subscription; 33use Google\Service\Pubsub\TestIamPermissionsRequest; 34use Google\Service\Pubsub\TestIamPermissionsResponse; 35use Google\Service\Pubsub\UpdateSubscriptionRequest; 36 37/** 38 * The "subscriptions" collection of methods. 39 * Typical usage is: 40 * <code> 41 * $pubsubService = new Google\Service\Pubsub(...); 42 * $subscriptions = $pubsubService->subscriptions; 43 * </code> 44 */ 45class ProjectsSubscriptions extends \Google\Service\Resource 46{ 47 /** 48 * Acknowledges the messages associated with the `ack_ids` in the 49 * `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages 50 * from the subscription. Acknowledging a message whose ack deadline has expired 51 * may succeed, but such a message may be redelivered later. Acknowledging a 52 * message more than once will not result in an error. 53 * (subscriptions.acknowledge) 54 * 55 * @param string $subscription Required. The subscription whose message is being 56 * acknowledged. Format is `projects/{project}/subscriptions/{sub}`. 57 * @param AcknowledgeRequest $postBody 58 * @param array $optParams Optional parameters. 59 * @return PubsubEmpty 60 */ 61 public function acknowledge($subscription, AcknowledgeRequest $postBody, $optParams = []) 62 { 63 $params = ['subscription' => $subscription, 'postBody' => $postBody]; 64 $params = array_merge($params, $optParams); 65 return $this->call('acknowledge', [$params], PubsubEmpty::class); 66 } 67 /** 68 * Creates a subscription to a given topic. See the [resource name rules] 69 * (https://cloud.google.com/pubsub/docs/admin#resource_names). If the 70 * subscription already exists, returns `ALREADY_EXISTS`. If the corresponding 71 * topic doesn't exist, returns `NOT_FOUND`. If the name is not provided in the 72 * request, the server will assign a random name for this subscription on the 73 * same project as the topic, conforming to the [resource name format] 74 * (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated 75 * name is populated in the returned Subscription object. Note that for REST API 76 * requests, you must specify a name in the request. (subscriptions.create) 77 * 78 * @param string $name Required. The name of the subscription. It must have the 79 * format `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` 80 * must start with a letter, and contain only letters (`[A-Za-z]`), numbers 81 * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), plus 82 * (`+`) or percent signs (`%`). It must be between 3 and 255 characters in 83 * length, and it must not start with `"goog"`. 84 * @param Subscription $postBody 85 * @param array $optParams Optional parameters. 86 * @return Subscription 87 */ 88 public function create($name, Subscription $postBody, $optParams = []) 89 { 90 $params = ['name' => $name, 'postBody' => $postBody]; 91 $params = array_merge($params, $optParams); 92 return $this->call('create', [$params], Subscription::class); 93 } 94 /** 95 * Deletes an existing subscription. All messages retained in the subscription 96 * are immediately dropped. Calls to `Pull` after deletion will return 97 * `NOT_FOUND`. After a subscription is deleted, a new one may be created with 98 * the same name, but the new one has no association with the old subscription 99 * or its topic unless the same topic is specified. (subscriptions.delete) 100 * 101 * @param string $subscription Required. The subscription to delete. Format is 102 * `projects/{project}/subscriptions/{sub}`. 103 * @param array $optParams Optional parameters. 104 * @return PubsubEmpty 105 */ 106 public function delete($subscription, $optParams = []) 107 { 108 $params = ['subscription' => $subscription]; 109 $params = array_merge($params, $optParams); 110 return $this->call('delete', [$params], PubsubEmpty::class); 111 } 112 /** 113 * Detaches a subscription from this topic. All messages retained in the 114 * subscription are dropped. Subsequent `Pull` and `StreamingPull` requests will 115 * return FAILED_PRECONDITION. If the subscription is a push subscription, 116 * pushes to the endpoint will stop. (subscriptions.detach) 117 * 118 * @param string $subscription Required. The subscription to detach. Format is 119 * `projects/{project}/subscriptions/{subscription}`. 120 * @param array $optParams Optional parameters. 121 * @return DetachSubscriptionResponse 122 */ 123 public function detach($subscription, $optParams = []) 124 { 125 $params = ['subscription' => $subscription]; 126 $params = array_merge($params, $optParams); 127 return $this->call('detach', [$params], DetachSubscriptionResponse::class); 128 } 129 /** 130 * Gets the configuration details of a subscription. (subscriptions.get) 131 * 132 * @param string $subscription Required. The name of the subscription to get. 133 * Format is `projects/{project}/subscriptions/{sub}`. 134 * @param array $optParams Optional parameters. 135 * @return Subscription 136 */ 137 public function get($subscription, $optParams = []) 138 { 139 $params = ['subscription' => $subscription]; 140 $params = array_merge($params, $optParams); 141 return $this->call('get', [$params], Subscription::class); 142 } 143 /** 144 * Gets the access control policy for a resource. Returns an empty policy if the 145 * resource exists and does not have a policy set. (subscriptions.getIamPolicy) 146 * 147 * @param string $resource REQUIRED: The resource for which the policy is being 148 * requested. See the operation documentation for the appropriate value for this 149 * field. 150 * @param array $optParams Optional parameters. 151 * 152 * @opt_param int options.requestedPolicyVersion Optional. The maximum policy 153 * version that will be used to format the policy. Valid values are 0, 1, and 3. 154 * Requests specifying an invalid value will be rejected. Requests for policies 155 * with any conditional role bindings must specify version 3. Policies with no 156 * conditional role bindings may specify any valid value or leave the field 157 * unset. The policy in the response might use the policy version that you 158 * specified, or it might use a lower policy version. For example, if you 159 * specify version 3, but the policy has no conditional role bindings, the 160 * response uses version 1. To learn which resources support conditions in their 161 * IAM policies, see the [IAM 162 * documentation](https://cloud.google.com/iam/help/conditions/resource- 163 * policies). 164 * @return Policy 165 */ 166 public function getIamPolicy($resource, $optParams = []) 167 { 168 $params = ['resource' => $resource]; 169 $params = array_merge($params, $optParams); 170 return $this->call('getIamPolicy', [$params], Policy::class); 171 } 172 /** 173 * Lists matching subscriptions. (subscriptions.listProjectsSubscriptions) 174 * 175 * @param string $project Required. The name of the project in which to list 176 * subscriptions. Format is `projects/{project-id}`. 177 * @param array $optParams Optional parameters. 178 * 179 * @opt_param int pageSize Maximum number of subscriptions to return. 180 * @opt_param string pageToken The value returned by the last 181 * `ListSubscriptionsResponse`; indicates that this is a continuation of a prior 182 * `ListSubscriptions` call, and that the system should return the next page of 183 * data. 184 * @return ListSubscriptionsResponse 185 */ 186 public function listProjectsSubscriptions($project, $optParams = []) 187 { 188 $params = ['project' => $project]; 189 $params = array_merge($params, $optParams); 190 return $this->call('list', [$params], ListSubscriptionsResponse::class); 191 } 192 /** 193 * Modifies the ack deadline for a specific message. This method is useful to 194 * indicate that more time is needed to process a message by the subscriber, or 195 * to make the message available for redelivery if the processing was 196 * interrupted. Note that this does not modify the subscription-level 197 * `ackDeadlineSeconds` used for subsequent messages. 198 * (subscriptions.modifyAckDeadline) 199 * 200 * @param string $subscription Required. The name of the subscription. Format is 201 * `projects/{project}/subscriptions/{sub}`. 202 * @param ModifyAckDeadlineRequest $postBody 203 * @param array $optParams Optional parameters. 204 * @return PubsubEmpty 205 */ 206 public function modifyAckDeadline($subscription, ModifyAckDeadlineRequest $postBody, $optParams = []) 207 { 208 $params = ['subscription' => $subscription, 'postBody' => $postBody]; 209 $params = array_merge($params, $optParams); 210 return $this->call('modifyAckDeadline', [$params], PubsubEmpty::class); 211 } 212 /** 213 * Modifies the `PushConfig` for a specified subscription. This may be used to 214 * change a push subscription to a pull one (signified by an empty `PushConfig`) 215 * or vice versa, or change the endpoint URL and other attributes of a push 216 * subscription. Messages will accumulate for delivery continuously through the 217 * call regardless of changes to the `PushConfig`. 218 * (subscriptions.modifyPushConfig) 219 * 220 * @param string $subscription Required. The name of the subscription. Format is 221 * `projects/{project}/subscriptions/{sub}`. 222 * @param ModifyPushConfigRequest $postBody 223 * @param array $optParams Optional parameters. 224 * @return PubsubEmpty 225 */ 226 public function modifyPushConfig($subscription, ModifyPushConfigRequest $postBody, $optParams = []) 227 { 228 $params = ['subscription' => $subscription, 'postBody' => $postBody]; 229 $params = array_merge($params, $optParams); 230 return $this->call('modifyPushConfig', [$params], PubsubEmpty::class); 231 } 232 /** 233 * Updates an existing subscription. Note that certain properties of a 234 * subscription, such as its topic, are not modifiable. (subscriptions.patch) 235 * 236 * @param string $name Required. The name of the subscription. It must have the 237 * format `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` 238 * must start with a letter, and contain only letters (`[A-Za-z]`), numbers 239 * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), plus 240 * (`+`) or percent signs (`%`). It must be between 3 and 255 characters in 241 * length, and it must not start with `"goog"`. 242 * @param UpdateSubscriptionRequest $postBody 243 * @param array $optParams Optional parameters. 244 * @return Subscription 245 */ 246 public function patch($name, UpdateSubscriptionRequest $postBody, $optParams = []) 247 { 248 $params = ['name' => $name, 'postBody' => $postBody]; 249 $params = array_merge($params, $optParams); 250 return $this->call('patch', [$params], Subscription::class); 251 } 252 /** 253 * Pulls messages from the server. The server may return `UNAVAILABLE` if there 254 * are too many concurrent pull requests pending for the given subscription. 255 * (subscriptions.pull) 256 * 257 * @param string $subscription Required. The subscription from which messages 258 * should be pulled. Format is `projects/{project}/subscriptions/{sub}`. 259 * @param PullRequest $postBody 260 * @param array $optParams Optional parameters. 261 * @return PullResponse 262 */ 263 public function pull($subscription, PullRequest $postBody, $optParams = []) 264 { 265 $params = ['subscription' => $subscription, 'postBody' => $postBody]; 266 $params = array_merge($params, $optParams); 267 return $this->call('pull', [$params], PullResponse::class); 268 } 269 /** 270 * Seeks an existing subscription to a point in time or to a given snapshot, 271 * whichever is provided in the request. Snapshots are used in [Seek] 272 * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which 273 * allow you to manage message acknowledgments in bulk. That is, you can set the 274 * acknowledgment state of messages in an existing subscription to the state 275 * captured by a snapshot. Note that both the subscription and the snapshot must 276 * be on the same topic. (subscriptions.seek) 277 * 278 * @param string $subscription Required. The subscription to affect. 279 * @param SeekRequest $postBody 280 * @param array $optParams Optional parameters. 281 * @return SeekResponse 282 */ 283 public function seek($subscription, SeekRequest $postBody, $optParams = []) 284 { 285 $params = ['subscription' => $subscription, 'postBody' => $postBody]; 286 $params = array_merge($params, $optParams); 287 return $this->call('seek', [$params], SeekResponse::class); 288 } 289 /** 290 * Sets the access control policy on the specified resource. Replaces any 291 * existing policy. Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and 292 * `PERMISSION_DENIED` errors. (subscriptions.setIamPolicy) 293 * 294 * @param string $resource REQUIRED: The resource for which the policy is being 295 * specified. See the operation documentation for the appropriate value for this 296 * field. 297 * @param SetIamPolicyRequest $postBody 298 * @param array $optParams Optional parameters. 299 * @return Policy 300 */ 301 public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = []) 302 { 303 $params = ['resource' => $resource, 'postBody' => $postBody]; 304 $params = array_merge($params, $optParams); 305 return $this->call('setIamPolicy', [$params], Policy::class); 306 } 307 /** 308 * Returns permissions that a caller has on the specified resource. If the 309 * resource does not exist, this will return an empty set of permissions, not a 310 * `NOT_FOUND` error. Note: This operation is designed to be used for building 311 * permission-aware UIs and command-line tools, not for authorization checking. 312 * This operation may "fail open" without warning. 313 * (subscriptions.testIamPermissions) 314 * 315 * @param string $resource REQUIRED: The resource for which the policy detail is 316 * being requested. See the operation documentation for the appropriate value 317 * for this field. 318 * @param TestIamPermissionsRequest $postBody 319 * @param array $optParams Optional parameters. 320 * @return TestIamPermissionsResponse 321 */ 322 public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = []) 323 { 324 $params = ['resource' => $resource, 'postBody' => $postBody]; 325 $params = array_merge($params, $optParams); 326 return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class); 327 } 328} 329 330// Adding a class alias for backwards compatibility with the previous class name. 331class_alias(ProjectsSubscriptions::class, 'Google_Service_Pubsub_Resource_ProjectsSubscriptions'); 332