Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 1 | |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 3 | <html><head><title>Python: module apiclient.http</title> |
| 4 | </head><body bgcolor="#f0f0f8"> |
| 5 | |
| 6 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 7 | <tr bgcolor="#7799ee"> |
| 8 | <td valign=bottom> <br> |
| 9 | <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 |
| 10 | ><td align=right valign=bottom |
Joe Gregorio | 3cf90d0 | 2010-12-20 10:26:08 -0500 | [diff] [blame] | 11 | ><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> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 12 | <p><tt>Classes to encapsulate a single HTTP request.<br> |
| 13 | <br> |
| 14 | The classes implement a command pattern, with every<br> |
| 15 | <a href="__builtin__.html#object">object</a> supporting an execute() method that does the<br> |
| 16 | actuall HTTP request.</tt></p> |
| 17 | <p> |
| 18 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 19 | <tr bgcolor="#ee77aa"> |
| 20 | <td colspan=3 valign=bottom> <br> |
| 21 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 22 | |
| 23 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 24 | <td width="100%"><dl> |
| 25 | <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| 26 | </font></dt><dd> |
| 27 | <dl> |
| 28 | <dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a> |
| 29 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#RequestMockBuilder">RequestMockBuilder</a> |
| 30 | </font></dt></dl> |
| 31 | </dd> |
| 32 | </dl> |
| 33 | <p> |
| 34 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 35 | <tr bgcolor="#ffc8d8"> |
| 36 | <td colspan=3 valign=bottom> <br> |
| 37 | <font color="#000000" face="helvetica, arial"><a name="HttpRequest">class <strong>HttpRequest</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 38 | |
| 39 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 40 | <td colspan=2><tt>Encapsulates a single HTTP request.<br> </tt></td></tr> |
| 41 | <tr><td> </td> |
| 42 | <td width="100%">Methods defined here:<br> |
| 43 | <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 for an <a href="#HttpRequest">HttpRequest</a>.<br> |
| 44 | <br> |
| 45 | Only http and uri are required.<br> |
| 46 | <br> |
| 47 | Args:<br> |
| 48 | http: httplib2.Http, the transport <a href="__builtin__.html#object">object</a> to use to make a request<br> |
| 49 | uri: string, the absolute URI to send the request to<br> |
| 50 | method: string, the HTTP method to use<br> |
| 51 | body: string, the request body of the HTTP request<br> |
| 52 | headers: dict, the HTTP request headers<br> |
| 53 | postproc: callable, called on the HTTP response and content to transform<br> |
| 54 | it into a data <a href="__builtin__.html#object">object</a> before returning, or raising an exception<br> |
| 55 | on an error.<br> |
| 56 | methodId: string, a unique identifier for the API method being called.</tt></dd></dl> |
| 57 | |
| 58 | <dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br> |
| 59 | <br> |
| 60 | Args:<br> |
| 61 | http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the<br> |
| 62 | one the <a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with.<br> |
| 63 | <br> |
| 64 | Returns:<br> |
| 65 | A deserialized <a href="__builtin__.html#object">object</a> model of the response body as determined<br> |
| 66 | by the postproc.<br> |
| 67 | <br> |
| 68 | Raises:<br> |
| 69 | apiclient.errors.HttpError if the response was not a 2xx.<br> |
| 70 | httplib2.Error if a transport error has occured.</tt></dd></dl> |
| 71 | |
| 72 | <hr> |
| 73 | Data descriptors defined here:<br> |
| 74 | <dl><dt><strong>__dict__</strong></dt> |
| 75 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 76 | </dl> |
| 77 | <dl><dt><strong>__weakref__</strong></dt> |
| 78 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 79 | </dl> |
| 80 | </td></tr></table> <p> |
| 81 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 82 | <tr bgcolor="#ffc8d8"> |
| 83 | <td colspan=3 valign=bottom> <br> |
| 84 | <font color="#000000" face="helvetica, arial"><a name="RequestMockBuilder">class <strong>RequestMockBuilder</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 85 | |
| 86 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 87 | <td colspan=2><tt>A simple mock of <a href="#HttpRequest">HttpRequest</a><br> |
| 88 | <br> |
| 89 | Pass in a dictionary to the constructor that maps request methodIds to<br> |
| 90 | tuples of (httplib2.Response, content) that should be returned when that<br> |
| 91 | method is called. None may also be passed in for the httplib2.Response, in<br> |
| 92 | which case a 200 OK response will be generated.<br> |
| 93 | <br> |
| 94 | Example:<br> |
| 95 | response = '{"data": {"id": "tag:google.c...'<br> |
| 96 | requestBuilder = <a href="#RequestMockBuilder">RequestMockBuilder</a>(<br> |
| 97 | {<br> |
| 98 | 'chili.activities.get': (None, response),<br> |
| 99 | }<br> |
| 100 | )<br> |
| 101 | apiclient.discovery.build("buzz", "v1", requestBuilder=requestBuilder)<br> |
| 102 | <br> |
| 103 | Methods that you do not supply a response for will return a<br> |
| 104 | 200 OK with an empty string as the response content. The methodId<br> |
| 105 | is taken from the rpcName in the discovery document.<br> |
| 106 | <br> |
| 107 | For more details see the project wiki.<br> </tt></td></tr> |
| 108 | <tr><td> </td> |
| 109 | <td width="100%">Methods defined here:<br> |
| 110 | <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 the callable interface that discovery.build() expects<br> |
| 111 | of requestBuilder, which is to build an <a href="__builtin__.html#object">object</a> compatible with<br> |
| 112 | <a href="#HttpRequest">HttpRequest</a>.execute(). See that method for the description of the<br> |
| 113 | parameters and the expected response.</tt></dd></dl> |
| 114 | |
| 115 | <dl><dt><a name="RequestMockBuilder-__init__"><strong>__init__</strong></a>(self, responses)</dt><dd><tt>Constructor for <a href="#RequestMockBuilder">RequestMockBuilder</a><br> |
| 116 | <br> |
| 117 | The constructed <a href="__builtin__.html#object">object</a> should be a callable <a href="__builtin__.html#object">object</a><br> |
| 118 | that can replace the class HttpResponse.<br> |
| 119 | <br> |
| 120 | responses - A dictionary that maps methodIds into tuples<br> |
| 121 | of (httplib2.Response, content). The methodId<br> |
| 122 | comes from the 'rpcName' field in the discovery<br> |
| 123 | document.</tt></dd></dl> |
| 124 | |
| 125 | <hr> |
| 126 | Data descriptors defined here:<br> |
| 127 | <dl><dt><strong>__dict__</strong></dt> |
| 128 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 129 | </dl> |
| 130 | <dl><dt><strong>__weakref__</strong></dt> |
| 131 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 132 | </dl> |
| 133 | </td></tr></table></td></tr></table><p> |
| 134 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 135 | <tr bgcolor="#55aa55"> |
| 136 | <td colspan=3 valign=bottom> <br> |
| 137 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 138 | |
| 139 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
| 140 | <td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder']<br> |
| 141 | <strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p> |
| 142 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 143 | <tr bgcolor="#7799ee"> |
| 144 | <td colspan=3 valign=bottom> <br> |
| 145 | <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| 146 | |
| 147 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| 148 | <td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table> |
| 149 | </body></html> |