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\ListTopicsResponse;
21use Google\Service\Pubsub\Policy;
22use Google\Service\Pubsub\PublishRequest;
23use Google\Service\Pubsub\PublishResponse;
24use Google\Service\Pubsub\PubsubEmpty;
25use Google\Service\Pubsub\SetIamPolicyRequest;
26use Google\Service\Pubsub\TestIamPermissionsRequest;
27use Google\Service\Pubsub\TestIamPermissionsResponse;
28use Google\Service\Pubsub\Topic;
29use Google\Service\Pubsub\UpdateTopicRequest;
30
31/**
32 * The "topics" collection of methods.
33 * Typical usage is:
34 *  <code>
35 *   $pubsubService = new Google\Service\Pubsub(...);
36 *   $topics = $pubsubService->topics;
37 *  </code>
38 */
39class ProjectsTopics extends \Google\Service\Resource
40{
41  /**
42   * Creates the given topic with the given name. See the [resource name rules]
43   * (https://cloud.google.com/pubsub/docs/admin#resource_names). (topics.create)
44   *
45   * @param string $name Required. The name of the topic. It must have the format
46   * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter,
47   * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
48   * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent signs
49   * (`%`). It must be between 3 and 255 characters in length, and it must not
50   * start with `"goog"`.
51   * @param Topic $postBody
52   * @param array $optParams Optional parameters.
53   * @return Topic
54   */
55  public function create($name, Topic $postBody, $optParams = [])
56  {
57    $params = ['name' => $name, 'postBody' => $postBody];
58    $params = array_merge($params, $optParams);
59    return $this->call('create', [$params], Topic::class);
60  }
61  /**
62   * Deletes the topic with the given name. Returns `NOT_FOUND` if the topic does
63   * not exist. After a topic is deleted, a new topic may be created with the same
64   * name; this is an entirely new topic with none of the old configuration or
65   * subscriptions. Existing subscriptions to this topic are not deleted, but
66   * their `topic` field is set to `_deleted-topic_`. (topics.delete)
67   *
68   * @param string $topic Required. Name of the topic to delete. Format is
69   * `projects/{project}/topics/{topic}`.
70   * @param array $optParams Optional parameters.
71   * @return PubsubEmpty
72   */
73  public function delete($topic, $optParams = [])
74  {
75    $params = ['topic' => $topic];
76    $params = array_merge($params, $optParams);
77    return $this->call('delete', [$params], PubsubEmpty::class);
78  }
79  /**
80   * Gets the configuration of a topic. (topics.get)
81   *
82   * @param string $topic Required. The name of the topic to get. Format is
83   * `projects/{project}/topics/{topic}`.
84   * @param array $optParams Optional parameters.
85   * @return Topic
86   */
87  public function get($topic, $optParams = [])
88  {
89    $params = ['topic' => $topic];
90    $params = array_merge($params, $optParams);
91    return $this->call('get', [$params], Topic::class);
92  }
93  /**
94   * Gets the access control policy for a resource. Returns an empty policy if the
95   * resource exists and does not have a policy set. (topics.getIamPolicy)
96   *
97   * @param string $resource REQUIRED: The resource for which the policy is being
98   * requested. See the operation documentation for the appropriate value for this
99   * field.
100   * @param array $optParams Optional parameters.
101   *
102   * @opt_param int options.requestedPolicyVersion Optional. The maximum policy
103   * version that will be used to format the policy. Valid values are 0, 1, and 3.
104   * Requests specifying an invalid value will be rejected. Requests for policies
105   * with any conditional role bindings must specify version 3. Policies with no
106   * conditional role bindings may specify any valid value or leave the field
107   * unset. The policy in the response might use the policy version that you
108   * specified, or it might use a lower policy version. For example, if you
109   * specify version 3, but the policy has no conditional role bindings, the
110   * response uses version 1. To learn which resources support conditions in their
111   * IAM policies, see the [IAM
112   * documentation](https://cloud.google.com/iam/help/conditions/resource-
113   * policies).
114   * @return Policy
115   */
116  public function getIamPolicy($resource, $optParams = [])
117  {
118    $params = ['resource' => $resource];
119    $params = array_merge($params, $optParams);
120    return $this->call('getIamPolicy', [$params], Policy::class);
121  }
122  /**
123   * Lists matching topics. (topics.listProjectsTopics)
124   *
125   * @param string $project Required. The name of the project in which to list
126   * topics. Format is `projects/{project-id}`.
127   * @param array $optParams Optional parameters.
128   *
129   * @opt_param int pageSize Maximum number of topics to return.
130   * @opt_param string pageToken The value returned by the last
131   * `ListTopicsResponse`; indicates that this is a continuation of a prior
132   * `ListTopics` call, and that the system should return the next page of data.
133   * @return ListTopicsResponse
134   */
135  public function listProjectsTopics($project, $optParams = [])
136  {
137    $params = ['project' => $project];
138    $params = array_merge($params, $optParams);
139    return $this->call('list', [$params], ListTopicsResponse::class);
140  }
141  /**
142   * Updates an existing topic. Note that certain properties of a topic are not
143   * modifiable. (topics.patch)
144   *
145   * @param string $name Required. The name of the topic. It must have the format
146   * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter,
147   * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
148   * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent signs
149   * (`%`). It must be between 3 and 255 characters in length, and it must not
150   * start with `"goog"`.
151   * @param UpdateTopicRequest $postBody
152   * @param array $optParams Optional parameters.
153   * @return Topic
154   */
155  public function patch($name, UpdateTopicRequest $postBody, $optParams = [])
156  {
157    $params = ['name' => $name, 'postBody' => $postBody];
158    $params = array_merge($params, $optParams);
159    return $this->call('patch', [$params], Topic::class);
160  }
161  /**
162   * Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic does
163   * not exist. (topics.publish)
164   *
165   * @param string $topic Required. The messages in the request will be published
166   * on this topic. Format is `projects/{project}/topics/{topic}`.
167   * @param PublishRequest $postBody
168   * @param array $optParams Optional parameters.
169   * @return PublishResponse
170   */
171  public function publish($topic, PublishRequest $postBody, $optParams = [])
172  {
173    $params = ['topic' => $topic, 'postBody' => $postBody];
174    $params = array_merge($params, $optParams);
175    return $this->call('publish', [$params], PublishResponse::class);
176  }
177  /**
178   * Sets the access control policy on the specified resource. Replaces any
179   * existing policy. Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and
180   * `PERMISSION_DENIED` errors. (topics.setIamPolicy)
181   *
182   * @param string $resource REQUIRED: The resource for which the policy is being
183   * specified. See the operation documentation for the appropriate value for this
184   * field.
185   * @param SetIamPolicyRequest $postBody
186   * @param array $optParams Optional parameters.
187   * @return Policy
188   */
189  public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = [])
190  {
191    $params = ['resource' => $resource, 'postBody' => $postBody];
192    $params = array_merge($params, $optParams);
193    return $this->call('setIamPolicy', [$params], Policy::class);
194  }
195  /**
196   * Returns permissions that a caller has on the specified resource. If the
197   * resource does not exist, this will return an empty set of permissions, not a
198   * `NOT_FOUND` error. Note: This operation is designed to be used for building
199   * permission-aware UIs and command-line tools, not for authorization checking.
200   * This operation may "fail open" without warning. (topics.testIamPermissions)
201   *
202   * @param string $resource REQUIRED: The resource for which the policy detail is
203   * being requested. See the operation documentation for the appropriate value
204   * for this field.
205   * @param TestIamPermissionsRequest $postBody
206   * @param array $optParams Optional parameters.
207   * @return TestIamPermissionsResponse
208   */
209  public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = [])
210  {
211    $params = ['resource' => $resource, 'postBody' => $postBody];
212    $params = array_merge($params, $optParams);
213    return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class);
214  }
215}
216
217// Adding a class alias for backwards compatibility with the previous class name.
218class_alias(ProjectsTopics::class, 'Google_Service_Pubsub_Resource_ProjectsTopics');
219