blob: b18e2dee544096eaf31b9573226170d44edd6b5e [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 Gregorio6e537032011-02-09 23:04:26 -050011><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiary/apiclient/http.py">/home/jcgregorio/projects/apiary/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>
26</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
Joe Gregorio6e537032011-02-09 23:04:26 -050027<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
Joe Gregorio30dfdc32010-12-09 16:34:22 -050028<tr bgcolor="#ee77aa">
29<td colspan=3 valign=bottom>&nbsp;<br>
30<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
31
32<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
33<td width="100%"><dl>
34<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
35</font></dt><dd>
36<dl>
Joe Gregoriocb8103d2011-02-11 23:20:52 -050037<dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpMock">HttpMock</a>
38</font></dt><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>
Joe Gregoriocb8103d2011-02-11 23:20:52 -050047<font color="#000000" face="helvetica, arial"><a name="HttpMock">class <strong>HttpMock</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>Mock&nbsp;of&nbsp;httplib2.Http<br>&nbsp;</tt></td></tr>
51<tr><td>&nbsp;</td>
52<td width="100%">Methods defined here:<br>
53<dl><dt><a name="HttpMock-__init__"><strong>__init__</strong></a>(self, filename, headers)</dt><dd><tt>Args:<br>
54&nbsp;&nbsp;filename:&nbsp;string,&nbsp;absolute&nbsp;filename&nbsp;to&nbsp;read&nbsp;response&nbsp;from<br>
55&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;header&nbsp;to&nbsp;return&nbsp;with&nbsp;response</tt></dd></dl>
56
57<dl><dt><a name="HttpMock-request"><strong>request</strong></a>(self, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, redirections<font color="#909090">=1</font>, connection_type<font color="#909090">=None</font>)</dt></dl>
58
59<hr>
60Data descriptors defined here:<br>
61<dl><dt><strong>__dict__</strong></dt>
62<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
63</dl>
64<dl><dt><strong>__weakref__</strong></dt>
65<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
66</dl>
67</td></tr></table> <p>
68<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
69<tr bgcolor="#ffc8d8">
70<td colspan=3 valign=bottom>&nbsp;<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -050071<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>
72
73<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
74<td colspan=2><tt>Encapsulates&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>&nbsp;</tt></td></tr>
75<tr><td>&nbsp;</td>
76<td width="100%">Methods defined here:<br>
Joe Gregorioabda96f2011-02-11 20:19:33 -050077<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 -050078&nbsp;<br>
79Args:<br>
80&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 -050081&nbsp;&nbsp;postproc:&nbsp;callable,&nbsp;called&nbsp;on&nbsp;the&nbsp;HTTP&nbsp;response&nbsp;and&nbsp;content&nbsp;to&nbsp;transform<br>
82&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>
83&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 -050084&nbsp;&nbsp;uri:&nbsp;string,&nbsp;the&nbsp;absolute&nbsp;URI&nbsp;to&nbsp;send&nbsp;the&nbsp;request&nbsp;to<br>
85&nbsp;&nbsp;method:&nbsp;string,&nbsp;the&nbsp;HTTP&nbsp;method&nbsp;to&nbsp;use<br>
86&nbsp;&nbsp;body:&nbsp;string,&nbsp;the&nbsp;request&nbsp;body&nbsp;of&nbsp;the&nbsp;HTTP&nbsp;request<br>
87&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;the&nbsp;HTTP&nbsp;request&nbsp;headers<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -050088&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>
89
90<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>
91&nbsp;<br>
92Args:<br>
93&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>
94&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>
95&nbsp;<br>
96Returns:<br>
97&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>
98&nbsp;&nbsp;by&nbsp;the&nbsp;postproc.<br>
99&nbsp;<br>
100Raises:<br>
101&nbsp;&nbsp;apiclient.errors.HttpError&nbsp;if&nbsp;the&nbsp;response&nbsp;was&nbsp;not&nbsp;a&nbsp;2xx.<br>
102&nbsp;&nbsp;httplib2.Error&nbsp;if&nbsp;a&nbsp;transport&nbsp;error&nbsp;has&nbsp;occured.</tt></dd></dl>
103
104<hr>
105Data descriptors defined here:<br>
106<dl><dt><strong>__dict__</strong></dt>
107<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
108</dl>
109<dl><dt><strong>__weakref__</strong></dt>
110<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
111</dl>
112</td></tr></table> <p>
113<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
114<tr bgcolor="#ffc8d8">
115<td colspan=3 valign=bottom>&nbsp;<br>
116<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>
117
118<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
119<td colspan=2><tt>A&nbsp;simple&nbsp;mock&nbsp;of&nbsp;<a href="#HttpRequest">HttpRequest</a><br>
120&nbsp;<br>
121Pass&nbsp;in&nbsp;a&nbsp;dictionary&nbsp;to&nbsp;the&nbsp;constructor&nbsp;that&nbsp;maps&nbsp;request&nbsp;methodIds&nbsp;to<br>
122tuples&nbsp;of&nbsp;(httplib2.Response,&nbsp;content)&nbsp;that&nbsp;should&nbsp;be&nbsp;returned&nbsp;when&nbsp;that<br>
123method&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>
124which&nbsp;case&nbsp;a&nbsp;200&nbsp;OK&nbsp;response&nbsp;will&nbsp;be&nbsp;generated.<br>
125&nbsp;<br>
126Example:<br>
127&nbsp;&nbsp;response&nbsp;=&nbsp;'{"data":&nbsp;{"id":&nbsp;"tag:google.c...'<br>
128&nbsp;&nbsp;requestBuilder&nbsp;=&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a>(<br>
129&nbsp;&nbsp;&nbsp;&nbsp;{<br>
130&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'chili.activities.get':&nbsp;(None,&nbsp;response),<br>
131&nbsp;&nbsp;&nbsp;&nbsp;}<br>
132&nbsp;&nbsp;)<br>
133&nbsp;&nbsp;apiclient.discovery.build("buzz",&nbsp;"v1",&nbsp;requestBuilder=requestBuilder)<br>
134&nbsp;<br>
135Methods&nbsp;that&nbsp;you&nbsp;do&nbsp;not&nbsp;supply&nbsp;a&nbsp;response&nbsp;for&nbsp;will&nbsp;return&nbsp;a<br>
136200&nbsp;OK&nbsp;with&nbsp;an&nbsp;empty&nbsp;string&nbsp;as&nbsp;the&nbsp;response&nbsp;content.&nbsp;The&nbsp;methodId<br>
137is&nbsp;taken&nbsp;from&nbsp;the&nbsp;rpcName&nbsp;in&nbsp;the&nbsp;discovery&nbsp;document.<br>
138&nbsp;<br>
139For&nbsp;more&nbsp;details&nbsp;see&nbsp;the&nbsp;project&nbsp;wiki.<br>&nbsp;</tt></td></tr>
140<tr><td>&nbsp;</td>
141<td width="100%">Methods defined here:<br>
Joe Gregorioabda96f2011-02-11 20:19:33 -0500142<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 -0500143of&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>
144<a href="#HttpRequest">HttpRequest</a>.execute().&nbsp;See&nbsp;that&nbsp;method&nbsp;for&nbsp;the&nbsp;description&nbsp;of&nbsp;the<br>
145parameters&nbsp;and&nbsp;the&nbsp;expected&nbsp;response.</tt></dd></dl>
146
147<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>
148&nbsp;<br>
149The&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>
150that&nbsp;can&nbsp;replace&nbsp;the&nbsp;class&nbsp;HttpResponse.<br>
151&nbsp;<br>
152responses&nbsp;-&nbsp;A&nbsp;dictionary&nbsp;that&nbsp;maps&nbsp;methodIds&nbsp;into&nbsp;tuples<br>
153&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;(httplib2.Response,&nbsp;content).&nbsp;The&nbsp;methodId<br>
154&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>
155&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.</tt></dd></dl>
156
157<hr>
158Data descriptors defined here:<br>
159<dl><dt><strong>__dict__</strong></dt>
160<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
161</dl>
162<dl><dt><strong>__weakref__</strong></dt>
163<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
164</dl>
165</td></tr></table></td></tr></table><p>
166<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
167<tr bgcolor="#55aa55">
168<td colspan=3 valign=bottom>&nbsp;<br>
169<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
170
171<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
Joe Gregoriocb8103d2011-02-11 23:20:52 -0500172<td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder', 'HttpMock']<br>
Joe Gregorio30dfdc32010-12-09 16:34:22 -0500173<strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p>
174<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
175<tr bgcolor="#7799ee">
176<td colspan=3 valign=bottom>&nbsp;<br>
177<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
178
179<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
180<td width="100%">jcgregorio@google.com&nbsp;(Joe&nbsp;Gregorio)</td></tr></table>
181</body></html>