blob: f2d9b11f89d6825461c061d7dc0805c04269698f [file] [log] [blame]
Joe Gregorio30dfdc32010-12-09 16:34:22 -05001
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>&nbsp;<br>
9<font color="#ffffff" face="helvetica, arial">&nbsp;<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 Gregorio351b1492011-05-08 23:32:46 -070011><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 Gregorio30dfdc32010-12-09 16:34:22 -050012 <p><tt>Classes&nbsp;to&nbsp;encapsulate&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>
13&nbsp;<br>
14The&nbsp;classes&nbsp;implement&nbsp;a&nbsp;command&nbsp;pattern,&nbsp;with&nbsp;every<br>
15<a href="__builtin__.html#object">object</a>&nbsp;supporting&nbsp;an&nbsp;execute()&nbsp;method&nbsp;that&nbsp;does&nbsp;the<br>
16actuall&nbsp;HTTP&nbsp;request.</tt></p>
17<p>
18<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
Joe Gregorio6e537032011-02-09 23:04:26 -050019<tr bgcolor="#aa55cc">
20<td colspan=3 valign=bottom>&nbsp;<br>
21<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
22
23<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
24<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="httplib2.html">httplib2</a><br>
Joe Gregoriocb8103d2011-02-11 23:20:52 -050025</td><td width="25%" valign=top><a href="os.html">os</a><br>
Joe Gregorio20a5aa92011-04-01 17:44:25 -040026</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 Gregorio6e537032011-02-09 23:04:26 -050028<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
Joe Gregorio30dfdc32010-12-09 16:34:22 -050029<tr bgcolor="#ee77aa">
30<td colspan=3 valign=bottom>&nbsp;<br>
31<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
32
33<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</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 Gregorio20a5aa92011-04-01 17:44:25 -040038<dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a>
Joe Gregorio30dfdc32010-12-09 16:34:22 -050039</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>&nbsp;<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>&nbsp;&nbsp;&nbsp;</tt></td>
50<td colspan=2><tt>Encapsulates&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>&nbsp;</tt></td></tr>
51<tr><td>&nbsp;</td>
52<td width="100%">Methods defined here:<br>
Joe Gregorioabda96f2011-02-11 20:19:33 -050053<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>
Joe Gregorio30dfdc32010-12-09 16:34:22 -050054&nbsp;<br>
55Args:<br>
56&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>
Joe Gregorioabda96f2011-02-11 20:19:33 -050057&nbsp;&nbsp;postproc:&nbsp;callable,&nbsp;called&nbsp;on&nbsp;the&nbsp;HTTP&nbsp;response&nbsp;and&nbsp;content&nbsp;to&nbsp;transform<br>
58&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>
59&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on&nbsp;an&nbsp;error.<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -050060&nbsp;&nbsp;uri:&nbsp;string,&nbsp;the&nbsp;absolute&nbsp;URI&nbsp;to&nbsp;send&nbsp;the&nbsp;request&nbsp;to<br>
61&nbsp;&nbsp;method:&nbsp;string,&nbsp;the&nbsp;HTTP&nbsp;method&nbsp;to&nbsp;use<br>
62&nbsp;&nbsp;body:&nbsp;string,&nbsp;the&nbsp;request&nbsp;body&nbsp;of&nbsp;the&nbsp;HTTP&nbsp;request<br>
63&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;the&nbsp;HTTP&nbsp;request&nbsp;headers<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -050064&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>
65
66<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>
67&nbsp;<br>
68Args:<br>
69&nbsp;&nbsp;http:&nbsp;httplib2.Http,&nbsp;an&nbsp;http&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;be&nbsp;used&nbsp;in&nbsp;place&nbsp;of&nbsp;the<br>
70&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;one&nbsp;the&nbsp;<a href="#HttpRequest">HttpRequest</a>&nbsp;request&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;was&nbsp;constructed&nbsp;with.<br>
71&nbsp;<br>
72Returns:<br>
73&nbsp;&nbsp;A&nbsp;deserialized&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;model&nbsp;of&nbsp;the&nbsp;response&nbsp;body&nbsp;as&nbsp;determined<br>
74&nbsp;&nbsp;by&nbsp;the&nbsp;postproc.<br>
75&nbsp;<br>
76Raises:<br>
77&nbsp;&nbsp;apiclient.errors.HttpError&nbsp;if&nbsp;the&nbsp;response&nbsp;was&nbsp;not&nbsp;a&nbsp;2xx.<br>
78&nbsp;&nbsp;httplib2.Error&nbsp;if&nbsp;a&nbsp;transport&nbsp;error&nbsp;has&nbsp;occured.</tt></dd></dl>
79
80<hr>
81Data descriptors defined here:<br>
82<dl><dt><strong>__dict__</strong></dt>
83<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
84</dl>
85<dl><dt><strong>__weakref__</strong></dt>
86<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;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>&nbsp;<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>&nbsp;&nbsp;&nbsp;</tt></td>
95<td colspan=2><tt>A&nbsp;simple&nbsp;mock&nbsp;of&nbsp;<a href="#HttpRequest">HttpRequest</a><br>
96&nbsp;<br>
97Pass&nbsp;in&nbsp;a&nbsp;dictionary&nbsp;to&nbsp;the&nbsp;constructor&nbsp;that&nbsp;maps&nbsp;request&nbsp;methodIds&nbsp;to<br>
98tuples&nbsp;of&nbsp;(httplib2.Response,&nbsp;content)&nbsp;that&nbsp;should&nbsp;be&nbsp;returned&nbsp;when&nbsp;that<br>
99method&nbsp;is&nbsp;called.&nbsp;None&nbsp;may&nbsp;also&nbsp;be&nbsp;passed&nbsp;in&nbsp;for&nbsp;the&nbsp;httplib2.Response,&nbsp;in<br>
100which&nbsp;case&nbsp;a&nbsp;200&nbsp;OK&nbsp;response&nbsp;will&nbsp;be&nbsp;generated.<br>
101&nbsp;<br>
102Example:<br>
103&nbsp;&nbsp;response&nbsp;=&nbsp;'{"data":&nbsp;{"id":&nbsp;"tag:google.c...'<br>
104&nbsp;&nbsp;requestBuilder&nbsp;=&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a>(<br>
105&nbsp;&nbsp;&nbsp;&nbsp;{<br>
106&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'chili.activities.get':&nbsp;(None,&nbsp;response),<br>
107&nbsp;&nbsp;&nbsp;&nbsp;}<br>
108&nbsp;&nbsp;)<br>
109&nbsp;&nbsp;apiclient.discovery.build("buzz",&nbsp;"v1",&nbsp;requestBuilder=requestBuilder)<br>
110&nbsp;<br>
111Methods&nbsp;that&nbsp;you&nbsp;do&nbsp;not&nbsp;supply&nbsp;a&nbsp;response&nbsp;for&nbsp;will&nbsp;return&nbsp;a<br>
112200&nbsp;OK&nbsp;with&nbsp;an&nbsp;empty&nbsp;string&nbsp;as&nbsp;the&nbsp;response&nbsp;content.&nbsp;The&nbsp;methodId<br>
113is&nbsp;taken&nbsp;from&nbsp;the&nbsp;rpcName&nbsp;in&nbsp;the&nbsp;discovery&nbsp;document.<br>
114&nbsp;<br>
115For&nbsp;more&nbsp;details&nbsp;see&nbsp;the&nbsp;project&nbsp;wiki.<br>&nbsp;</tt></td></tr>
116<tr><td>&nbsp;</td>
117<td width="100%">Methods defined here:<br>
Joe Gregorioabda96f2011-02-11 20:19:33 -0500118<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>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500119of&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>
120<a href="#HttpRequest">HttpRequest</a>.execute().&nbsp;See&nbsp;that&nbsp;method&nbsp;for&nbsp;the&nbsp;description&nbsp;of&nbsp;the<br>
121parameters&nbsp;and&nbsp;the&nbsp;expected&nbsp;response.</tt></dd></dl>
122
123<dl><dt><a name="RequestMockBuilder-__init__"><strong>__init__</strong></a>(self, responses)</dt><dd><tt>Constructor&nbsp;for&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a><br>
124&nbsp;<br>
125The&nbsp;constructed&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;should&nbsp;be&nbsp;a&nbsp;callable&nbsp;<a href="__builtin__.html#object">object</a><br>
126that&nbsp;can&nbsp;replace&nbsp;the&nbsp;class&nbsp;HttpResponse.<br>
127&nbsp;<br>
128responses&nbsp;-&nbsp;A&nbsp;dictionary&nbsp;that&nbsp;maps&nbsp;methodIds&nbsp;into&nbsp;tuples<br>
129&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;(httplib2.Response,&nbsp;content).&nbsp;The&nbsp;methodId<br>
130&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;comes&nbsp;from&nbsp;the&nbsp;'rpcName'&nbsp;field&nbsp;in&nbsp;the&nbsp;discovery<br>
131&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.</tt></dd></dl>
132
133<hr>
134Data descriptors defined here:<br>
135<dl><dt><strong>__dict__</strong></dt>
136<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
137</dl>
138<dl><dt><strong>__weakref__</strong></dt>
139<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;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 Gregorio20a5aa92011-04-01 17:44:25 -0400143<tr bgcolor="#eeaa77">
144<td colspan=3 valign=bottom>&nbsp;<br>
145<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
146
147<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
148<td width="100%"><dl><dt><a name="-tunnel_patch"><strong>tunnel_patch</strong></a>(http)</dt><dd><tt>Tunnel&nbsp;PATCH&nbsp;requests&nbsp;over&nbsp;POST.<br>
149Args:<br>
150&nbsp;&nbsp;&nbsp;http&nbsp;-&nbsp;An&nbsp;instance&nbsp;of&nbsp;httplib2.Http<br>
151&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;something&nbsp;that&nbsp;acts&nbsp;like&nbsp;it.<br>
152&nbsp;<br>
153Returns:<br>
154&nbsp;&nbsp;&nbsp;A&nbsp;modified&nbsp;instance&nbsp;of&nbsp;http&nbsp;that&nbsp;was&nbsp;passed&nbsp;in.<br>
155&nbsp;<br>
156Example:<br>
157&nbsp;<br>
158&nbsp;&nbsp;h&nbsp;=&nbsp;httplib2.Http()<br>
159&nbsp;&nbsp;h&nbsp;=&nbsp;<a href="#-tunnel_patch">tunnel_patch</a>(h,&nbsp;"my-app-name/6.0")<br>
160&nbsp;<br>
161Useful&nbsp;if&nbsp;you&nbsp;are&nbsp;running&nbsp;on&nbsp;a&nbsp;platform&nbsp;that&nbsp;doesn't&nbsp;support&nbsp;PATCH.<br>
162Apply&nbsp;this&nbsp;last&nbsp;if&nbsp;you&nbsp;are&nbsp;using&nbsp;OAuth&nbsp;1.0,&nbsp;as&nbsp;changing&nbsp;the&nbsp;method<br>
163will&nbsp;result&nbsp;in&nbsp;a&nbsp;different&nbsp;signature.</tt></dd></dl>
164</td></tr></table><p>
165<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500166<tr bgcolor="#55aa55">
167<td colspan=3 valign=bottom>&nbsp;<br>
168<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
169
170<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
Joe Gregorio20a5aa92011-04-01 17:44:25 -0400171<td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder', 'HttpMockset_user_agent', 'tunnel_patch']<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500172<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>&nbsp;<br>
176<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
177
178<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
179<td width="100%">jcgregorio@google.com&nbsp;(Joe&nbsp;Gregorio)</td></tr></table>
180</body></html>