Finish adding Storage to the OAuth 1.0 client and updated all examples to use file.Storage. No more three_legged_dance.py files anywhere.
diff --git a/apiclient/ext/authtools.py b/apiclient/ext/authtools.py
index f605d72..c383811 100644
--- a/apiclient/ext/authtools.py
+++ b/apiclient/ext/authtools.py
@@ -76,12 +76,21 @@
pass
-def run(flow, filename):
+def run(flow, storage):
"""Core code for a command-line application.
+
+ Args:
+ flow: Flow, an OAuth 1.0 Flow to step through.
+ storage: Storage, a Storage to store the credential in.
+
+ Returns:
+ Credentials, the obtained credential.
+
+ Exceptions:
+ RequestError: if step2 of the flow fails.
+ Args:
"""
parser = OptionParser()
- parser.add_option("-f", "--file", dest="filename",
- default=filename, help="write credentials to FILE", metavar="FILE")
parser.add_option("-p", "--no_local_web_server", dest="localhost",
action="store_false",
default=True,
@@ -134,9 +143,8 @@
except RequestError:
sys.exit('The authentication has failed.')
- f = open(filename, 'w')
- f.write(pickle.dumps(credentials))
- f.close()
+ storage.put(credentials)
+ credentials.set_store(storage.put)
print "You have successfully authenticated."
return credentials
diff --git a/apiclient/ext/file.py b/apiclient/ext/file.py
index 0a2c97c..dba723e 100644
--- a/apiclient/ext/file.py
+++ b/apiclient/ext/file.py
@@ -28,9 +28,9 @@
f = open(self._filename, 'r')
credentials = pickle.loads(f.read())
f.close()
+ credentials.set_store(self.put)
except:
credentials = None
- credentials.set_store(self.put)
return credentials
diff --git a/docs/apiclient.anyjson.html b/docs/apiclient.anyjson.html
index df64fcd..7471a08 100644
--- a/docs/apiclient.anyjson.html
+++ b/docs/apiclient.anyjson.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.anyjson</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/anyjson.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/anyjson.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/anyjson.py">/home/jcgregorio/projects/apiary/apiclient/anyjson.py</a></font></td></tr></table>
<p><tt>Utility module to import a JSON module<br>
<br>
Hides all the messy details of exactly where<br>
diff --git a/docs/apiclient.contrib.html b/docs/apiclient.contrib.html
index 488fdaa..7ac2858 100644
--- a/docs/apiclient.contrib.html
+++ b/docs/apiclient.contrib.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.contrib</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/contrib/__init__.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/contrib/__init__.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/contrib/__init__.py">/home/jcgregorio/projects/apiary/apiclient/contrib/__init__.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
diff --git a/docs/apiclient.discovery.html b/docs/apiclient.discovery.html
index a192d16..f92de50 100644
--- a/docs/apiclient.discovery.html
+++ b/docs/apiclient.discovery.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.discovery</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/discovery.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/discovery.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/discovery.py">/home/jcgregorio/projects/apiary/apiclient/discovery.py</a></font></td></tr></table>
<p><tt>Client for discovery based APIs<br>
<br>
A client library for Google's discovery based APIs.</tt></p>
@@ -34,7 +34,7 @@
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
-<td width="100%"><dl><dt><a name="-build"><strong>build</strong></a>(serviceName, version, http<font color="#909090">=None</font>, discoveryServiceUrl<font color="#909090">='https://www.googleapis.com/discovery/v0.2beta1/describe/{api}/{apiVersion}'</font>, developerKey<font color="#909090">=None</font>, model<font color="#909090">=<apiclient.model.JsonModel object></font>, requestBuilder<font color="#909090">=<class 'apiclient.http.HttpRequest'></font>)</dt><dd><tt>Construct a Resource for interacting with an API.<br>
+<td width="100%"><dl><dt><a name="-build"><strong>build</strong></a>(serviceName, version, http<font color="#909090">=None</font>, discoveryServiceUrl<font color="#909090">='https://www.googleapis.com/discovery/v0.3/describe/{api}/{apiVersion}'</font>, developerKey<font color="#909090">=None</font>, model<font color="#909090">=<apiclient.model.JsonModel object></font>, requestBuilder<font color="#909090">=<class 'apiclient.http.HttpRequest'></font>)</dt><dd><tt>Construct a Resource for interacting with an API.<br>
<br>
Construct a Resource object for interacting with<br>
an API. The serviceName and version are the<br>
diff --git a/docs/apiclient.errors.html b/docs/apiclient.errors.html
index 037040f..f439bc0 100644
--- a/docs/apiclient.errors.html
+++ b/docs/apiclient.errors.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.errors</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/errors.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/errors.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/errors.py">/home/jcgregorio/projects/apiary/apiclient/errors.py</a></font></td></tr></table>
<p><tt>Errors for the library.<br>
<br>
All exceptions defined by the library<br>
diff --git a/docs/apiclient.ext.appengine.html b/docs/apiclient.ext.appengine.html
index b5aafca..6604c00 100644
--- a/docs/apiclient.ext.appengine.html
+++ b/docs/apiclient.ext.appengine.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.<a href="apiclient.ext.html"><font color="#ffffff">ext</font></a>.appengine</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/appengine.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/appengine.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/ext/appengine.py">/home/jcgregorio/projects/apiary/apiclient/ext/appengine.py</a></font></td></tr></table>
<p><tt>Utilities for Google App Engine<br>
<br>
Utilities for making it easier to use the<br>
diff --git a/docs/apiclient.ext.authtools.html b/docs/apiclient.ext.authtools.html
index df9e16d..0f9c083 100644
--- a/docs/apiclient.ext.authtools.html
+++ b/docs/apiclient.ext.authtools.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.<a href="apiclient.ext.html"><font color="#ffffff">ext</font></a>.authtools</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/authtools.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/authtools.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/ext/authtools.py">/home/jcgregorio/projects/apiary/apiclient/ext/authtools.py</a></font></td></tr></table>
<p><tt>Command-line tools for authenticating via OAuth 1.0<br>
<br>
Do the OAuth 1.0 Three Legged Dance for<br>
@@ -34,7 +34,18 @@
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
-<td width="100%"><dl><dt><a name="-run"><strong>run</strong></a>(flow, filename)</dt><dd><tt>Core code for a command-line application.</tt></dd></dl>
+<td width="100%"><dl><dt><a name="-run"><strong>run</strong></a>(flow, storage)</dt><dd><tt>Core code for a command-line application.<br>
+ <br>
+Args:<br>
+ flow: Flow, an OAuth 1.0 Flow to step through.<br>
+ storage: Storage, a Storage to store the credential in.<br>
+ <br>
+Returns:<br>
+ Credentials, the obtained credential.<br>
+ <br>
+Exceptions:<br>
+ RequestError: if step2 of the flow fails.<br>
+Args:</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
diff --git a/docs/apiclient.ext.django_orm.html b/docs/apiclient.ext.django_orm.html
index 163f80e..73e8bea 100644
--- a/docs/apiclient.ext.django_orm.html
+++ b/docs/apiclient.ext.django_orm.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.<a href="apiclient.ext.html"><font color="#ffffff">ext</font></a>.django_orm</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/django_orm.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/django_orm.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/ext/django_orm.py">/home/jcgregorio/projects/apiary/apiclient/ext/django_orm.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
diff --git a/docs/apiclient.ext.file.html b/docs/apiclient.ext.file.html
new file mode 100644
index 0000000..3a7ae64
--- /dev/null
+++ b/docs/apiclient.ext.file.html
@@ -0,0 +1,89 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html><head><title>Python: module apiclient.ext.file</title>
+</head><body bgcolor="#f0f0f8">
+
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
+<tr bgcolor="#7799ee">
+<td valign=bottom> <br>
+<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.<a href="apiclient.ext.html"><font color="#ffffff">ext</font></a>.file</strong></big></big></font></td
+><td align=right valign=bottom
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/ext/file.py">/home/jcgregorio/projects/apiary/apiclient/ext/file.py</a></font></td></tr></table>
+ <p><tt>Utilities for OAuth.<br>
+ <br>
+Utilities for making it easier to work with OAuth 1.0 credentials.</tt></p>
+<p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#aa55cc">
+<td colspan=3 valign=bottom> <br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
+
+<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
+<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="pickle.html">pickle</a><br>
+</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ee77aa">
+<td colspan=3 valign=bottom> <br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
+
+<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
+<td width="100%"><dl>
+<dt><font face="helvetica, arial"><a href="apiclient.oauth.html#Storage">apiclient.oauth.Storage</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
+</font></dt><dd>
+<dl>
+<dt><font face="helvetica, arial"><a href="apiclient.ext.file.html#Storage">Storage</a>
+</font></dt></dl>
+</dd>
+</dl>
+ <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom> <br>
+<font color="#000000" face="helvetica, arial"><a name="Storage">class <strong>Storage</strong></a>(<a href="apiclient.oauth.html#Storage">apiclient.oauth.Storage</a>)</font></td></tr>
+
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
+<td colspan=2><tt>Store and retrieve a single credential to and from a file.<br> </tt></td></tr>
+<tr><td> </td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="apiclient.ext.file.html#Storage">Storage</a></dd>
+<dd><a href="apiclient.oauth.html#Storage">apiclient.oauth.Storage</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Methods defined here:<br>
+<dl><dt><a name="Storage-__init__"><strong>__init__</strong></a>(self, filename)</dt></dl>
+
+<dl><dt><a name="Storage-get"><strong>get</strong></a>(self)</dt><dd><tt>Retrieve Credential from file.<br>
+ <br>
+Returns:<br>
+ apiclient.oauth.Credentials</tt></dd></dl>
+
+<dl><dt><a name="Storage-put"><strong>put</strong></a>(self, credentials)</dt><dd><tt>Write a pickled Credentials to file.<br>
+ <br>
+Args:<br>
+ credentials: Credentials, the credentials to store.</tt></dd></dl>
+
+<hr>
+Data descriptors inherited from <a href="apiclient.oauth.html#Storage">apiclient.oauth.Storage</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary for instance variables (if defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list of weak references to the object (if defined)</tt></dd>
+</dl>
+</td></tr></table></td></tr></table><p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#55aa55">
+<td colspan=3 valign=bottom> <br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
+
+<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
+<td width="100%"><strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#7799ee">
+<td colspan=3 valign=bottom> <br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
+
+<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
+<td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table>
+</body></html>
\ No newline at end of file
diff --git a/docs/apiclient.ext.html b/docs/apiclient.ext.html
index 5a7cfbe..d3b597d 100644
--- a/docs/apiclient.ext.html
+++ b/docs/apiclient.ext.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.ext</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/__init__.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/ext/__init__.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/ext/__init__.py">/home/jcgregorio/projects/apiary/apiclient/ext/__init__.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
@@ -20,5 +20,6 @@
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="apiclient.ext.appengine.html">appengine</a><br>
</td><td width="25%" valign=top><a href="apiclient.ext.authtools.html">authtools</a><br>
</td><td width="25%" valign=top><a href="apiclient.ext.django_orm.html">django_orm</a><br>
-</td><td width="25%" valign=top></td></tr></table></td></tr></table>
+</td><td width="25%" valign=top><a href="apiclient.ext.file.html">file</a><br>
+</td></tr></table></td></tr></table>
</body></html>
\ No newline at end of file
diff --git a/docs/apiclient.html b/docs/apiclient.html
index bf91ae5..4e9ce70 100644
--- a/docs/apiclient.html
+++ b/docs/apiclient.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>apiclient</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/__init__.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/__init__.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/__init__.py">/home/jcgregorio/projects/apiary/apiclient/__init__.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
@@ -19,12 +19,11 @@
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="apiclient.anyjson.html">anyjson</a><br>
<a href="apiclient.contrib.html"><strong>contrib</strong> (package)</a><br>
-<a href="apiclient.discovery.html">discovery</a><br>
-</td><td width="25%" valign=top><a href="apiclient.errors.html">errors</a><br>
-<a href="apiclient.ext.html"><strong>ext</strong> (package)</a><br>
+</td><td width="25%" valign=top><a href="apiclient.discovery.html">discovery</a><br>
+<a href="apiclient.errors.html">errors</a><br>
+</td><td width="25%" valign=top><a href="apiclient.ext.html"><strong>ext</strong> (package)</a><br>
<a href="apiclient.http.html">http</a><br>
-</td><td width="25%" valign=top><a href="apiclient.json.html">json</a><br>
-<a href="apiclient.model.html">model</a><br>
+</td><td width="25%" valign=top><a href="apiclient.model.html">model</a><br>
<a href="apiclient.oauth.html">oauth</a><br>
-</td><td width="25%" valign=top></td></tr></table></td></tr></table>
+</td></tr></table></td></tr></table>
</body></html>
\ No newline at end of file
diff --git a/docs/apiclient.http.html b/docs/apiclient.http.html
index 5daef03..a9c5ce4 100644
--- a/docs/apiclient.http.html
+++ b/docs/apiclient.http.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.http</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/http.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/http.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/http.py">/home/jcgregorio/projects/apiary/apiclient/http.py</a></font></td></tr></table>
<p><tt>Classes to encapsulate a single HTTP request.<br>
<br>
The classes implement a command pattern, with every<br>
diff --git a/docs/apiclient.model.html b/docs/apiclient.model.html
index 9a4ae1d..2a6867c 100644
--- a/docs/apiclient.model.html
+++ b/docs/apiclient.model.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.model</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/model.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/model.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/model.py">/home/jcgregorio/projects/apiary/apiclient/model.py</a></font></td></tr></table>
<p><tt><a href="#Model">Model</a> objects for requests and responses.<br>
<br>
Each API may support one or more serializations, such<br>
diff --git a/docs/apiclient.oauth.html b/docs/apiclient.oauth.html
index c99f722..90be756 100644
--- a/docs/apiclient.oauth.html
+++ b/docs/apiclient.oauth.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.oauth</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/oauth.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/oauth.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/oauth.py">/home/jcgregorio/projects/apiary/apiclient/oauth.py</a></font></td></tr></table>
<p><tt>Utilities for OAuth.<br>
<br>
Utilities for making it easier to work with OAuth.</tt></p>
@@ -49,7 +49,8 @@
<dt><font face="helvetica, arial"><a href="apiclient.oauth.html#FlowThreeLegged">FlowThreeLegged</a>
</font></dt></dl>
</dd>
-</dl>
+<dt><font face="helvetica, arial"><a href="apiclient.oauth.html#Storage">Storage</a>
+</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>)
</font></dt><dd>
@@ -57,7 +58,8 @@
<dt><font face="helvetica, arial"><a href="apiclient.oauth.html#Error">Error</a>
</font></dt><dd>
<dl>
-<dt><font face="helvetica, arial"><a href="apiclient.oauth.html#MissingParameter">MissingParameter</a>
+<dt><font face="helvetica, arial"><a href="apiclient.oauth.html#CredentialsInvalidError">CredentialsInvalidError</a>
+</font></dt><dt><font face="helvetica, arial"><a href="apiclient.oauth.html#MissingParameter">MissingParameter</a>
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.oauth.html#RequestError">RequestError</a>
</font></dt></dl>
</dd>
@@ -95,6 +97,65 @@
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
+<font color="#000000" face="helvetica, arial"><a name="CredentialsInvalidError">class <strong>CredentialsInvalidError</strong></a>(<a href="apiclient.oauth.html#Error">Error</a>)</font></td></tr>
+
+<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="apiclient.oauth.html#CredentialsInvalidError">CredentialsInvalidError</a></dd>
+<dd><a href="apiclient.oauth.html#Error">Error</a></dd>
+<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
+<dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Data descriptors inherited from <a href="apiclient.oauth.html#Error">Error</a>:<br>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list of weak references to the object (if defined)</tt></dd>
+</dl>
+<hr>
+Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
+<dl><dt><a name="CredentialsInvalidError-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__init__">__init__</a>(...) initializes x; see x.__class__.__doc__ for signature</tt></dd></dl>
+
+<hr>
+Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
+<dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#CredentialsInvalidError-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl>
+
+<hr>
+Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
+<dl><dt><a name="CredentialsInvalidError-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br>
+ <br>
+Use of negative indices is not supported.</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#CredentialsInvalidError-__str__">__str__</a>() <==> str(x)</tt></dd></dl>
+
+<dl><dt><a name="CredentialsInvalidError-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>
+
+<hr>
+Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+</dl>
+<dl><dt><strong>args</strong></dt>
+</dl>
+<dl><dt><strong>message</strong></dt>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Error">class <strong>Error</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
@@ -292,11 +353,15 @@
</dl>
<hr>
Methods defined here:<br>
+<dl><dt><a name="OAuthCredentials-__getstate__"><strong>__getstate__</strong></a>(self)</dt><dd><tt>Trim the state down to something that can be pickled.</tt></dd></dl>
+
<dl><dt><a name="OAuthCredentials-__init__"><strong>__init__</strong></a>(self, consumer, token, user_agent)</dt><dd><tt>consumer - An instance of oauth.Consumer.<br>
token - An instance of oauth.Token constructed with<br>
the access token and secret.<br>
user_agent - The HTTP User-Agent to provide for this application.</tt></dd></dl>
+<dl><dt><a name="OAuthCredentials-__setstate__"><strong>__setstate__</strong></a>(self, state)</dt><dd><tt>Reconstitute the state of the <a href="__builtin__.html#object">object</a> from being pickled.</tt></dd></dl>
+
<dl><dt><a name="OAuthCredentials-authorize"><strong>authorize</strong></a>(self, http)</dt><dd><tt>Args:<br>
http - An instance of httplib2.Http<br>
or something that acts like it.<br>
@@ -317,6 +382,19 @@
Authorization header and then calls the original version<br>
of 'request()'.</tt></dd></dl>
+<dl><dt><a name="OAuthCredentials-set_store"><strong>set_store</strong></a>(self, store)</dt><dd><tt>Set the storage for the credential.<br>
+ <br>
+Args:<br>
+ store: callable, a callable that when passed a Credential<br>
+ will store the credential back to where it came from.<br>
+ This is needed to store the latest access_token if it<br>
+ has been revoked.</tt></dd></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>invalid</strong></dt>
+<dd><tt>True if the credentials are invalid, such as being revoked.</tt></dd>
+</dl>
<hr>
Data descriptors inherited from <a href="apiclient.oauth.html#Credentials">Credentials</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
@@ -386,6 +464,36 @@
</dl>
<dl><dt><strong>message</strong></dt>
</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom> <br>
+<font color="#000000" face="helvetica, arial"><a name="Storage">class <strong>Storage</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
+
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
+<td colspan=2><tt>Base class for all <a href="#Storage">Storage</a> objects.<br>
+ <br>
+Store and retrieve a single credential.<br> </tt></td></tr>
+<tr><td> </td>
+<td width="100%">Methods defined here:<br>
+<dl><dt><a name="Storage-get"><strong>get</strong></a>(self)</dt><dd><tt>Retrieve credential.<br>
+ <br>
+Returns:<br>
+ apiclient.oauth.<a href="#Credentials">Credentials</a></tt></dd></dl>
+
+<dl><dt><a name="Storage-put"><strong>put</strong></a>(self, credentials)</dt><dd><tt>Write a credential.<br>
+ <br>
+Args:<br>
+ credentials: <a href="#Credentials">Credentials</a>, the credentials to store.</tt></dd></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary for instance variables (if defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list of weak references to the object (if defined)</tt></dd>
+</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
diff --git a/docs/oauth2client.appengine.html b/docs/oauth2client.appengine.html
index 4a491ad..8247e2f 100644
--- a/docs/oauth2client.appengine.html
+++ b/docs/oauth2client.appengine.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.appengine</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/appengine.py">/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/appengine.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/oauth2client/appengine.py">/home/jcgregorio/projects/apiary/oauth2client/appengine.py</a></font></td></tr></table>
<p><tt>Utilities for Google App Engine<br>
<br>
Utilities for making it easier to use OAuth 2.0 on Google App Engine.</tt></p>
diff --git a/docs/oauth2client.client.html b/docs/oauth2client.client.html
index 36bc502..431b96a 100644
--- a/docs/oauth2client.client.html
+++ b/docs/oauth2client.client.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.client</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/client.py">/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/client.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/oauth2client/client.py">/home/jcgregorio/projects/apiary/oauth2client/client.py</a></font></td></tr></table>
<p><tt>An OAuth 2.0 client<br>
<br>
Tools for interacting with OAuth 2.0 protected<br>
@@ -88,7 +88,7 @@
only the access_token is present it can not be refreshed and will in time<br>
expire.<br>
<br>
-<a href="#OAuth2Credentials">OAuth2Credentials</a> objects may be safely pickled and unpickled.<br>
+<a href="#AccessTokenCredentials">AccessTokenCredentials</a> objects may be safely pickled and unpickled.<br>
<br>
Usage:<br>
credentials = <a href="#AccessTokenCredentials">AccessTokenCredentials</a>('<an access token>',<br>
diff --git a/docs/oauth2client.django_orm.html b/docs/oauth2client.django_orm.html
index 437b1c8..b9d1e03 100644
--- a/docs/oauth2client.django_orm.html
+++ b/docs/oauth2client.django_orm.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.django_orm</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/django_orm.py">/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/django_orm.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/oauth2client/django_orm.py">/home/jcgregorio/projects/apiary/oauth2client/django_orm.py</a></font></td></tr></table>
<p><tt>OAuth 2.0 utilities for Django.<br>
<br>
Utilities for using OAuth 2.0 in conjunction with<br>
diff --git a/docs/oauth2client.file.html b/docs/oauth2client.file.html
index 003db2a..e5c441f 100644
--- a/docs/oauth2client.file.html
+++ b/docs/oauth2client.file.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.file</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/file.py">/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/file.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/oauth2client/file.py">/home/jcgregorio/projects/apiary/oauth2client/file.py</a></font></td></tr></table>
<p><tt>Utilities for OAuth.<br>
<br>
Utilities for making it easier to work with OAuth 2.0<br>
diff --git a/docs/oauth2client.html b/docs/oauth2client.html
index 9ca5fd4..a8f23e0 100644
--- a/docs/oauth2client.html
+++ b/docs/oauth2client.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>oauth2client</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/__init__.py">/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/__init__.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/oauth2client/__init__.py">/home/jcgregorio/projects/apiary/oauth2client/__init__.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
diff --git a/docs/oauth2client.tools.html b/docs/oauth2client.tools.html
index 84fb49d..50e66a7 100644
--- a/docs/oauth2client.tools.html
+++ b/docs/oauth2client.tools.html
@@ -8,7 +8,7 @@
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.tools</strong></big></big></font></td
><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/tools.py">/usr/local/google/home/jcgregorio/projects/apiclient/oauth2client/tools.py</a></font></td></tr></table>
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/oauth2client/tools.py">/home/jcgregorio/projects/apiary/oauth2client/tools.py</a></font></td></tr></table>
<p><tt>Command-line tools for authenticating via OAuth 2.0<br>
<br>
Do the OAuth 2.0 Web Server dance for a command line application. Stores the<br>
@@ -21,7 +21,17 @@
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
-<td width="100%"><dl><dt><a name="-run"><strong>run</strong></a>(flow, storage)</dt><dd><tt>Core code for a command-line application.</tt></dd></dl>
+<td width="100%"><dl><dt><a name="-run"><strong>run</strong></a>(flow, storage)</dt><dd><tt>Core code for a command-line application.<br>
+ <br>
+Args:<br>
+ flow: Flow, an OAuth 2.0 Flow to step through.<br>
+ storage: Storage, a Storage to store the credential in.<br>
+ <br>
+Returns:<br>
+ Credentials, the obtained credential.<br>
+ <br>
+Exceptions:<br>
+ RequestError: if step2 of the flow fails.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
diff --git a/oauth2client/tools.py b/oauth2client/tools.py
index edc8827..bd22416 100644
--- a/oauth2client/tools.py
+++ b/oauth2client/tools.py
@@ -25,6 +25,16 @@
def run(flow, storage):
"""Core code for a command-line application.
+
+ Args:
+ flow: Flow, an OAuth 2.0 Flow to step through.
+ storage: Storage, a Storage to store the credential in.
+
+ Returns:
+ Credentials, the obtained credential.
+
+ Exceptions:
+ RequestError: if step2 of the flow fails.
"""
authorize_url = flow.step1_get_authorize_url('oob')
@@ -37,7 +47,10 @@
accepted = raw_input('Have you authorized me? (y/n) ')
code = raw_input('What is the verification code? ').strip()
- credentials = flow.step2_exchange(code)
+ try:
+ credentials = flow.step2_exchange(code)
+ except RequestError:
+ sys.exit('The authentication has failed.')
storage.put(credentials)
credentials.set_store(storage.put)
diff --git a/samples/buzz/buzz.py b/samples/buzz/buzz.py
index cf3581b..769057e 100644
--- a/samples/buzz/buzz.py
+++ b/samples/buzz/buzz.py
@@ -18,7 +18,6 @@
from apiclient.oauth import CredentialsInvalidError
import httplib2
-import pickle
import pprint
# Uncomment the next line to get very detailed logging
@@ -26,7 +25,8 @@
def main():
- credentials = Storage('buzz.dat').get()
+ storage = Storage('buzz.dat')
+ credentials = storage.get()
if credentials is None or credentials.invalid == True:
buzz_discovery = build("buzz", "v1").auth_discovery()
@@ -38,7 +38,7 @@
scope='https://www.googleapis.com/auth/buzz',
xoauth_displayname='Google API Client Example App')
- credentials = run(flow, 'buzz.dat')
+ credentials = run(flow, storage)
http = httplib2.Http()
http = credentials.authorize(http)
diff --git a/samples/latitude/latitude.py b/samples/latitude/latitude.py
index c2ec635..4ff5b03 100644
--- a/samples/latitude/latitude.py
+++ b/samples/latitude/latitude.py
@@ -27,7 +27,8 @@
def main():
- credentials = Storage('latitude.dat').get()
+ storage = Storage('latitude.dat')
+ credentials = storage.get()
if credentials is None or credentials.invalid == True:
auth_discovery = build("latitude", "v1").auth_discovery()
flow = FlowThreeLegged(auth_discovery,
@@ -45,7 +46,7 @@
granularity='city'
)
- credentials = run(flow, 'latitude.dat')
+ credentials = run(flow, storage)
http = httplib2.Http()
http = credentials.authorize(http)
diff --git a/samples/localdiscovery/buzz.py b/samples/localdiscovery/buzz.py
index 416f58c..8b797f7 100644
--- a/samples/localdiscovery/buzz.py
+++ b/samples/localdiscovery/buzz.py
@@ -11,10 +11,14 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+from apiclient.discovery import build
from apiclient.discovery import build_from_document
+from apiclient.oauth import FlowThreeLegged
+from apiclient.ext.authtools import run
+from apiclient.ext.file import Storage
+from apiclient.oauth import CredentialsInvalidError
import httplib2
-import pickle
import pprint
# Uncomment the next line to get very detailed logging
@@ -22,10 +26,20 @@
def main():
- # Load the credentials and authorize
- f = open("buzz.dat", "r")
- credentials = pickle.loads(f.read())
- f.close()
+ storage = Storage('buzz.dat')
+ credentials = storage.get()
+ if credentials is None or credentials.invalid == True:
+ buzz_discovery = build("buzz", "v1").auth_discovery()
+
+ flow = FlowThreeLegged(buzz_discovery,
+ consumer_key='anonymous',
+ consumer_secret='anonymous',
+ user_agent='python-buzz-sample/1.0',
+ domain='anonymous',
+ scope='https://www.googleapis.com/auth/buzz',
+ xoauth_displayname='Google API Client Example App')
+
+ credentials = run(flow, storage)
http = httplib2.Http()
http = credentials.authorize(http)
@@ -48,43 +62,15 @@
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
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"
+ try:
+ # Retrieve the first two activities
+ activitylist = activities.list(
+ max_results='2', scope='@self', userId='@me').execute()
+ print "Retrieved the first two activities"
+ except CredentialsInvalidError:
+ print 'Your credentials are no longer valid.'
+ print 'Please re-run this application to re-authorize.'
- # Retrieve 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 = {
- "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"
-
- activitylist = activities.list(
- max_results='2', scope='@self', userId='@me').execute()
-
- # Add a comment to that activity
- comment_body = {
- "data": {
- "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/localdiscovery/three_legged_dance.py b/samples/localdiscovery/three_legged_dance.py
deleted file mode 100644
index 2dc26e5..0000000
--- a/samples/localdiscovery/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')
diff --git a/samples/moderator/moderator.py b/samples/moderator/moderator.py
index 89ec9ca..c22f86e 100644
--- a/samples/moderator/moderator.py
+++ b/samples/moderator/moderator.py
@@ -13,18 +13,33 @@
from apiclient.discovery import build
+from apiclient.oauth import FlowThreeLegged
+from apiclient.ext.authtools import run
+from apiclient.ext.file import Storage
+from apiclient.oauth import CredentialsInvalidError
import httplib2
-import pickle
# Uncomment to get detailed logging
# httplib2.debuglevel = 4
def main():
- f = open("moderator.dat", "r")
- credentials = pickle.loads(f.read())
- f.close()
+ storage = Storage('moderator.dat')
+ credentials = storage.get()
+ if credentials is None or credentials.invalid == True:
+ moderator_discovery = build("moderator", "v1").auth_discovery()
+
+ flow = FlowThreeLegged(moderator_discovery,
+ consumer_key='anonymous',
+ consumer_secret='anonymous',
+ user_agent='google-api-client-python-mdrtr-cmdline/1.0',
+ domain='anonymous',
+ scope='https://www.googleapis.com/auth/moderator',
+ #scope='tag:google.com,2010:auth/moderator',
+ xoauth_displayname='Google API Client Example App')
+
+ credentials = run(flow, storage)
http = httplib2.Http()
http = credentials.authorize(http)
@@ -38,43 +53,47 @@
"videoSubmissionAllowed": False
}
}
- series = p.series().insert(body=series_body).execute()
- print "Created a new series"
+ try:
+ series = p.series().insert(body=series_body).execute()
+ print "Created a new series"
- topic_body = {
- "data": {
- "description": "Share your ideas on eating healthy!",
- "name": "Ideas",
- "presenter": "liz"
+ topic_body = {
+ "data": {
+ "description": "Share your ideas on eating healthy!",
+ "name": "Ideas",
+ "presenter": "liz"
+ }
}
- }
- topic = p.topics().insert(seriesId=series['id']['seriesId'],
- body=topic_body).execute()
- print "Created a new topic"
+ topic = p.topics().insert(seriesId=series['id']['seriesId'],
+ body=topic_body).execute()
+ print "Created a new topic"
- submission_body = {
- "data": {
- "attachmentUrl": "http://www.youtube.com/watch?v=1a1wyc5Xxpg",
- "attribution": {
- "displayName": "Bashan",
- "location": "Bainbridge Island, WA"
- },
- "text": "Charlie Ayers @ Google"
+ submission_body = {
+ "data": {
+ "attachmentUrl": "http://www.youtube.com/watch?v=1a1wyc5Xxpg",
+ "attribution": {
+ "displayName": "Bashan",
+ "location": "Bainbridge Island, WA"
+ },
+ "text": "Charlie Ayers @ Google"
+ }
}
- }
- submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
- topicId=topic['id']['topicId'], body=submission_body).execute()
- print "Inserted a new submisson on the topic"
+ submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
+ topicId=topic['id']['topicId'], body=submission_body).execute()
+ print "Inserted a new submisson on the topic"
- vote_body = {
- "data": {
- "vote": "PLUS"
+ vote_body = {
+ "data": {
+ "vote": "PLUS"
+ }
}
- }
- p.votes().insert(seriesId=topic['id']['seriesId'],
- submissionId=submission['id']['submissionId'],
- body=vote_body)
- print "Voted on the submission"
+ p.votes().insert(seriesId=topic['id']['seriesId'],
+ submissionId=submission['id']['submissionId'],
+ body=vote_body)
+ print "Voted on the submission"
+ except CredentialsInvalidError:
+ print 'Your credentials are no longer valid.'
+ print 'Please re-run this application to re-authorize.'
if __name__ == '__main__':
diff --git a/samples/moderator/three_legged_dance.py b/samples/moderator/three_legged_dance.py
deleted file mode 100644
index 32e624d..0000000
--- a/samples/moderator/three_legged_dance.py
+++ /dev/null
@@ -1,41 +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
-
-
-moderator_discovery = build("moderator", "v1").auth_discovery()
-
-flow = FlowThreeLegged(moderator_discovery,
- consumer_key='anonymous',
- consumer_secret='anonymous',
- user_agent='google-api-client-python-mdrtr-cmdline/1.0',
- domain='anonymous',
- scope='https://www.googleapis.com/auth/moderator',
- #scope='tag:google.com,2010:auth/moderator',
- xoauth_displayname='Google API Client Example App')
-
-run(flow, 'moderator.dat')
diff --git a/samples/threadqueue/main.py b/samples/threadqueue/main.py
index 4e5c511..d184f6d 100644
--- a/samples/threadqueue/main.py
+++ b/samples/threadqueue/main.py
@@ -1,9 +1,13 @@
from apiclient.discovery import build
-from apiclient.discovery import HttpError
+from apiclient.discovery import build
+from apiclient.errors import HttpError
+from apiclient.ext.authtools import run
+from apiclient.ext.file import Storage
+from apiclient.oauth import CredentialsInvalidError
+from apiclient.oauth import FlowThreeLegged
import Queue
import httplib2
-import pickle
import threading
import time
@@ -47,8 +51,9 @@
def process_requests():
http = httplib2.Http()
http = credentials.authorize(http)
+ credentials_ok = True
- while True:
+ while credentials_ok:
request = queue.get()
backoff = Backoff()
while backoff.loop():
@@ -59,10 +64,15 @@
if e.resp.status in [402, 403, 408, 503, 504]:
print "Increasing backoff, got status code: %d" % e.resp.status
backoff.fail()
+ except CredentialsInvalidError:
+ print "Credentials no long valid. Exiting."
+ credentials_ok = False
+ break
print "Completed request"
queue.task_done()
+
for i in range(NUM_THREADS):
t = threading.Thread(target=process_requests)
t.daemon = True
@@ -70,9 +80,20 @@
def main():
- f = open("moderator.dat", "r")
- credentials = pickle.loads(f.read())
- f.close()
+ storage = Storage('moderator.dat')
+ credentials = storage.get()
+ if credentials is None or credentials.invalid == True:
+ moderator_discovery = build("moderator", "v1").auth_discovery()
+
+ flow = FlowThreeLegged(moderator_discovery,
+ consumer_key='anonymous',
+ consumer_secret='anonymous',
+ user_agent='google-api-client-python-thread-sample/1.0',
+ domain='anonymous',
+ scope='https://www.googleapis.com/auth/moderator',
+ xoauth_displayname='Google API Client Example App')
+
+ credentials = run(flow, storage)
start_threads(credentials)
@@ -88,21 +109,26 @@
"videoSubmissionAllowed": False
}
}
- series = p.series().insert(body=series_body).execute()
- print "Created a new series"
+ try:
+ series = p.series().insert(body=series_body).execute()
+ print "Created a new series"
- for i in range(NUM_ITEMS):
- topic_body = {
- "data": {
- "description": "Sample Topic # %d" % i,
- "name": "Sample",
- "presenter": "me"
+ for i in range(NUM_ITEMS):
+ topic_body = {
+ "data": {
+ "description": "Sample Topic # %d" % i,
+ "name": "Sample",
+ "presenter": "me"
+ }
}
- }
- topic_request = p.topics().insert(seriesId=series['id']['seriesId'],
- body=topic_body)
- print "Adding request to queue"
- queue.put(topic_request)
+ topic_request = p.topics().insert(seriesId=series['id']['seriesId'],
+ body=topic_body)
+ print "Adding request to queue"
+ queue.put(topic_request)
+ except CredentialsInvalidError:
+ print 'Your credentials are no longer valid.'
+ print 'Please re-run this application to re-authorize.'
+
queue.join()
diff --git a/samples/threadqueue/three_legged_dance.py b/samples/threadqueue/three_legged_dance.py
deleted file mode 100644
index 12c495b..0000000
--- a/samples/threadqueue/three_legged_dance.py
+++ /dev/null
@@ -1,41 +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
-
-
-moderator_discovery = build("moderator", "v1").auth_discovery()
-
-flow = FlowThreeLegged(moderator_discovery,
- consumer_key='anonymous',
- consumer_secret='anonymous',
- user_agent='google-api-client-python-thread-sample/1.0',
- domain='anonymous',
- scope='https://www.googleapis.com/auth/moderator',
- #scope='tag:google.com,2010:auth/moderator',
- xoauth_displayname='Google API Client Example App')
-
-run(flow, 'moderator.dat')