blob: 0cbc0a6129394f9268680f95c1add1bd42676896 [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 Gregorioa8451672011-09-15 09:53:21 -040011><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 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>
Joe Gregorioa8451672011-09-15 09:53:21 -040098tuples&nbsp;of&nbsp;(httplib2.Response,&nbsp;content,&nbsp;opt_expected_body)&nbsp;that&nbsp;should&nbsp;be<br>
99returned&nbsp;when&nbsp;that&nbsp;method&nbsp;is&nbsp;called.&nbsp;None&nbsp;may&nbsp;also&nbsp;be&nbsp;passed&nbsp;in&nbsp;for&nbsp;the<br>
100httplib2.Response,&nbsp;in&nbsp;which&nbsp;case&nbsp;a&nbsp;200&nbsp;OK&nbsp;response&nbsp;will&nbsp;be&nbsp;generated.<br>
101If&nbsp;an&nbsp;opt_expected_body&nbsp;(str&nbsp;or&nbsp;dict)&nbsp;is&nbsp;provided,&nbsp;it&nbsp;will&nbsp;be&nbsp;compared&nbsp;to<br>
102the&nbsp;body&nbsp;and&nbsp;UnexpectedBodyError&nbsp;will&nbsp;be&nbsp;raised&nbsp;on&nbsp;inequality.<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500103&nbsp;<br>
104Example:<br>
105&nbsp;&nbsp;response&nbsp;=&nbsp;'{"data":&nbsp;{"id":&nbsp;"tag:google.c...'<br>
106&nbsp;&nbsp;requestBuilder&nbsp;=&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a>(<br>
107&nbsp;&nbsp;&nbsp;&nbsp;{<br>
108&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'chili.activities.get':&nbsp;(None,&nbsp;response),<br>
109&nbsp;&nbsp;&nbsp;&nbsp;}<br>
110&nbsp;&nbsp;)<br>
111&nbsp;&nbsp;apiclient.discovery.build("buzz",&nbsp;"v1",&nbsp;requestBuilder=requestBuilder)<br>
112&nbsp;<br>
113Methods&nbsp;that&nbsp;you&nbsp;do&nbsp;not&nbsp;supply&nbsp;a&nbsp;response&nbsp;for&nbsp;will&nbsp;return&nbsp;a<br>
Joe Gregorioa8451672011-09-15 09:53:21 -0400114200&nbsp;OK&nbsp;with&nbsp;an&nbsp;empty&nbsp;string&nbsp;as&nbsp;the&nbsp;response&nbsp;content&nbsp;or&nbsp;raise&nbsp;an&nbsp;excpetion&nbsp;if<br>
115check_unexpected&nbsp;is&nbsp;set&nbsp;to&nbsp;True.&nbsp;The&nbsp;methodId&nbsp;is&nbsp;taken&nbsp;from&nbsp;the&nbsp;rpcName<br>
116in&nbsp;the&nbsp;discovery&nbsp;document.<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500117&nbsp;<br>
118For&nbsp;more&nbsp;details&nbsp;see&nbsp;the&nbsp;project&nbsp;wiki.<br>&nbsp;</tt></td></tr>
119<tr><td>&nbsp;</td>
120<td width="100%">Methods defined here:<br>
Joe Gregorioabda96f2011-02-11 20:19:33 -0500121<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 -0500122of&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>
123<a href="#HttpRequest">HttpRequest</a>.execute().&nbsp;See&nbsp;that&nbsp;method&nbsp;for&nbsp;the&nbsp;description&nbsp;of&nbsp;the<br>
124parameters&nbsp;and&nbsp;the&nbsp;expected&nbsp;response.</tt></dd></dl>
125
Joe Gregorioa8451672011-09-15 09:53:21 -0400126<dl><dt><a name="RequestMockBuilder-__init__"><strong>__init__</strong></a>(self, responses, check_unexpected<font color="#909090">=False</font>)</dt><dd><tt>Constructor&nbsp;for&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a><br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500127&nbsp;<br>
128The&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>
129that&nbsp;can&nbsp;replace&nbsp;the&nbsp;class&nbsp;HttpResponse.<br>
130&nbsp;<br>
131responses&nbsp;-&nbsp;A&nbsp;dictionary&nbsp;that&nbsp;maps&nbsp;methodIds&nbsp;into&nbsp;tuples<br>
132&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;(httplib2.Response,&nbsp;content).&nbsp;The&nbsp;methodId<br>
133&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>
Joe Gregorioa8451672011-09-15 09:53:21 -0400134&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.<br>
135check_unexpected&nbsp;-&nbsp;A&nbsp;boolean&nbsp;setting&nbsp;whether&nbsp;or&nbsp;not&nbsp;UnexpectedMethodError<br>
136&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;should&nbsp;be&nbsp;raised&nbsp;on&nbsp;unsupplied&nbsp;method.</tt></dd></dl>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500137
138<hr>
139Data descriptors defined here:<br>
140<dl><dt><strong>__dict__</strong></dt>
141<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
142</dl>
143<dl><dt><strong>__weakref__</strong></dt>
144<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
145</dl>
146</td></tr></table></td></tr></table><p>
147<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
Joe Gregorio20a5aa92011-04-01 17:44:25 -0400148<tr bgcolor="#eeaa77">
149<td colspan=3 valign=bottom>&nbsp;<br>
150<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
151
152<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
153<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>
154Args:<br>
155&nbsp;&nbsp;&nbsp;http&nbsp;-&nbsp;An&nbsp;instance&nbsp;of&nbsp;httplib2.Http<br>
156&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;something&nbsp;that&nbsp;acts&nbsp;like&nbsp;it.<br>
157&nbsp;<br>
158Returns:<br>
159&nbsp;&nbsp;&nbsp;A&nbsp;modified&nbsp;instance&nbsp;of&nbsp;http&nbsp;that&nbsp;was&nbsp;passed&nbsp;in.<br>
160&nbsp;<br>
161Example:<br>
162&nbsp;<br>
163&nbsp;&nbsp;h&nbsp;=&nbsp;httplib2.Http()<br>
164&nbsp;&nbsp;h&nbsp;=&nbsp;<a href="#-tunnel_patch">tunnel_patch</a>(h,&nbsp;"my-app-name/6.0")<br>
165&nbsp;<br>
166Useful&nbsp;if&nbsp;you&nbsp;are&nbsp;running&nbsp;on&nbsp;a&nbsp;platform&nbsp;that&nbsp;doesn't&nbsp;support&nbsp;PATCH.<br>
167Apply&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>
168will&nbsp;result&nbsp;in&nbsp;a&nbsp;different&nbsp;signature.</tt></dd></dl>
169</td></tr></table><p>
170<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500171<tr bgcolor="#55aa55">
172<td colspan=3 valign=bottom>&nbsp;<br>
173<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
174
175<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
Joe Gregorio20a5aa92011-04-01 17:44:25 -0400176<td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder', 'HttpMockset_user_agent', 'tunnel_patch']<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500177<strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p>
178<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
179<tr bgcolor="#7799ee">
180<td colspan=3 valign=bottom>&nbsp;<br>
181<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
182
183<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
184<td width="100%">jcgregorio@google.com&nbsp;(Joe&nbsp;Gregorio)</td></tr></table>
185</body></html>