Clean up buzz example so it is just one file.
diff --git a/Makefile b/Makefile
index ef0ec30..75d64b5 100644
--- a/Makefile
+++ b/Makefile
@@ -2,4 +2,4 @@
find apiclient samples -name "*.py" | xargs pep8 --ignore=E111,E202
test:
- python runtests.py
+ python runtests.py tests
diff --git a/apiclient/ext/authtools.py b/apiclient/ext/authtools.py
index 5398bd8..f605d72 100644
--- a/apiclient/ext/authtools.py
+++ b/apiclient/ext/authtools.py
@@ -138,3 +138,5 @@
f.write(pickle.dumps(credentials))
f.close()
print "You have successfully authenticated."
+
+ return credentials
diff --git a/samples/buzz/buzz.py b/samples/buzz/buzz.py
index 72ef991..a82cfc7 100644
--- a/samples/buzz/buzz.py
+++ b/samples/buzz/buzz.py
@@ -12,6 +12,9 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
from apiclient.discovery import build
+from apiclient.oauth import FlowThreeLegged
+from apiclient.ext.authtools import run
+
import httplib2
import pickle
@@ -22,9 +25,22 @@
def main():
- f = open("buzz.dat", "r")
- credentials = pickle.loads(f.read())
- f.close()
+ try:
+ f = open("buzz.dat", "r")
+ credentials = pickle.loads(f.read())
+ f.close()
+ except:
+ buzz_discovery = build("buzz", "v1").auth_discovery()
+
+ flow = FlowThreeLegged(buzz_discovery,
+ consumer_key='anonymous',
+ consumer_secret='anonymous',
+ user_agent='google-api-client-python-buzz-cmdline/1.0',
+ domain='anonymous',
+ scope='https://www.googleapis.com/auth/buzz',
+ xoauth_displayname='Google API Client Example App')
+
+ credentials = run(flow, 'buzz.dat')
http = httplib2.Http()
http = credentials.authorize(http)
diff --git a/samples/buzz/three_legged_dance.py b/samples/buzz/three_legged_dance.py
deleted file mode 100644
index 2dc26e5..0000000
--- a/samples/buzz/three_legged_dance.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2010 Google Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Do the OAuth 1.0a three legged dance.
-
-Do the OAuth 1.0a three legged dance for
-a Buzz command line application. Store the generated
-credentials in a common file that is used by
-other example apps in the same directory.
-"""
-
-__author__ = 'jcgregorio@google.com (Joe Gregorio)'
-
-from apiclient.discovery import build
-from apiclient.oauth import FlowThreeLegged
-from apiclient.ext.authtools import run
-
-
-buzz_discovery = build("buzz", "v1").auth_discovery()
-
-flow = FlowThreeLegged(buzz_discovery,
- consumer_key='anonymous',
- consumer_secret='anonymous',
- user_agent='google-api-client-python-buzz-cmdline/1.0',
- domain='anonymous',
- scope='https://www.googleapis.com/auth/buzz',
- xoauth_displayname='Google API Client Example App')
-
-run(flow, 'buzz.dat')