Skip to content

Commit bc2ff9b

Browse files
committed
Fix for a temporary problem with discovery documents. Now query vs path parameters are inferred from the restPath.
1 parent 913e70d commit bc2ff9b

3 files changed

Lines changed: 58 additions & 33 deletions

File tree

apiclient/discovery.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
from apiclient.http import HttpRequest
3636
from apiclient.json import simplejson
3737

38+
URITEMPLATE = re.compile('{[^}]*}')
39+
VARNAME = re.compile('[a-zA-Z0-9_-]+')
40+
3841
class Error(Exception):
3942
"""Base error for this module."""
4043
pass
@@ -215,6 +218,13 @@ def createMethod(theclass, methodName, methodDesc, futureDesc):
215218
if desc.get('restParameterType') == 'path':
216219
path_params[param] = param
217220

221+
for match in URITEMPLATE.finditer(pathUrl):
222+
for namematch in VARNAME.finditer(match.group(0)):
223+
name = key2param(namematch.group(0))
224+
path_params[name] = name
225+
if name in query_params:
226+
query_params.remove(name)
227+
218228
def method(self, **kwargs):
219229
for name in kwargs.iterkeys():
220230
if name not in argmap:

functional_tests/test_services.py

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def test_can_efficiently_get_follower_count_of_user(self):
124124
buzz = build('buzz', 'v1')
125125

126126
# Restricting max_results to 1 means only a tiny amount of data comes back but the totalResults still has the total.
127-
following = buzz.people().list(userId='googlebuzz', groupId='@followers', max_results=1).execute()
127+
following = buzz.people().list(userId='googlebuzz', groupId='@followers',
128+
max_results='1').execute()
128129

129130
# @googlebuzz has a large but fluctuating number of followers
130131
# It is sufficient if the result is bigger than 10, 000
@@ -152,28 +153,32 @@ def test_can_create_activity(self):
152153
buzz = build('buzz', 'v1', http=self.http)
153154

154155
activity = buzz.activities().insert(userId='@me', body={
155-
'title': 'Testing insert',
156-
'object': {
157-
'content': u'Just a short note to show that insert is working. ?',
158-
'type': 'note'}
159-
}
156+
'data': {
157+
'title': 'Testing insert',
158+
'object': {
159+
'content': u'Just a short note to show that insert is working. ?',
160+
'type': 'note'}
161+
}
162+
}
160163
).execute()
161164
self.assertTrue(activity is not None)
162165

163166
def test_can_create_private_activity(self):
164167
buzz = build('buzz', 'v1', http=self.http)
165168

166169
activity = buzz.activities().insert(userId='@me', body={
167-
'title': 'Testing insert',
168-
'object': {
169-
'content': 'This is a private post.'
170-
},
171-
'visibility': {
172-
'entries': [
173-
{ 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
174-
]
175-
}
176-
}
170+
'data': {
171+
'title': 'Testing insert',
172+
'object': {
173+
'content': 'This is a private post.'
174+
},
175+
'visibility': {
176+
'entries': [
177+
{ 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
178+
]
179+
}
180+
}
181+
}
177182
).execute()
178183
self.assertTrue(activity is not None)
179184

@@ -201,11 +206,13 @@ def test_can_identify_number_of_groups_belonging_to_user(self):
201206
def IGNORE__test_can_like_activity(self):
202207
buzz = build('buzz', 'v1', http=self.http)
203208
activity = buzz.activities().insert(userId='@me', body={
204-
'title': 'Testing insert',
205-
'object': {
206-
'content': u'Just a short note to show that insert is working. ?',
207-
'type': 'note'}
208-
}
209+
'data': {
210+
'title': 'Testing insert',
211+
'object': {
212+
'content': u'Just a short note to show that insert is working. ?',
213+
'type': 'note'}
214+
}
215+
}
209216
).execute()
210217
pprint.pprint(activity)
211218
id = activity['id']
@@ -216,16 +223,20 @@ def test_can_comment_on_activity(self):
216223
buzz = build('buzz', 'v1', http=self.http)
217224

218225
activity = buzz.activities().insert(userId='@me', body={
219-
'title': 'A new activity',
220-
'object': {
221-
'content': u'The body of the new activity',
222-
'type': 'note'}
223-
}
226+
'data': {
227+
'title': 'A new activity',
228+
'object': {
229+
'content': u'The body of the new activity',
230+
'type': 'note'}
231+
}
232+
}
224233
).execute()
225234

226235
id = activity['id']
227236
comment = buzz.comments().insert(userId='@me', postId=id, body={
228-
"content": "A comment on the new activity"
237+
'data': {
238+
'content': 'A comment on the new activity'
239+
}
229240
}).execute()
230241

231242
def test_can_list_groups_belonging_to_user(self):
@@ -248,11 +259,13 @@ def test_can_delete_activity(self):
248259
buzz = build('buzz', 'v1', http=self.http)
249260

250261
activity = buzz.activities().insert(userId='@me', body={
251-
'title': 'Activity to be deleted',
252-
'object': {
253-
'content': u'Created this activity so that it can be deleted.',
254-
'type': 'note'}
255-
}
262+
'data': {
263+
'title': 'Activity to be deleted',
264+
'object': {
265+
'content': u'Created this activity so that it can be deleted.',
266+
'type': 'note'}
267+
}
268+
}
256269
).execute()
257270
id = activity['id']
258271

samples/buzz/buzz.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pprint
1919

2020
# Uncomment the next line to get very detailed logging
21-
# httplib2.debuglevel = 4
21+
#httplib2.debuglevel = 4
2222

2323
def main():
2424
f = open("buzz.dat", "r")
@@ -56,7 +56,9 @@ def main():
5656

5757
# Add a comment to that activity
5858
comment_body = {
59+
"data": {
5960
"content": "This is a comment"
61+
}
6062
}
6163
item = activitylist['items'][0]
6264
comment = p.comments().insert(

0 commit comments

Comments
 (0)