From 913e70d2255481765da2a5a7e484cf3b78f27f7b Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Fri, 5 Nov 2010 15:38:23 -0400 Subject: [PATCH] No longer adding in the 'data' wrapper object if it is missing, as some APIs don't use it. --- apiclient/discovery.py | 6 +----- samples/buzz/buzz.py | 15 +++++++++------ samples/moderator/moderator.py | 2 ++ samples/threadqueue/main.py | 8 +++++--- tests/test_json_model.py | 4 ++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/apiclient/discovery.py b/apiclient/discovery.py index fe98db1..db042f7 100644 --- a/apiclient/discovery.py +++ b/apiclient/discovery.py @@ -88,12 +88,8 @@ class JsonModel(object): if body_value is None: return (headers, path_params, query, None) else: - if len(body_value) == 1 and 'data' in body_value: - model = body_value - else: - model = {'data': body_value} headers['content-type'] = 'application/json' - return (headers, path_params, query, simplejson.dumps(model)) + return (headers, path_params, query, simplejson.dumps(body_value)) def build_query(self, params): params.update({'alt': 'json'}) diff --git a/samples/buzz/buzz.py b/samples/buzz/buzz.py index a49e3a6..94cba2a 100644 --- a/samples/buzz/buzz.py +++ b/samples/buzz/buzz.py @@ -36,15 +36,18 @@ def main(): print "Retrieved the first two activities" # Retrieve the next two activities - activitylist = activities.list_next(activitylist).execute() - print "Retrieved the next two activities" + if activitylist: + activitylist = activities.list_next(activitylist).execute() + print "Retrieved the next two activities" # Add a new activity new_activity_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'} + } } activity = activities.insert(userId='@me', body=new_activity_body).execute() print "Added a new activity" diff --git a/samples/moderator/moderator.py b/samples/moderator/moderator.py index 3d742e8..da8d344 100644 --- a/samples/moderator/moderator.py +++ b/samples/moderator/moderator.py @@ -31,9 +31,11 @@ def main(): p = build("moderator", "v1", http=http) series_body = { + "data": { "description": "Share and rank tips for eating healthily on the cheaps!", "name": "Eating Healthy & Cheap", "videoSubmissionAllowed": False + } } series = p.series().insert(body=series_body).execute() print "Created a new series" diff --git a/samples/threadqueue/main.py b/samples/threadqueue/main.py index 5e9314e..1b3b6af 100644 --- a/samples/threadqueue/main.py +++ b/samples/threadqueue/main.py @@ -81,9 +81,11 @@ def main(): p = build("moderator", "v1", http=http) series_body = { - "description": "An example of bulk creating topics", - "name": "Using threading and queues", - "videoSubmissionAllowed": False + "data": { + "description": "An example of bulk creating topics", + "name": "Using threading and queues", + "videoSubmissionAllowed": False + } } series = p.series().insert(body=series_body).execute() print "Created a new series" diff --git a/tests/test_json_model.py b/tests/test_json_model.py index 2bf0302..5ce9b63 100644 --- a/tests/test_json_model.py +++ b/tests/test_json_model.py @@ -62,7 +62,7 @@ class Model(unittest.TestCase): self.assertEqual(headers['accept'], 'application/json') self.assertEqual(headers['content-type'], 'application/json') self.assertNotEqual(query, '') - self.assertEqual(body, '{"data": {}}') + self.assertEqual(body, '{}') def test_json_body_default_data(self): """Test that a 'data' wrapper doesn't get added if one is already present.""" @@ -96,7 +96,7 @@ class Model(unittest.TestCase): query_dict = parse_qs(query) self.assertEqual(query_dict['foo'], ['1']) self.assertEqual(query_dict['bar'], [u'\N{COMET}'.encode('utf-8')]) - self.assertEqual(body, '{"data": {}}') + self.assertEqual(body, '{}') def test_user_agent(self): model = JsonModel()