Added TODO and did PEP 8 cleanup.
diff --git a/samples/cmdline/buzz.py b/samples/cmdline/buzz.py
index 9a0a909..e6b2ff4 100644
--- a/samples/cmdline/buzz.py
+++ b/samples/cmdline/buzz.py
@@ -10,38 +10,14 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
-# TODO
-# - Add normalize_ that converts max-results into MaxResults
-#
-# - Each 'resource' should be its own object accessible
-# from the service object returned from discovery.
-#
-# - Methods can either execute immediately or return
-# RestRequest objects which can be batched.
-#
-# - 'Body' parameter for non-GET requests
-#
-# - 2.x and 3.x compatible
-
-# JS also has the idea of a TransportRequest and a Transport.
-# The Transport has a doRequest() method that takes a request
-# and a callback function.
-#
-
-
-# Discovery doc notes
-# - Which parameters are optional vs mandatory
-# - Is pattern a regex?
-# - Inconsistent naming max-results vs userId
-
from apiclient.discovery import build
import httplib2
-import simplejson
-import re
-
import oauth2 as oauth
+import re
+import simplejson
+
def oauth_wrap(consumer, token, http):
"""
@@ -51,7 +27,7 @@
Returns:
A modified instance of http that was passed in.
-
+
Example:
h = httplib2.Http()
@@ -61,14 +37,15 @@
subclass of httplib2.Authenication because
it never gets passed the absolute URI, which is
needed for signing. So instead we have to overload
- 'request' with a closure that adds in the
+ 'request' with a closure that adds in the
Authorization header and then calls the original version
of 'request()'.
"""
request_orig = http.request
signer = oauth.SignatureMethod_HMAC_SHA1()
- def new_request(uri, method="GET", body=None, headers=None, redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
+ def new_request(uri, method="GET", body=None, headers=None,
+ redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
"""Modify the request headers to add the appropriate
Authorization header."""
req = oauth.Request.from_consumer_and_token(
@@ -78,19 +55,23 @@
headers = {}
headers.update(req.to_header())
headers['user-agent'] = 'jcgregorio-test-client'
- return request_orig(uri, method, body, headers, redirections, connection_type)
+ return request_orig(uri, method, body, headers,
+ redirections, connection_type)
http.request = new_request
return http
+
def get_wrapped_http():
f = open("oauth_token.dat", "r")
oauth_params = simplejson.loads(f.read())
- consumer = oauth.Consumer(oauth_params['consumer_key'], oauth_params['consumer_secret'])
- token = oauth.Token(oauth_params['oauth_token'], oauth_params['oauth_token_secret'])
+ consumer = oauth.Consumer(
+ oauth_params['consumer_key'], oauth_params['consumer_secret'])
+ token = oauth.Token(
+ oauth_params['oauth_token'], oauth_params['oauth_token_secret'])
- # Create a simple monkeypatch for httplib2.Http.request
+ # Create a simple monkeypatch for httplib2.Http.request
# just adds in the oauth authorization header and then calls
# the original request().
http = httplib2.Http()
@@ -99,14 +80,14 @@
def main():
http = get_wrapped_http()
- p = build("buzz", "v1", http = http)
+ p = build("buzz", "v1", http=http)
activities = p.activities()
activitylist = activities.list(scope='@self', userId='@me')
print activitylist['items'][0]['title']
activities.insert(userId='@me', body={
'title': 'Testing insert',
'object': {
- 'content': u'Just a short note to show that insert is working. ☄',
+ 'content': u'Just a short note to show that insert is working. ☄',
'type': 'note'}
}
)