Added in more documentation, cleaned up use of postproc in HttpRequest and refreshed docs

This commit is contained in:
Joe Gregorio
2011-02-11 20:19:33 -05:00
parent 4b2e51aee5
commit abda96fe2c
7 changed files with 203 additions and 36 deletions

View File

@@ -20,6 +20,9 @@ based APIs.
__author__ = 'jcgregorio@google.com (Joe Gregorio)' __author__ = 'jcgregorio@google.com (Joe Gregorio)'
__all__ = [
'build', 'build_from_document'
]
import httplib2 import httplib2
import logging import logging
@@ -67,6 +70,28 @@ def build(serviceName, version,
developerKey=None, developerKey=None,
model=JsonModel(), model=JsonModel(),
requestBuilder=HttpRequest): requestBuilder=HttpRequest):
"""Construct a Resource for interacting with an API.
Construct a Resource object for interacting with
an API. The serviceName and version are the
names from the Discovery service.
Args:
serviceName: string, name of the service
version: string, the version of the service
discoveryServiceUrl: string, a URI Template that points to
the location of the discovery service. It should have two
parameters {api} and {apiVersion} that when filled in
produce an absolute URI to the discovery document for
that service.
developerKey: string, key obtained from https://code.google.com/apis/console
model: apiclient.Model, converts to and from the wire format
requestBuilder: apiclient.http.HttpRequest, encapsulator for an HTTP request
Returns:
A Resource object with methods for interacting with
the service.
"""
params = { params = {
'api': serviceName, 'api': serviceName,
'apiVersion': version 'apiVersion': version
@@ -100,7 +125,12 @@ def build_from_document(
developerKey=None, developerKey=None,
model=JsonModel(), model=JsonModel(),
requestBuilder=HttpRequest): requestBuilder=HttpRequest):
""" """Create a Resource for interacting with an API.
Same as `build()`, but constructs the Resource object
from a discovery document that is it given, as opposed to
retrieving one over HTTP.
Args: Args:
service: string, discovery document service: string, discovery document
base: string, base URI for all HTTP requests, usually the discovery URI base: string, base URI for all HTTP requests, usually the discovery URI
@@ -113,6 +143,10 @@ def build_from_document(
model: Model class instance that serializes and model: Model class instance that serializes and
de-serializes requests and responses. de-serializes requests and responses.
requestBuilder: Takes an http request and packages it up to be executed. requestBuilder: Takes an http request and packages it up to be executed.
Returns:
A Resource object with methods for interacting with
the service.
""" """
service = simplejson.loads(service) service = simplejson.loads(service)
@@ -229,10 +263,12 @@ def createResource(http, baseUrl, model, requestBuilder,
url_result.path + expanded_url + query) url_result.path + expanded_url + query)
logging.info('URL being requested: %s' % url) logging.info('URL being requested: %s' % url)
return self._requestBuilder(self._http, url, return self._requestBuilder(self._http,
method=httpMethod, body=body, self._model.response,
url,
method=httpMethod,
body=body,
headers=headers, headers=headers,
postproc=self._model.response,
methodId=methodId) methodId=methodId)
docs = ['A description of how to use this function\n\n'] docs = ['A description of how to use this function\n\n']
@@ -281,9 +317,11 @@ def createResource(http, baseUrl, model, requestBuilder,
logging.info('URL being requested: %s' % url) logging.info('URL being requested: %s' % url)
resp, content = self._http.request(url, method='GET', headers=headers) resp, content = self._http.request(url, method='GET', headers=headers)
return self._requestBuilder(self._http, url, method='GET', return self._requestBuilder(self._http,
self._model.response,
url,
method='GET',
headers=headers, headers=headers,
postproc=self._model.response,
methodId=methodId) methodId=methodId)
setattr(theclass, methodName, method) setattr(theclass, methodName, method)

View File

@@ -20,21 +20,19 @@ class HttpRequest(object):
"""Encapsulates a single HTTP request. """Encapsulates a single HTTP request.
""" """
def __init__(self, http, uri, method="GET", body=None, headers=None, def __init__(self, http, postproc, uri, method="GET", body=None, headers=None,
postproc=None, methodId=None): methodId=None):
"""Constructor for an HttpRequest. """Constructor for an HttpRequest.
Only http and uri are required.
Args: Args:
http: httplib2.Http, the transport object to use to make a request http: httplib2.Http, the transport object to use to make a request
postproc: callable, called on the HTTP response and content to transform
it into a data object before returning, or raising an exception
on an error.
uri: string, the absolute URI to send the request to uri: string, the absolute URI to send the request to
method: string, the HTTP method to use method: string, the HTTP method to use
body: string, the request body of the HTTP request body: string, the request body of the HTTP request
headers: dict, the HTTP request headers headers: dict, the HTTP request headers
postproc: callable, called on the HTTP response and content to transform
it into a data object before returning, or raising an exception
on an error.
methodId: string, a unique identifier for the API method being called. methodId: string, a unique identifier for the API method being called.
""" """
self.uri = uri self.uri = uri
@@ -136,8 +134,8 @@ class RequestMockBuilder(object):
""" """
self.responses = responses self.responses = responses
def __call__(self, http, uri, method="GET", body=None, headers=None, def __call__(self, http, postproc, uri, method="GET", body=None,
postproc=None, methodId=None): headers=None, methodId=None):
"""Implements the callable interface that discovery.build() expects """Implements the callable interface that discovery.build() expects
of requestBuilder, which is to build an object compatible with of requestBuilder, which is to build an object compatible with
HttpRequest.execute(). See that method for the description of the HttpRequest.execute(). See that method for the description of the

View File

@@ -18,8 +18,54 @@ import urllib
from anyjson import simplejson from anyjson import simplejson
from errors import HttpError from errors import HttpError
def _abstract():
raise NotImplementedError('You need to override this function')
class JsonModel(object):
class Model(object):
"""Model base class.
All Model classes should implement this interface.
The Model serializes and de-serializes between a wire
format such as JSON and a Python object representation.
"""
def request(self, headers, path_params, query_params, body_value):
"""Updates outgoing requests with a deserialized body.
Args:
headers: dict, request headers
path_params: dict, parameters that appear in the request path
query_params: dict, parameters that appear in the query
body_value: object, the request body as a Python object, which must be
serializable.
Returns:
A tuple of (headers, path_params, query, body)
headers: dict, request headers
path_params: dict, parameters that appear in the request path
query: string, query part of the request URI
body: string, the body serialized in the desired wire format.
"""
_abstract()
def response(self, resp, content):
"""Convert the response wire format into a Python object.
Args:
resp: httplib2.Response, the HTTP response headers and status
content: string, the body of the HTTP response
Returns:
The body de-serialized as a Python object.
Raises:
apiclient.errors.HttpError if a non 2xx response is received.
"""
_abstract()
class JsonModel(Model):
"""Model class for JSON. """Model class for JSON.
Serializes and de-serializes between JSON and the Python Serializes and de-serializes between JSON and the Python

View File

@@ -35,8 +35,34 @@ based&nbsp;APIs.</tt></p>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</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">=&lt;apiclient.model.JsonModel object&gt;</font>, requestBuilder<font color="#909090">=&lt;class 'apiclient.http.HttpRequest'&gt;</font>)</dt></dl> <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">=&lt;apiclient.model.JsonModel object&gt;</font>, requestBuilder<font color="#909090">=&lt;class 'apiclient.http.HttpRequest'&gt;</font>)</dt><dd><tt>Construct&nbsp;a&nbsp;Resource&nbsp;for&nbsp;interacting&nbsp;with&nbsp;an&nbsp;API.<br>
<dl><dt><a name="-build_from_document"><strong>build_from_document</strong></a>(service, base, future<font color="#909090">=None</font>, http<font color="#909090">=None</font>, developerKey<font color="#909090">=None</font>, model<font color="#909090">=&lt;apiclient.model.JsonModel object&gt;</font>, requestBuilder<font color="#909090">=&lt;class 'apiclient.http.HttpRequest'&gt;</font>)</dt><dd><tt>Args:<br> &nbsp;<br>
Construct&nbsp;a&nbsp;Resource&nbsp;object&nbsp;for&nbsp;interacting&nbsp;with<br>
an&nbsp;API.&nbsp;The&nbsp;serviceName&nbsp;and&nbsp;version&nbsp;are&nbsp;the<br>
names&nbsp;from&nbsp;the&nbsp;Discovery&nbsp;service.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;serviceName:&nbsp;string,&nbsp;name&nbsp;of&nbsp;the&nbsp;service<br>
&nbsp;&nbsp;version:&nbsp;string,&nbsp;the&nbsp;version&nbsp;of&nbsp;the&nbsp;service<br>
&nbsp;&nbsp;discoveryServiceUrl:&nbsp;string,&nbsp;a&nbsp;URI&nbsp;Template&nbsp;that&nbsp;points&nbsp;to<br>
&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;location&nbsp;of&nbsp;the&nbsp;discovery&nbsp;service.&nbsp;It&nbsp;should&nbsp;have&nbsp;two<br>
&nbsp;&nbsp;&nbsp;&nbsp;parameters&nbsp;{api}&nbsp;and&nbsp;{apiVersion}&nbsp;that&nbsp;when&nbsp;filled&nbsp;in<br>
&nbsp;&nbsp;&nbsp;&nbsp;produce&nbsp;an&nbsp;absolute&nbsp;URI&nbsp;to&nbsp;the&nbsp;discovery&nbsp;document&nbsp;for<br>
&nbsp;&nbsp;&nbsp;&nbsp;that&nbsp;service.<br>
&nbsp;&nbsp;developerKey:&nbsp;string,&nbsp;key&nbsp;obtained&nbsp;from&nbsp;https://code.google.com/apis/console<br>
&nbsp;&nbsp;model:&nbsp;apiclient.Model,&nbsp;converts&nbsp;to&nbsp;and&nbsp;from&nbsp;the&nbsp;wire&nbsp;format<br>
&nbsp;&nbsp;requestBuilder:&nbsp;apiclient.http.HttpRequest,&nbsp;encapsulator&nbsp;for&nbsp;an&nbsp;HTTP&nbsp;request<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;A&nbsp;Resource&nbsp;object&nbsp;with&nbsp;methods&nbsp;for&nbsp;interacting&nbsp;with<br>
&nbsp;&nbsp;the&nbsp;service.</tt></dd></dl>
<dl><dt><a name="-build_from_document"><strong>build_from_document</strong></a>(service, base, future<font color="#909090">=None</font>, http<font color="#909090">=None</font>, developerKey<font color="#909090">=None</font>, model<font color="#909090">=&lt;apiclient.model.JsonModel object&gt;</font>, requestBuilder<font color="#909090">=&lt;class 'apiclient.http.HttpRequest'&gt;</font>)</dt><dd><tt>Create&nbsp;a&nbsp;Resource&nbsp;for&nbsp;interacting&nbsp;with&nbsp;an&nbsp;API.<br>
&nbsp;<br>
Same&nbsp;as&nbsp;`<a href="#-build">build</a>()`,&nbsp;but&nbsp;constructs&nbsp;the&nbsp;Resource&nbsp;object<br>
from&nbsp;a&nbsp;discovery&nbsp;document&nbsp;that&nbsp;is&nbsp;it&nbsp;given,&nbsp;as&nbsp;opposed&nbsp;to<br>
retrieving&nbsp;one&nbsp;over&nbsp;HTTP.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;service:&nbsp;string,&nbsp;discovery&nbsp;document<br> &nbsp;&nbsp;service:&nbsp;string,&nbsp;discovery&nbsp;document<br>
&nbsp;&nbsp;base:&nbsp;string,&nbsp;base&nbsp;URI&nbsp;for&nbsp;all&nbsp;HTTP&nbsp;requests,&nbsp;usually&nbsp;the&nbsp;discovery&nbsp;URI<br> &nbsp;&nbsp;base:&nbsp;string,&nbsp;base&nbsp;URI&nbsp;for&nbsp;all&nbsp;HTTP&nbsp;requests,&nbsp;usually&nbsp;the&nbsp;discovery&nbsp;URI<br>
&nbsp;&nbsp;future:&nbsp;string,&nbsp;discovery&nbsp;document&nbsp;with&nbsp;future&nbsp;capabilities<br> &nbsp;&nbsp;future:&nbsp;string,&nbsp;discovery&nbsp;document&nbsp;with&nbsp;future&nbsp;capabilities<br>
@@ -47,9 +73,11 @@ based&nbsp;APIs.</tt></p>
&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;the&nbsp;API&nbsp;Console.<br> &nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;the&nbsp;API&nbsp;Console.<br>
&nbsp;&nbsp;model:&nbsp;Model&nbsp;class&nbsp;instance&nbsp;that&nbsp;serializes&nbsp;and<br> &nbsp;&nbsp;model:&nbsp;Model&nbsp;class&nbsp;instance&nbsp;that&nbsp;serializes&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;de-serializes&nbsp;requests&nbsp;and&nbsp;responses.<br> &nbsp;&nbsp;&nbsp;&nbsp;de-serializes&nbsp;requests&nbsp;and&nbsp;responses.<br>
&nbsp;&nbsp;requestBuilder:&nbsp;Takes&nbsp;an&nbsp;http&nbsp;request&nbsp;and&nbsp;packages&nbsp;it&nbsp;up&nbsp;to&nbsp;be&nbsp;executed.</tt></dd></dl> &nbsp;&nbsp;requestBuilder:&nbsp;Takes&nbsp;an&nbsp;http&nbsp;request&nbsp;and&nbsp;packages&nbsp;it&nbsp;up&nbsp;to&nbsp;be&nbsp;executed.<br>
<dl><dt><a name="-createResource"><strong>createResource</strong></a>(http, baseUrl, model, requestBuilder, developerKey, resourceDesc, futureDesc)</dt></dl> &nbsp;<br>
<dl><dt><a name="-key2param"><strong>key2param</strong></a>(key)</dt><dd><tt>max-results&nbsp;-&gt;&nbsp;max_results</tt></dd></dl> Returns:<br>
&nbsp;&nbsp;A&nbsp;Resource&nbsp;object&nbsp;with&nbsp;methods&nbsp;for&nbsp;interacting&nbsp;with<br>
&nbsp;&nbsp;the&nbsp;service.</tt></dd></dl>
</td></tr></table><p> </td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55"> <tr bgcolor="#55aa55">
@@ -57,9 +85,7 @@ based&nbsp;APIs.</tt></p>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>DISCOVERY_URI</strong> = 'https://www.googleapis.com/discovery/v0.2beta1/describe/{api}/{apiVersion}'<br> <td width="100%"><strong>__all__</strong> = ['build', 'build_from_document']<br>
<strong>URITEMPLATE</strong> = &lt;_sre.SRE_Pattern object&gt;<br>
<strong>VARNAME</strong> = &lt;_sre.SRE_Pattern object&gt;<br>
<strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p> <strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee"> <tr bgcolor="#7799ee">

View File

@@ -8,7 +8,7 @@
<td valign=bottom>&nbsp;<br> <td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<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 <font color="#ffffff" face="helvetica, arial">&nbsp;<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 ><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></p>
<p> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">

View File

@@ -48,19 +48,17 @@ actuall&nbsp;HTTP&nbsp;request.</tt></p>
<td colspan=2><tt>Encapsulates&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>&nbsp;</tt></td></tr> <td colspan=2><tt>Encapsulates&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td> <tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br> <td width="100%">Methods defined here:<br>
<dl><dt><a name="HttpRequest-__init__"><strong>__init__</strong></a>(self, http, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, postproc<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>)</dt><dd><tt>Constructor&nbsp;for&nbsp;an&nbsp;<a href="#HttpRequest">HttpRequest</a>.<br> <dl><dt><a name="HttpRequest-__init__"><strong>__init__</strong></a>(self, http, postproc, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>)</dt><dd><tt>Constructor&nbsp;for&nbsp;an&nbsp;<a href="#HttpRequest">HttpRequest</a>.<br>
&nbsp;<br>
Only&nbsp;http&nbsp;and&nbsp;uri&nbsp;are&nbsp;required.<br>
&nbsp;<br> &nbsp;<br>
Args:<br> Args:<br>
&nbsp;&nbsp;http:&nbsp;httplib2.Http,&nbsp;the&nbsp;transport&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;use&nbsp;to&nbsp;make&nbsp;a&nbsp;request<br> &nbsp;&nbsp;http:&nbsp;httplib2.Http,&nbsp;the&nbsp;transport&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;use&nbsp;to&nbsp;make&nbsp;a&nbsp;request<br>
&nbsp;&nbsp;postproc:&nbsp;callable,&nbsp;called&nbsp;on&nbsp;the&nbsp;HTTP&nbsp;response&nbsp;and&nbsp;content&nbsp;to&nbsp;transform<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;into&nbsp;a&nbsp;data&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;before&nbsp;returning,&nbsp;or&nbsp;raising&nbsp;an&nbsp;exception<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on&nbsp;an&nbsp;error.<br>
&nbsp;&nbsp;uri:&nbsp;string,&nbsp;the&nbsp;absolute&nbsp;URI&nbsp;to&nbsp;send&nbsp;the&nbsp;request&nbsp;to<br> &nbsp;&nbsp;uri:&nbsp;string,&nbsp;the&nbsp;absolute&nbsp;URI&nbsp;to&nbsp;send&nbsp;the&nbsp;request&nbsp;to<br>
&nbsp;&nbsp;method:&nbsp;string,&nbsp;the&nbsp;HTTP&nbsp;method&nbsp;to&nbsp;use<br> &nbsp;&nbsp;method:&nbsp;string,&nbsp;the&nbsp;HTTP&nbsp;method&nbsp;to&nbsp;use<br>
&nbsp;&nbsp;body:&nbsp;string,&nbsp;the&nbsp;request&nbsp;body&nbsp;of&nbsp;the&nbsp;HTTP&nbsp;request<br> &nbsp;&nbsp;body:&nbsp;string,&nbsp;the&nbsp;request&nbsp;body&nbsp;of&nbsp;the&nbsp;HTTP&nbsp;request<br>
&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;the&nbsp;HTTP&nbsp;request&nbsp;headers<br> &nbsp;&nbsp;headers:&nbsp;dict,&nbsp;the&nbsp;HTTP&nbsp;request&nbsp;headers<br>
&nbsp;&nbsp;postproc:&nbsp;callable,&nbsp;called&nbsp;on&nbsp;the&nbsp;HTTP&nbsp;response&nbsp;and&nbsp;content&nbsp;to&nbsp;transform<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;into&nbsp;a&nbsp;data&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;before&nbsp;returning,&nbsp;or&nbsp;raising&nbsp;an&nbsp;exception<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on&nbsp;an&nbsp;error.<br>
&nbsp;&nbsp;methodId:&nbsp;string,&nbsp;a&nbsp;unique&nbsp;identifier&nbsp;for&nbsp;the&nbsp;API&nbsp;method&nbsp;being&nbsp;called.</tt></dd></dl> &nbsp;&nbsp;methodId:&nbsp;string,&nbsp;a&nbsp;unique&nbsp;identifier&nbsp;for&nbsp;the&nbsp;API&nbsp;method&nbsp;being&nbsp;called.</tt></dd></dl>
<dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute&nbsp;the&nbsp;request.<br> <dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute&nbsp;the&nbsp;request.<br>
@@ -115,7 +113,7 @@ is&nbsp;taken&nbsp;from&nbsp;the&nbsp;rpcName&nbsp;in&nbsp;the&nbsp;discovery&nb
For&nbsp;more&nbsp;details&nbsp;see&nbsp;the&nbsp;project&nbsp;wiki.<br>&nbsp;</tt></td></tr> For&nbsp;more&nbsp;details&nbsp;see&nbsp;the&nbsp;project&nbsp;wiki.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td> <tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br> <td width="100%">Methods defined here:<br>
<dl><dt><a name="RequestMockBuilder-__call__"><strong>__call__</strong></a>(self, http, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, postproc<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>)</dt><dd><tt>Implements&nbsp;the&nbsp;callable&nbsp;interface&nbsp;that&nbsp;discovery.build()&nbsp;expects<br> <dl><dt><a name="RequestMockBuilder-__call__"><strong>__call__</strong></a>(self, http, postproc, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>)</dt><dd><tt>Implements&nbsp;the&nbsp;callable&nbsp;interface&nbsp;that&nbsp;discovery.build()&nbsp;expects<br>
of&nbsp;requestBuilder,&nbsp;which&nbsp;is&nbsp;to&nbsp;build&nbsp;an&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;compatible&nbsp;with<br> of&nbsp;requestBuilder,&nbsp;which&nbsp;is&nbsp;to&nbsp;build&nbsp;an&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;compatible&nbsp;with<br>
<a href="#HttpRequest">HttpRequest</a>.execute().&nbsp;See&nbsp;that&nbsp;method&nbsp;for&nbsp;the&nbsp;description&nbsp;of&nbsp;the<br> <a href="#HttpRequest">HttpRequest</a>.execute().&nbsp;See&nbsp;that&nbsp;method&nbsp;for&nbsp;the&nbsp;description&nbsp;of&nbsp;the<br>
parameters&nbsp;and&nbsp;the&nbsp;expected&nbsp;response.</tt></dd></dl> parameters&nbsp;and&nbsp;the&nbsp;expected&nbsp;response.</tt></dd></dl>

View File

@@ -9,7 +9,7 @@
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.model</strong></big></big></font></td <font color="#ffffff" face="helvetica, arial">&nbsp;<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 ><td align=right valign=bottom
><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> ><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>Model&nbsp;objects&nbsp;for&nbsp;requests&nbsp;and&nbsp;responses<br> <p><tt><a href="#Model">Model</a>&nbsp;objects&nbsp;for&nbsp;requests&nbsp;and&nbsp;responses<br>
&nbsp;<br> &nbsp;<br>
Each&nbsp;API&nbsp;may&nbsp;support&nbsp;one&nbsp;or&nbsp;more&nbsp;serializations,&nbsp;such<br> Each&nbsp;API&nbsp;may&nbsp;support&nbsp;one&nbsp;or&nbsp;more&nbsp;serializations,&nbsp;such<br>
as&nbsp;JSON,&nbsp;Atom,&nbsp;etc.&nbsp;The&nbsp;model&nbsp;classes&nbsp;are&nbsp;responsible<br> as&nbsp;JSON,&nbsp;Atom,&nbsp;etc.&nbsp;The&nbsp;model&nbsp;classes&nbsp;are&nbsp;responsible<br>
@@ -36,23 +36,34 @@ for&nbsp;converting&nbsp;between&nbsp;the&nbsp;wire&nbsp;format&nbsp;and&nbsp;th
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd> </font></dt><dd>
<dl> <dl>
<dt><font face="helvetica, arial"><a href="apiclient.model.html#Model">Model</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="apiclient.model.html#JsonModel">JsonModel</a> <dt><font face="helvetica, arial"><a href="apiclient.model.html#JsonModel">JsonModel</a>
</font></dt></dl> </font></dt></dl>
</dd> </dd>
</dl>
</dd>
</dl> </dl>
<p> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8"> <tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br> <td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="JsonModel">class <strong>JsonModel</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> <font color="#000000" face="helvetica, arial"><a name="JsonModel">class <strong>JsonModel</strong></a>(<a href="apiclient.model.html#Model">Model</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td> <tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Model&nbsp;class&nbsp;for&nbsp;JSON.<br> <td colspan=2><tt><a href="#Model">Model</a>&nbsp;class&nbsp;for&nbsp;JSON.<br>
&nbsp;<br> &nbsp;<br>
Serializes&nbsp;and&nbsp;de-serializes&nbsp;between&nbsp;JSON&nbsp;and&nbsp;the&nbsp;Python<br> Serializes&nbsp;and&nbsp;de-serializes&nbsp;between&nbsp;JSON&nbsp;and&nbsp;the&nbsp;Python<br>
<a href="__builtin__.html#object">object</a>&nbsp;representation&nbsp;of&nbsp;HTTP&nbsp;request&nbsp;and&nbsp;response&nbsp;bodies.<br>&nbsp;</tt></td></tr> <a href="__builtin__.html#object">object</a>&nbsp;representation&nbsp;of&nbsp;HTTP&nbsp;request&nbsp;and&nbsp;response&nbsp;bodies.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td> <tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br> <td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="apiclient.model.html#JsonModel">JsonModel</a></dd>
<dd><a href="apiclient.model.html#Model">Model</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="JsonModel-request"><strong>request</strong></a>(self, headers, path_params, query_params, body_value)</dt><dd><tt>Updates&nbsp;outgoing&nbsp;requests&nbsp;with&nbsp;JSON&nbsp;bodies.<br> <dl><dt><a name="JsonModel-request"><strong>request</strong></a>(self, headers, path_params, query_params, body_value)</dt><dd><tt>Updates&nbsp;outgoing&nbsp;requests&nbsp;with&nbsp;JSON&nbsp;bodies.<br>
&nbsp;<br> &nbsp;<br>
Args:<br> Args:<br>
@@ -81,6 +92,56 @@ Returns:<br>
Raises:<br> Raises:<br>
&nbsp;&nbsp;apiclient.errors.HttpError&nbsp;if&nbsp;a&nbsp;non&nbsp;2xx&nbsp;response&nbsp;is&nbsp;received.</tt></dd></dl> &nbsp;&nbsp;apiclient.errors.HttpError&nbsp;if&nbsp;a&nbsp;non&nbsp;2xx&nbsp;response&nbsp;is&nbsp;received.</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="apiclient.model.html#Model">Model</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Model">class <strong>Model</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt><a href="#Model">Model</a>&nbsp;base&nbsp;class.<br>
&nbsp;<br>
All&nbsp;<a href="#Model">Model</a>&nbsp;classes&nbsp;should&nbsp;implement&nbsp;this&nbsp;interface.<br>
The&nbsp;<a href="#Model">Model</a>&nbsp;serializes&nbsp;and&nbsp;de-serializes&nbsp;between&nbsp;a&nbsp;wire<br>
format&nbsp;such&nbsp;as&nbsp;JSON&nbsp;and&nbsp;a&nbsp;Python&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;representation.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Model-request"><strong>request</strong></a>(self, headers, path_params, query_params, body_value)</dt><dd><tt>Updates&nbsp;outgoing&nbsp;requests&nbsp;with&nbsp;a&nbsp;deserialized&nbsp;body.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;request&nbsp;headers<br>
&nbsp;&nbsp;path_params:&nbsp;dict,&nbsp;parameters&nbsp;that&nbsp;appear&nbsp;in&nbsp;the&nbsp;request&nbsp;path<br>
&nbsp;&nbsp;query_params:&nbsp;dict,&nbsp;parameters&nbsp;that&nbsp;appear&nbsp;in&nbsp;the&nbsp;query<br>
&nbsp;&nbsp;body_value:&nbsp;<a href="__builtin__.html#object">object</a>,&nbsp;the&nbsp;request&nbsp;body&nbsp;as&nbsp;a&nbsp;Python&nbsp;<a href="__builtin__.html#object">object</a>,&nbsp;which&nbsp;must&nbsp;be<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serializable.<br>
Returns:<br>
&nbsp;&nbsp;A&nbsp;tuple&nbsp;of&nbsp;(headers,&nbsp;path_params,&nbsp;query,&nbsp;body)<br>
&nbsp;<br>
&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;request&nbsp;headers<br>
&nbsp;&nbsp;path_params:&nbsp;dict,&nbsp;parameters&nbsp;that&nbsp;appear&nbsp;in&nbsp;the&nbsp;request&nbsp;path<br>
&nbsp;&nbsp;query:&nbsp;string,&nbsp;query&nbsp;part&nbsp;of&nbsp;the&nbsp;request&nbsp;URI<br>
&nbsp;&nbsp;body:&nbsp;string,&nbsp;the&nbsp;body&nbsp;serialized&nbsp;in&nbsp;the&nbsp;desired&nbsp;wire&nbsp;format.</tt></dd></dl>
<dl><dt><a name="Model-response"><strong>response</strong></a>(self, resp, content)</dt><dd><tt>Convert&nbsp;the&nbsp;response&nbsp;wire&nbsp;format&nbsp;into&nbsp;a&nbsp;Python&nbsp;<a href="__builtin__.html#object">object</a>.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;resp:&nbsp;httplib2.Response,&nbsp;the&nbsp;HTTP&nbsp;response&nbsp;headers&nbsp;and&nbsp;status<br>
&nbsp;&nbsp;content:&nbsp;string,&nbsp;the&nbsp;body&nbsp;of&nbsp;the&nbsp;HTTP&nbsp;response<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;The&nbsp;body&nbsp;de-serialized&nbsp;as&nbsp;a&nbsp;Python&nbsp;<a href="__builtin__.html#object">object</a>.<br>
&nbsp;<br>
Raises:<br>
&nbsp;&nbsp;apiclient.errors.HttpError&nbsp;if&nbsp;a&nbsp;non&nbsp;2xx&nbsp;response&nbsp;is&nbsp;received.</tt></dd></dl>
<hr> <hr>
Data descriptors defined here:<br> Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt> <dl><dt><strong>__dict__</strong></dt>