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 | 351b149 | 2011-05-08 23:32:46 -0700 | [diff] [blame^] | 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/google-api-python-client/apiclient/http.py">/home/jcgregorio/projects/google-api-python-client/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"> |
Joe Gregorio | 6e53703 | 2011-02-09 23:04:26 -0500 | [diff] [blame] | 19 | <tr bgcolor="#aa55cc"> |
| 20 | <td colspan=3 valign=bottom> <br> |
| 21 | <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| 22 | |
| 23 | <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
| 24 | <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="httplib2.html">httplib2</a><br> |
Joe Gregorio | cb8103d | 2011-02-11 23:20:52 -0500 | [diff] [blame] | 25 | </td><td width="25%" valign=top><a href="os.html">os</a><br> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 26 | </td><td width="25%" valign=top><a href="simplejson.html">simplejson</a><br> |
| 27 | </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
Joe Gregorio | 6e53703 | 2011-02-09 23:04:26 -0500 | [diff] [blame] | 28 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 29 | <tr bgcolor="#ee77aa"> |
| 30 | <td colspan=3 valign=bottom> <br> |
| 31 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 32 | |
| 33 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 34 | <td width="100%"><dl> |
| 35 | <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| 36 | </font></dt><dd> |
| 37 | <dl> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 38 | <dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 39 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#RequestMockBuilder">RequestMockBuilder</a> |
| 40 | </font></dt></dl> |
| 41 | </dd> |
| 42 | </dl> |
| 43 | <p> |
| 44 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 45 | <tr bgcolor="#ffc8d8"> |
| 46 | <td colspan=3 valign=bottom> <br> |
| 47 | <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> |
| 48 | |
| 49 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 50 | <td colspan=2><tt>Encapsulates a single HTTP request.<br> </tt></td></tr> |
| 51 | <tr><td> </td> |
| 52 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | abda96f | 2011-02-11 20:19:33 -0500 | [diff] [blame] | 53 | <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 for an <a href="#HttpRequest">HttpRequest</a>.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 54 | <br> |
| 55 | Args:<br> |
| 56 | http: httplib2.Http, the transport <a href="__builtin__.html#object">object</a> to use to make a request<br> |
Joe Gregorio | abda96f | 2011-02-11 20:19:33 -0500 | [diff] [blame] | 57 | postproc: callable, called on the HTTP response and content to transform<br> |
| 58 | it into a data <a href="__builtin__.html#object">object</a> before returning, or raising an exception<br> |
| 59 | on an error.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 60 | uri: string, the absolute URI to send the request to<br> |
| 61 | method: string, the HTTP method to use<br> |
| 62 | body: string, the request body of the HTTP request<br> |
| 63 | headers: dict, the HTTP request headers<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 64 | methodId: string, a unique identifier for the API method being called.</tt></dd></dl> |
| 65 | |
| 66 | <dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br> |
| 67 | <br> |
| 68 | Args:<br> |
| 69 | http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the<br> |
| 70 | one the <a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with.<br> |
| 71 | <br> |
| 72 | Returns:<br> |
| 73 | A deserialized <a href="__builtin__.html#object">object</a> model of the response body as determined<br> |
| 74 | by the postproc.<br> |
| 75 | <br> |
| 76 | Raises:<br> |
| 77 | apiclient.errors.HttpError if the response was not a 2xx.<br> |
| 78 | httplib2.Error if a transport error has occured.</tt></dd></dl> |
| 79 | |
| 80 | <hr> |
| 81 | Data descriptors defined here:<br> |
| 82 | <dl><dt><strong>__dict__</strong></dt> |
| 83 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 84 | </dl> |
| 85 | <dl><dt><strong>__weakref__</strong></dt> |
| 86 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 87 | </dl> |
| 88 | </td></tr></table> <p> |
| 89 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 90 | <tr bgcolor="#ffc8d8"> |
| 91 | <td colspan=3 valign=bottom> <br> |
| 92 | <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> |
| 93 | |
| 94 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 95 | <td colspan=2><tt>A simple mock of <a href="#HttpRequest">HttpRequest</a><br> |
| 96 | <br> |
| 97 | Pass in a dictionary to the constructor that maps request methodIds to<br> |
| 98 | tuples of (httplib2.Response, content) that should be returned when that<br> |
| 99 | method is called. None may also be passed in for the httplib2.Response, in<br> |
| 100 | which case a 200 OK response will be generated.<br> |
| 101 | <br> |
| 102 | Example:<br> |
| 103 | response = '{"data": {"id": "tag:google.c...'<br> |
| 104 | requestBuilder = <a href="#RequestMockBuilder">RequestMockBuilder</a>(<br> |
| 105 | {<br> |
| 106 | 'chili.activities.get': (None, response),<br> |
| 107 | }<br> |
| 108 | )<br> |
| 109 | apiclient.discovery.build("buzz", "v1", requestBuilder=requestBuilder)<br> |
| 110 | <br> |
| 111 | Methods that you do not supply a response for will return a<br> |
| 112 | 200 OK with an empty string as the response content. The methodId<br> |
| 113 | is taken from the rpcName in the discovery document.<br> |
| 114 | <br> |
| 115 | For more details see the project wiki.<br> </tt></td></tr> |
| 116 | <tr><td> </td> |
| 117 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | abda96f | 2011-02-11 20:19:33 -0500 | [diff] [blame] | 118 | <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 the callable interface that discovery.build() expects<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 119 | of requestBuilder, which is to build an <a href="__builtin__.html#object">object</a> compatible with<br> |
| 120 | <a href="#HttpRequest">HttpRequest</a>.execute(). See that method for the description of the<br> |
| 121 | parameters and the expected response.</tt></dd></dl> |
| 122 | |
| 123 | <dl><dt><a name="RequestMockBuilder-__init__"><strong>__init__</strong></a>(self, responses)</dt><dd><tt>Constructor for <a href="#RequestMockBuilder">RequestMockBuilder</a><br> |
| 124 | <br> |
| 125 | The constructed <a href="__builtin__.html#object">object</a> should be a callable <a href="__builtin__.html#object">object</a><br> |
| 126 | that can replace the class HttpResponse.<br> |
| 127 | <br> |
| 128 | responses - A dictionary that maps methodIds into tuples<br> |
| 129 | of (httplib2.Response, content). The methodId<br> |
| 130 | comes from the 'rpcName' field in the discovery<br> |
| 131 | document.</tt></dd></dl> |
| 132 | |
| 133 | <hr> |
| 134 | Data descriptors defined here:<br> |
| 135 | <dl><dt><strong>__dict__</strong></dt> |
| 136 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 137 | </dl> |
| 138 | <dl><dt><strong>__weakref__</strong></dt> |
| 139 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 140 | </dl> |
| 141 | </td></tr></table></td></tr></table><p> |
| 142 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 143 | <tr bgcolor="#eeaa77"> |
| 144 | <td colspan=3 valign=bottom> <br> |
| 145 | <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
| 146 | |
| 147 | <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
| 148 | <td width="100%"><dl><dt><a name="-tunnel_patch"><strong>tunnel_patch</strong></a>(http)</dt><dd><tt>Tunnel PATCH requests over POST.<br> |
| 149 | Args:<br> |
| 150 | http - An instance of httplib2.Http<br> |
| 151 | or something that acts like it.<br> |
| 152 | <br> |
| 153 | Returns:<br> |
| 154 | A modified instance of http that was passed in.<br> |
| 155 | <br> |
| 156 | Example:<br> |
| 157 | <br> |
| 158 | h = httplib2.Http()<br> |
| 159 | h = <a href="#-tunnel_patch">tunnel_patch</a>(h, "my-app-name/6.0")<br> |
| 160 | <br> |
| 161 | Useful if you are running on a platform that doesn't support PATCH.<br> |
| 162 | Apply this last if you are using OAuth 1.0, as changing the method<br> |
| 163 | will result in a different signature.</tt></dd></dl> |
| 164 | </td></tr></table><p> |
| 165 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 166 | <tr bgcolor="#55aa55"> |
| 167 | <td colspan=3 valign=bottom> <br> |
| 168 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 169 | |
| 170 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 171 | <td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder', 'HttpMockset_user_agent', 'tunnel_patch']<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 172 | <strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p> |
| 173 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 174 | <tr bgcolor="#7799ee"> |
| 175 | <td colspan=3 valign=bottom> <br> |
| 176 | <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| 177 | |
| 178 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| 179 | <td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table> |
| 180 | </body></html> |