We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
PubSub subscription with ack_deadline set causes HTTP 400
Page Name: pubsub-usage
Release: 0.7.1

This appears to return an API error:

```
subscription = topic.subscription('subscription_name', ack_deadline=600)
```

Here is what I am seeing:

```
...
  File "/home/greg.taylor/workspace/aclima/sig-cassandra-extractor/aclima/cass_extractor/queue.py", line 42, in run
    self.subscription.create()
  File "/home/greg.taylor/.virtualenvs/cas-e/lib/python3.4/site-packages/gcloud/pubsub/subscription.py", line 121, in create
    client.connection.api_request(method='PUT', path=self.path, data=data)
  File "/home/greg.taylor/.virtualenvs/cas-e/lib/python3.4/site-packages/gcloud/connection.py", line 419, in api_request
    error_info=method + ' ' + url)
gcloud.exceptions.BadRequest: 400 Invalid JSON payload received. Unknown name "ack_deadline": Cannot find field. (PUT https://pubsub.googleapis.com/v1/projects/aclima-gsa/subscriptions/cassandra_extractor)
```

If I remove the `ack_deadline` kwarg, all is well. We definitely want the ack_deadline, thoguh.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gcloud/pubsub/subscription.py`
Content:
```
1 # Copyright 2015 Google Inc. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Define API Subscriptions."""
16 
17 from gcloud.exceptions import NotFound
18 from gcloud.pubsub._helpers import topic_name_from_path
19 from gcloud.pubsub.message import Message
20 
21 
22 class Subscription(object):
23     """Subscriptions receive messages published to their topics.
24 
25     See:
26     https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions
27 
28     :type name: string
29     :param name: the name of the subscription
30 
31     :type topic: :class:`gcloud.pubsub.topic.Topic`
32     :param topic: the topic to which the subscription belongs..
33 
34     :type ack_deadline: int
35     :param ack_deadline: the deadline (in seconds) by which messages pulled
36                          from the back-end must be acknowledged.
37 
38     :type push_endpoint: string
39     :param push_endpoint: URL to which messages will be pushed by the back-end.
40                           If not set, the application must pull messages.
41     """
42     def __init__(self, name, topic, ack_deadline=None, push_endpoint=None):
43         self.name = name
44         self.topic = topic
45         self.ack_deadline = ack_deadline
46         self.push_endpoint = push_endpoint
47 
48     @classmethod
49     def from_api_repr(cls, resource, client, topics=None):
50         """Factory:  construct a topic given its API representation
51 
52         :type resource: dict
53         :param resource: topic resource representation returned from the API
54 
55         :type client: :class:`gcloud.pubsub.client.Client`
56         :param client: Client which holds credentials and project
57                        configuration for a topic.
58 
59         :type topics: dict or None
60         :param topics: A mapping of topic names -> topics.  If not passed,
61                        the subscription will have a newly-created topic.
62 
63         :rtype: :class:`gcloud.pubsub.subscription.Subscription`
64         :returns: Subscription parsed from ``resource``.
65         """
66         if topics is None:
67             topics = {}
68         topic_path = resource['topic']
69         topic = topics.get(topic_path)
70         if topic is None:
71             # NOTE: This duplicates behavior from Topic.from_api_repr to avoid
72             #       an import cycle.
73             topic_name = topic_name_from_path(topic_path, client.project)
74             topic = topics[topic_path] = client.topic(topic_name)
75         _, _, _, name = resource['name'].split('/')
76         ack_deadline = resource.get('ackDeadlineSeconds')
77         push_config = resource.get('pushConfig', {})
78         push_endpoint = push_config.get('pushEndpoint')
79         return cls(name, topic, ack_deadline, push_endpoint)
80 
81     @property
82     def path(self):
83         """URL path for the subscription's APIs"""
84         project = self.topic.project
85         return '/projects/%s/subscriptions/%s' % (project, self.name)
86 
87     def _require_client(self, client):
88         """Check client or verify over-ride.
89 
90         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
91         :param client: the client to use.  If not passed, falls back to the
92                        ``client`` stored on the topic of the
93                        current subscription.
94 
95         :rtype: :class:`gcloud.pubsub.client.Client`
96         :returns: The client passed in or the currently bound client.
97         """
98         if client is None:
99             client = self.topic._client
100         return client
101 
102     def create(self, client=None):
103         """API call:  create the subscription via a PUT request
104 
105         See:
106         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/create
107 
108         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
109         :param client: the client to use.  If not passed, falls back to the
110                        ``client`` stored on the current subscription's topic.
111         """
112         data = {'topic': self.topic.full_name}
113 
114         if self.ack_deadline is not None:
115             data['ackDeadline'] = self.ack_deadline
116 
117         if self.push_endpoint is not None:
118             data['pushConfig'] = {'pushEndpoint': self.push_endpoint}
119 
120         client = self._require_client(client)
121         client.connection.api_request(method='PUT', path=self.path, data=data)
122 
123     def exists(self, client=None):
124         """API call:  test existence of the subscription via a GET request
125 
126         See
127         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/get
128 
129         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
130         :param client: the client to use.  If not passed, falls back to the
131                        ``client`` stored on the current subscription's topic.
132         """
133         client = self._require_client(client)
134         try:
135             client.connection.api_request(method='GET', path=self.path)
136         except NotFound:
137             return False
138         else:
139             return True
140 
141     def reload(self, client=None):
142         """API call:  sync local subscription configuration via a GET request
143 
144         See
145         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/get
146 
147         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
148         :param client: the client to use.  If not passed, falls back to the
149                        ``client`` stored on the current subscription's topic.
150         """
151         client = self._require_client(client)
152         data = client.connection.api_request(method='GET', path=self.path)
153         self.ack_deadline = data.get('ackDeadline')
154         push_config = data.get('pushConfig', {})
155         self.push_endpoint = push_config.get('pushEndpoint')
156 
157     def modify_push_configuration(self, push_endpoint, client=None):
158         """API call:  update the push endpoint for the subscription.
159 
160         See:
161         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/modifyPushConfig
162 
163         :type push_endpoint: string
164         :param push_endpoint: URL to which messages will be pushed by the
165                               back-end.  If None, the application must pull
166                               messages.
167 
168         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
169         :param client: the client to use.  If not passed, falls back to the
170                        ``client`` stored on the current subscription's topic.
171         """
172         client = self._require_client(client)
173         data = {}
174         config = data['pushConfig'] = {}
175         if push_endpoint is not None:
176             config['pushEndpoint'] = push_endpoint
177         client.connection.api_request(
178             method='POST', path='%s:modifyPushConfig' % (self.path,),
179             data=data)
180         self.push_endpoint = push_endpoint
181 
182     def pull(self, return_immediately=False, max_messages=1, client=None):
183         """API call:  retrieve messages for the subscription.
184 
185         See:
186         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/pull
187 
188         :type return_immediately: boolean
189         :param return_immediately: if True, the back-end returns even if no
190                                    messages are available;  if False, the API
191                                    call blocks until one or more messages are
192                                    available.
193 
194         :type max_messages: int
195         :param max_messages: the maximum number of messages to return.
196 
197         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
198         :param client: the client to use.  If not passed, falls back to the
199                        ``client`` stored on the current subscription's topic.
200 
201         :rtype: list of (ack_id, message) tuples
202         :returns: sequence of tuples: ``ack_id`` is the ID to be used in a
203                   subsequent call to :meth:`acknowledge`, and ``message``
204                   is an instance of :class:`gcloud.pubsub.message.Message`.
205         """
206         client = self._require_client(client)
207         data = {'returnImmediately': return_immediately,
208                 'maxMessages': max_messages}
209         response = client.connection.api_request(
210             method='POST', path='%s:pull' % (self.path,), data=data)
211         return [(info['ackId'], Message.from_api_repr(info['message']))
212                 for info in response.get('receivedMessages', ())]
213 
214     def acknowledge(self, ack_ids, client=None):
215         """API call:  acknowledge retrieved messages for the subscription.
216 
217         See:
218         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/acknowledge
219 
220         :type ack_ids: list of string
221         :param ack_ids: ack IDs of messages being acknowledged
222 
223         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
224         :param client: the client to use.  If not passed, falls back to the
225                        ``client`` stored on the current subscription's topic.
226         """
227         client = self._require_client(client)
228         data = {'ackIds': ack_ids}
229         client.connection.api_request(
230             method='POST', path='%s:acknowledge' % (self.path,), data=data)
231 
232     def modify_ack_deadline(self, ack_id, ack_deadline, client=None):
233         """API call:  update acknowledgement deadline for a retrieved message.
234 
235         See:
236         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/acknowledge
237 
238         :type ack_id: string
239         :param ack_id: ack ID of message being updated
240 
241         :type ack_deadline: int
242         :param ack_deadline: new deadline for the message, in seconds
243 
244         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
245         :param client: the client to use.  If not passed, falls back to the
246                        ``client`` stored on the current subscription's topic.
247         """
248         client = self._require_client(client)
249         data = {'ackIds': [ack_id], 'ackDeadlineSeconds': ack_deadline}
250         client.connection.api_request(
251             method='POST', path='%s:modifyAckDeadline' % (self.path,),
252             data=data)
253 
254     def delete(self, client=None):
255         """API call:  delete the subscription via a DELETE request.
256 
257         See:
258         https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/delete
259 
260         :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``
261         :param client: the client to use.  If not passed, falls back to the
262                        ``client`` stored on the current subscription's topic.
263         """
264         client = self._require_client(client)
265         client.connection.api_request(method='DELETE', path=self.path)
266
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gcloud/pubsub/subscription.py b/gcloud/pubsub/subscription.py
--- a/gcloud/pubsub/subscription.py
+++ b/gcloud/pubsub/subscription.py
@@ -112,7 +112,7 @@
         data = {'topic': self.topic.full_name}
 
         if self.ack_deadline is not None:
