diff --git a/apiclient/discovery.py b/apiclient/discovery.py index 954ad6c..e71e990 100644 --- a/apiclient/discovery.py +++ b/apiclient/discovery.py @@ -99,7 +99,7 @@ class JsonModel(object): return (headers, path_params, query, simplejson.dumps(model)) def build_query(self, params): - params.update({'alt': 'json', 'prettyprint': 'true'}) + params.update({'alt': 'json'}) astuples = [] for key, value in params.iteritems(): if getattr(value, 'encode', False) and callable(value.encode): diff --git a/samples/buzz/buzz.py b/samples/buzz/buzz.py new file mode 100644 index 0000000..14b5ea1 --- /dev/null +++ b/samples/buzz/buzz.py @@ -0,0 +1,66 @@ +#!/usr/bin/python2.4 +# -*- coding: utf-8 -*- +# +# Copyright 2010 Google Inc. All Rights Reserved. + +"""Simple command-line example for Buzz. + +Command-line application that retrieves the users +latest content and then adds a new entry. +""" + +__author__ = 'jcgregorio@google.com (Joe Gregorio)' + +from apiclient.discovery import build + +import httplib2 +import pickle +import pprint + +# Uncomment the next line to get very detailed logging +# httplib2.debuglevel = 4 + +def main(): + f = open("buzz.dat", "r") + credentials = pickle.loads(f.read()) + f.close() + + http = httplib2.Http() + http = credentials.authorize(http) + + p = build("buzz", "v1", http=http) + activities = p.activities() + + # Retrieve the first two activities + activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute() + print "Retrieved the first two activities" + + # Retrieve the next two activities + 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'} + } + activity = activities.insert(userId='@me', body=new_activity_body).execute() + print "Added a new activity" + + activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute() + + # Add a comment to that activity + comment_body = { + "content": "This is a comment" + } + item = activitylist['items'][0] + comment = p.comments().insert( + userId=item['actor']['id'], postId=item['id'], body=comment_body + ).execute() + print 'Added a comment to the new activity' + pprint.pprint(comment) + +if __name__ == '__main__': + main() diff --git a/samples/cmdline/three_legged_dance.py b/samples/buzz/three_legged_dance.py similarity index 94% rename from samples/cmdline/three_legged_dance.py rename to samples/buzz/three_legged_dance.py index ff1d657..9972455 100644 --- a/samples/cmdline/three_legged_dance.py +++ b/samples/buzz/three_legged_dance.py @@ -22,11 +22,6 @@ other example apps in the same directory. __author__ = 'jcgregorio@google.com (Joe Gregorio)' -# Enable this sample to be run from the top-level directory -import os -import sys -sys.path.insert(0, os.getcwd()) - from apiclient.discovery import build from apiclient.oauth import FlowThreeLegged diff --git a/samples/cmdline/buzz.py b/samples/cmdline/buzz.py deleted file mode 100644 index f24c032..0000000 --- a/samples/cmdline/buzz.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/python2.4 -# -*- coding: utf-8 -*- -# -# Copyright 2010 Google Inc. All Rights Reserved. - -"""Simple command-line example for Buzz. - -Command-line application that retrieves the users -latest content and then adds a new entry. -""" - -__author__ = 'jcgregorio@google.com (Joe Gregorio)' - -# Enable this sample to be run from the top-level directory -import os -import sys -sys.path.insert(0, os.getcwd()) - -from apiclient.discovery import build - -import httplib2 -# httplib2.debuglevel = 4 -import pickle -import pprint - -def main(): - f = open("buzz.dat", "r") - credentials = pickle.loads(f.read()) - f.close() - - http = httplib2.Http() - http = credentials.authorize(http) - - p = build("buzz", "v1", http=http) - activities = p.activities() - activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute() - print activitylist['items'][0]['title'] - activitylist = activities.list_next(activitylist).execute() - print activitylist['items'][0]['title'] - - activity = activities.insert(userId='@me', body={ - 'title': 'Testing insert', - 'object': { - 'content': u'Just a short note to show that insert is working. ☄', - 'type': 'note'} - } - ).execute() - pprint.pprint(activity) - print - print 'Just created: ', activity['links']['alternate'][0]['href'] - -if __name__ == '__main__': - main() diff --git a/samples/cmdline/moderator.py b/samples/moderator/moderator.py similarity index 100% rename from samples/cmdline/moderator.py rename to samples/moderator/moderator.py diff --git a/samples/cmdline/three_legged_dance_moderator.py b/samples/moderator/three_legged_dance.py similarity index 100% rename from samples/cmdline/three_legged_dance_moderator.py rename to samples/moderator/three_legged_dance.py