Fix for a temporary problem with discovery documents. Now query vs path parameters are inferred from the restPath.
diff --git a/apiclient/discovery.py b/apiclient/discovery.py
index db042f7..1660288 100644
--- a/apiclient/discovery.py
+++ b/apiclient/discovery.py
@@ -35,6 +35,9 @@
from apiclient.http import HttpRequest
from apiclient.json import simplejson
+URITEMPLATE = re.compile('{[^}]*}')
+VARNAME = re.compile('[a-zA-Z0-9_-]+')
+
class Error(Exception):
"""Base error for this module."""
pass
@@ -215,6 +218,13 @@
if desc.get('restParameterType') == 'path':
path_params[param] = param
+ for match in URITEMPLATE.finditer(pathUrl):
+ for namematch in VARNAME.finditer(match.group(0)):
+ name = key2param(namematch.group(0))
+ path_params[name] = name
+ if name in query_params:
+ query_params.remove(name)
+
def method(self, **kwargs):
for name in kwargs.iterkeys():
if name not in argmap:
diff --git a/functional_tests/test_services.py b/functional_tests/test_services.py
index cf35d8f..8a20d3f 100644
--- a/functional_tests/test_services.py
+++ b/functional_tests/test_services.py
@@ -124,7 +124,8 @@
buzz = build('buzz', 'v1')
# Restricting max_results to 1 means only a tiny amount of data comes back but the totalResults still has the total.
- following = buzz.people().list(userId='googlebuzz', groupId='@followers', max_results=1).execute()
+ following = buzz.people().list(userId='googlebuzz', groupId='@followers',
+ max_results='1').execute()
# @googlebuzz has a large but fluctuating number of followers
# It is sufficient if the result is bigger than 10, 000
@@ -152,11 +153,13 @@
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
- 'title': 'Testing insert',
- 'object': {
- 'content': u'Just a short note to show that insert is working. ?',
- 'type': 'note'}
- }
+ 'data': {
+ 'title': 'Testing insert',
+ 'object': {
+ 'content': u'Just a short note to show that insert is working. ?',
+ 'type': 'note'}
+ }
+ }
).execute()
self.assertTrue(activity is not None)
@@ -164,16 +167,18 @@
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
- 'title': 'Testing insert',
- 'object': {
- 'content': 'This is a private post.'
- },
- 'visibility': {
- 'entries': [
- { 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
- ]
- }
- }
+ 'data': {
+ 'title': 'Testing insert',
+ 'object': {
+ 'content': 'This is a private post.'
+ },
+ 'visibility': {
+ 'entries': [
+ { 'id': 'tag:google.com,2010:buzz-group:108242092577082601423:13' }
+ ]
+ }
+ }
+ }
).execute()
self.assertTrue(activity is not None)
@@ -201,11 +206,13 @@
def IGNORE__test_can_like_activity(self):
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
- 'title': 'Testing insert',
- 'object': {
- 'content': u'Just a short note to show that insert is working. ?',
- 'type': 'note'}
- }
+ 'data': {
+ 'title': 'Testing insert',
+ 'object': {
+ 'content': u'Just a short note to show that insert is working. ?',
+ 'type': 'note'}
+ }
+ }
).execute()
pprint.pprint(activity)
id = activity['id']
@@ -216,16 +223,20 @@
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
- 'title': 'A new activity',
- 'object': {
- 'content': u'The body of the new activity',
- 'type': 'note'}
- }
+ 'data': {
+ 'title': 'A new activity',
+ 'object': {
+ 'content': u'The body of the new activity',
+ 'type': 'note'}
+ }
+ }
).execute()
id = activity['id']
comment = buzz.comments().insert(userId='@me', postId=id, body={
- "content": "A comment on the new activity"
+ 'data': {
+ 'content': 'A comment on the new activity'
+ }
}).execute()
def test_can_list_groups_belonging_to_user(self):
@@ -248,11 +259,13 @@
buzz = build('buzz', 'v1', http=self.http)
activity = buzz.activities().insert(userId='@me', body={
- 'title': 'Activity to be deleted',
- 'object': {
- 'content': u'Created this activity so that it can be deleted.',
- 'type': 'note'}
- }
+ 'data': {
+ 'title': 'Activity to be deleted',
+ 'object': {
+ 'content': u'Created this activity so that it can be deleted.',
+ 'type': 'note'}
+ }
+ }
).execute()
id = activity['id']
diff --git a/samples/buzz/buzz.py b/samples/buzz/buzz.py
index 94cba2a..9cebd79 100644
--- a/samples/buzz/buzz.py
+++ b/samples/buzz/buzz.py
@@ -18,7 +18,7 @@
import pprint
# Uncomment the next line to get very detailed logging
-# httplib2.debuglevel = 4
+#httplib2.debuglevel = 4
def main():
f = open("buzz.dat", "r")
@@ -56,7 +56,9 @@
# Add a comment to that activity
comment_body = {
+ "data": {
"content": "This is a comment"
+ }
}
item = activitylist['items'][0]
comment = p.comments().insert(