-            data['ackDeadline'] = self.ack_deadline
+            data['ackDeadlineSeconds'] = self.ack_deadline
 
         if self.push_endpoint is not None:
             data['pushConfig'] = {'pushEndpoint': self.push_endpoint}
@@ -150,7 +150,7 @@
         """
         client = self._require_client(client)
         data = client.connection.api_request(method='GET', path=self.path)
-        self.ack_deadline = data.get('ackDeadline')
+        self.ack_deadline = data.get('ackDeadlineSeconds')
         push_config = data.get('pushConfig', {})
         self.push_endpoint = push_config.get('pushEndpoint')

{"golden_diff": "diff --git a/gcloud/pubsub/subscription.py b/gcloud/pubsub/subscription.py\n--- a/gcloud/pubsub/subscription.py\n+++ b/gcloud/pubsub/subscription.py\n@@ -112,7 +112,7 @@\n         data = {'topic': self.topic.full_name}\n \n         if self.ack_deadline is not None:\n-            data['ackDeadline'] = self.ack_deadline\n+            data['ackDeadlineSeconds'] = self.ack_deadline\n \n         if self.push_endpoint is not None:\n             data['pushConfig'] = {'pushEndpoint': self.push_endpoint}\n@@ -150,7 +150,7 @@\n         \"\"\"\n         client = self._require_client(client)\n         data = client.connection.api_request(method='GET', path=self.path)\n-        self.ack_deadline = data.get('ackDeadline')\n+        self.ack_deadline = data.get('ackDeadlineSeconds')\n         push_config = data.get('pushConfig', {})\n         self.push_endpoint = push_config.get('pushEndpoint')\n", "issue": "PubSub subscription with ack_deadline set causes HTTP 400\nPage Name: pubsub-usage\nRelease: 0.7.1\n\nThis appears to return an API error:\n\n```\nsubscription = topic.subscription('subscription_name', ack_deadline=600)\n```\n\nHere is what I am seeing:\n\n```\n...\n  File \"/home/greg.taylor/workspace/aclima/sig-cassandra-extractor/aclima/cass_extractor/queue.py\", line 42, in run\n    self.subscription.create()\n  File \"/home/greg.taylor/.virtualenvs/cas-e/lib/python3.4/site-packages/gcloud/pubsub/subscription.py\", line 121, in create\n    client.connection.api_request(method='PUT', path=self.path, data=data)\n  File \"/home/greg.taylor/.virtualenvs/cas-e/lib/python3.4/site-packages/gcloud/connection.py\", line 419, in api_request\n    error_info=method + ' ' + url)\ngcloud.exceptions.BadRequest: 400 Invalid JSON payload received. Unknown name \"ack_deadline\": Cannot find field. (PUT https://pubsub.googleapis.com/v1/projects/aclima-gsa/subscriptions/cassandra_extractor)\n```\n\nIf I remove the `ack_deadline` kwarg, all is well. We definitely want the ack_deadline, thoguh.\n\n", "before_files": [{"content": "# Copyright 2015 Google Inc. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Define API Subscriptions.\"\"\"\n\nfrom gcloud.exceptions import NotFound\nfrom gcloud.pubsub._helpers import topic_name_from_path\nfrom gcloud.pubsub.message import Message\n\n\nclass Subscription(object):\n    \"\"\"Subscriptions receive messages published to their topics.\n\n    See:\n    https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions\n\n    :type name: string\n    :param name: the name of the subscription\n\n    :type topic: :class:`gcloud.pubsub.topic.Topic`\n    :param topic: the topic to which the subscription belongs..\n\n    :type ack_deadline: int\n    :param ack_deadline: the deadline (in seconds) by which messages pulled\n                         from the back-end must be acknowledged.\n\n    :type push_endpoint: string\n    :param push_endpoint: URL to which messages will be pushed by the back-end.\n                          If not set, the application must pull messages.\n    \"\"\"\n    def __init__(self, name, topic, ack_deadline=None, push_endpoint=None):\n        self.name = name\n        self.topic = topic\n        self.ack_deadline = ack_deadline\n        self.push_endpoint = push_endpoint\n\n    @classmethod\n    def from_api_repr(cls, resource, client, topics=None):\n        \"\"\"Factory:  construct a topic given its API representation\n\n        :type resource: dict\n        :param resource: topic resource representation returned from the API\n\n        :type client: :class:`gcloud.pubsub.client.Client`\n        :param client: Client which holds credentials and project\n                       configuration for a topic.\n\n        :type topics: dict or None\n        :param topics: A mapping of topic names -> topics.  If not passed,\n                       the subscription will have a newly-created topic.\n\n        :rtype: :class:`gcloud.pubsub.subscription.Subscription`\n        :returns: Subscription parsed from ``resource``.\n        \"\"\"\n        if topics is None:\n            topics = {}\n        topic_path = resource['topic']\n        topic = topics.get(topic_path)\n        if topic is None:\n            # NOTE: This duplicates behavior from Topic.from_api_repr to avoid\n            #       an import cycle.\n            topic_name = topic_name_from_path(topic_path, client.project)\n            topic = topics[topic_path] = client.topic(topic_name)\n        _, _, _, name = resource['name'].split('/')\n        ack_deadline = resource.get('ackDeadlineSeconds')\n        push_config = resource.get('pushConfig', {})\n        push_endpoint = push_config.get('pushEndpoint')\n        return cls(name, topic, ack_deadline, push_endpoint)\n\n    @property\n    def path(self):\n        \"\"\"URL path for the subscription's APIs\"\"\"\n        project = self.topic.project\n        return '/projects/%s/subscriptions/%s' % (project, self.name)\n\n    def _require_client(self, client):\n        \"\"\"Check client or verify over-ride.\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the topic of the\n                       current subscription.\n\n        :rtype: :class:`gcloud.pubsub.client.Client`\n        :returns: The client passed in or the currently bound client.\n        \"\"\"\n        if client is None:\n            client = self.topic._client\n        return client\n\n    def create(self, client=None):\n        \"\"\"API call:  create the subscription via a PUT request\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/create\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        data = {'topic': self.topic.full_name}\n\n        if self.ack_deadline is not None:\n            data['ackDeadline'] = self.ack_deadline\n\n        if self.push_endpoint is not None:\n            data['pushConfig'] = {'pushEndpoint': self.push_endpoint}\n\n        client = self._require_client(client)\n        client.connection.api_request(method='PUT', path=self.path, data=data)\n\n    def exists(self, client=None):\n        \"\"\"API call:  test existence of the subscription via a GET request\n\n        See\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/get\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        try:\n            client.connection.api_request(method='GET', path=self.path)\n        except NotFound:\n            return False\n        else:\n            return True\n\n    def reload(self, client=None):\n        \"\"\"API call:  sync local subscription configuration via a GET request\n\n        See\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/get\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = client.connection.api_request(method='GET', path=self.path)\n        self.ack_deadline = data.get('ackDeadline')\n        push_config = data.get('pushConfig', {})\n        self.push_endpoint = push_config.get('pushEndpoint')\n\n    def modify_push_configuration(self, push_endpoint, client=None):\n        \"\"\"API call:  update the push endpoint for the subscription.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/modifyPushConfig\n\n        :type push_endpoint: string\n        :param push_endpoint: URL to which messages will be pushed by the\n                              back-end.  If None, the application must pull\n                              messages.\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = {}\n        config = data['pushConfig'] = {}\n        if push_endpoint is not None:\n            config['pushEndpoint'] = push_endpoint\n        client.connection.api_request(\n            method='POST', path='%s:modifyPushConfig' % (self.path,),\n            data=data)\n        self.push_endpoint = push_endpoint\n\n    def pull(self, return_immediately=False, max_messages=1, client=None):\n        \"\"\"API call:  retrieve messages for the subscription.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/pull\n\n        :type return_immediately: boolean\n        :param return_immediately: if True, the back-end returns even if no\n                                   messages are available;  if False, the API\n                                   call blocks until one or more messages are\n                                   available.\n\n        :type max_messages: int\n        :param max_messages: the maximum number of messages to return.\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n\n        :rtype: list of (ack_id, message) tuples\n        :returns: sequence of tuples: ``ack_id`` is the ID to be used in a\n                  subsequent call to :meth:`acknowledge`, and ``message``\n                  is an instance of :class:`gcloud.pubsub.message.Message`.\n        \"\"\"\n        client = self._require_client(client)\n        data = {'returnImmediately': return_immediately,\n                'maxMessages': max_messages}\n        response = client.connection.api_request(\n            method='POST', path='%s:pull' % (self.path,), data=data)\n        return [(info['ackId'], Message.from_api_repr(info['message']))\n                for info in response.get('receivedMessages', ())]\n\n    def acknowledge(self, ack_ids, client=None):\n        \"\"\"API call:  acknowledge retrieved messages for the subscription.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/acknowledge\n\n        :type ack_ids: list of string\n        :param ack_ids: ack IDs of messages being acknowledged\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = {'ackIds': ack_ids}\n        client.connection.api_request(\n            method='POST', path='%s:acknowledge' % (self.path,), data=data)\n\n    def modify_ack_deadline(self, ack_id, ack_deadline, client=None):\n        \"\"\"API call:  update acknowledgement deadline for a retrieved message.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/acknowledge\n\n        :type ack_id: string\n        :param ack_id: ack ID of message being updated\n\n        :type ack_deadline: int\n        :param ack_deadline: new deadline for the message, in seconds\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = {'ackIds': [ack_id], 'ackDeadlineSeconds': ack_deadline}\n        client.connection.api_request(\n            method='POST', path='%s:modifyAckDeadline' % (self.path,),\n            data=data)\n\n    def delete(self, client=None):\n        \"\"\"API call:  delete the subscription via a DELETE request.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/delete\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        client.connection.api_request(method='DELETE', path=self.path)\n", "path": "gcloud/pubsub/subscription.py"}], "after_files": [{"content": "# Copyright 2015 Google Inc. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Define API Subscriptions.\"\"\"\n\nfrom gcloud.exceptions import NotFound\nfrom gcloud.pubsub._helpers import topic_name_from_path\nfrom gcloud.pubsub.message import Message\n\n\nclass Subscription(object):\n    \"\"\"Subscriptions receive messages published to their topics.\n\n    See:\n    https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions\n\n    :type name: string\n    :param name: the name of the subscription\n\n    :type topic: :class:`gcloud.pubsub.topic.Topic`\n    :param topic: the topic to which the subscription belongs..\n\n    :type ack_deadline: int\n    :param ack_deadline: the deadline (in seconds) by which messages pulled\n                         from the back-end must be acknowledged.\n\n    :type push_endpoint: string\n    :param push_endpoint: URL to which messages will be pushed by the back-end.\n                          If not set, the application must pull messages.\n    \"\"\"\n    def __init__(self, name, topic, ack_deadline=None, push_endpoint=None):\n        self.name = name\n        self.topic = topic\n        self.ack_deadline = ack_deadline\n        self.push_endpoint = push_endpoint\n\n    @classmethod\n    def from_api_repr(cls, resource, client, topics=None):\n        \"\"\"Factory:  construct a topic given its API representation\n\n        :type resource: dict\n        :param resource: topic resource representation returned from the API\n\n        :type client: :class:`gcloud.pubsub.client.Client`\n        :param client: Client which holds credentials and project\n                       configuration for a topic.\n\n        :type topics: dict or None\n        :param topics: A mapping of topic names -> topics.  If not passed,\n                       the subscription will have a newly-created topic.\n\n        :rtype: :class:`gcloud.pubsub.subscription.Subscription`\n        :returns: Subscription parsed from ``resource``.\n        \"\"\"\n        if topics is None:\n            topics = {}\n        topic_path = resource['topic']\n        topic = topics.get(topic_path)\n        if topic is None:\n            # NOTE: This duplicates behavior from Topic.from_api_repr to avoid\n            #       an import cycle.\n            topic_name = topic_name_from_path(topic_path, client.project)\n            topic = topics[topic_path] = client.topic(topic_name)\n        _, _, _, name = resource['name'].split('/')\n        ack_deadline = resource.get('ackDeadlineSeconds')\n        push_config = resource.get('pushConfig', {})\n        push_endpoint = push_config.get('pushEndpoint')\n        return cls(name, topic, ack_deadline, push_endpoint)\n\n    @property\n    def path(self):\n        \"\"\"URL path for the subscription's APIs\"\"\"\n        project = self.topic.project\n        return '/projects/%s/subscriptions/%s' % (project, self.name)\n\n    def _require_client(self, client):\n        \"\"\"Check client or verify over-ride.\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the topic of the\n                       current subscription.\n\n        :rtype: :class:`gcloud.pubsub.client.Client`\n        :returns: The client passed in or the currently bound client.\n        \"\"\"\n        if client is None:\n            client = self.topic._client\n        return client\n\n    def create(self, client=None):\n        \"\"\"API call:  create the subscription via a PUT request\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/create\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        data = {'topic': self.topic.full_name}\n\n        if self.ack_deadline is not None:\n            data['ackDeadlineSeconds'] = self.ack_deadline\n\n        if self.push_endpoint is not None:\n            data['pushConfig'] = {'pushEndpoint': self.push_endpoint}\n\n        client = self._require_client(client)\n        client.connection.api_request(method='PUT', path=self.path, data=data)\n\n    def exists(self, client=None):\n        \"\"\"API call:  test existence of the subscription via a GET request\n\n        See\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/get\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        try:\n            client.connection.api_request(method='GET', path=self.path)\n        except NotFound:\n            return False\n        else:\n            return True\n\n    def reload(self, client=None):\n        \"\"\"API call:  sync local subscription configuration via a GET request\n\n        See\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/get\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = client.connection.api_request(method='GET', path=self.path)\n        self.ack_deadline = data.get('ackDeadlineSeconds')\n        push_config = data.get('pushConfig', {})\n        self.push_endpoint = push_config.get('pushEndpoint')\n\n    def modify_push_configuration(self, push_endpoint, client=None):\n        \"\"\"API call:  update the push endpoint for the subscription.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/modifyPushConfig\n\n        :type push_endpoint: string\n        :param push_endpoint: URL to which messages will be pushed by the\n                              back-end.  If None, the application must pull\n                              messages.\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = {}\n        config = data['pushConfig'] = {}\n        if push_endpoint is not None:\n            config['pushEndpoint'] = push_endpoint\n        client.connection.api_request(\n            method='POST', path='%s:modifyPushConfig' % (self.path,),\n            data=data)\n        self.push_endpoint = push_endpoint\n\n    def pull(self, return_immediately=False, max_messages=1, client=None):\n        \"\"\"API call:  retrieve messages for the subscription.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/pull\n\n        :type return_immediately: boolean\n        :param return_immediately: if True, the back-end returns even if no\n                                   messages are available;  if False, the API\n                                   call blocks until one or more messages are\n                                   available.\n\n        :type max_messages: int\n        :param max_messages: the maximum number of messages to return.\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n\n        :rtype: list of (ack_id, message) tuples\n        :returns: sequence of tuples: ``ack_id`` is the ID to be used in a\n                  subsequent call to :meth:`acknowledge`, and ``message``\n                  is an instance of :class:`gcloud.pubsub.message.Message`.\n        \"\"\"\n        client = self._require_client(client)\n        data = {'returnImmediately': return_immediately,\n                'maxMessages': max_messages}\n        response = client.connection.api_request(\n            method='POST', path='%s:pull' % (self.path,), data=data)\n        return [(info['ackId'], Message.from_api_repr(info['message']))\n                for info in response.get('receivedMessages', ())]\n\n    def acknowledge(self, ack_ids, client=None):\n        \"\"\"API call:  acknowledge retrieved messages for the subscription.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/acknowledge\n\n        :type ack_ids: list of string\n        :param ack_ids: ack IDs of messages being acknowledged\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = {'ackIds': ack_ids}\n        client.connection.api_request(\n            method='POST', path='%s:acknowledge' % (self.path,), data=data)\n\n    def modify_ack_deadline(self, ack_id, ack_deadline, client=None):\n        \"\"\"API call:  update acknowledgement deadline for a retrieved message.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/acknowledge\n\n        :type ack_id: string\n        :param ack_id: ack ID of message being updated\n\n        :type ack_deadline: int\n        :param ack_deadline: new deadline for the message, in seconds\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        data = {'ackIds': [ack_id], 'ackDeadlineSeconds': ack_deadline}\n        client.connection.api_request(\n            method='POST', path='%s:modifyAckDeadline' % (self.path,),\n            data=data)\n\n    def delete(self, client=None):\n        \"\"\"API call:  delete the subscription via a DELETE request.\n\n        See:\n        https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/subscriptions/delete\n\n        :type client: :class:`gcloud.pubsub.client.Client` or ``NoneType``\n        :param client: the client to use.  If not passed, falls back to the\n                       ``client`` stored on the current subscription's topic.\n        \"\"\"\n        client = self._require_client(client)\n        client.connection.api_request(method='DELETE', path=self.path)\n", "path": "gcloud/pubsub/subscription.py"}]}