/usr/share/doc/python-beanbag-doc/html/v1.html is in python-beanbag-doc 1.9.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>beanbag.v1 – Original-style REST API access — beanbag 1.9.2 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.9.2',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="beanbag 1.9.2 documentation" href="index.html" />
<link rel="next" title="beanbag.auth – Authentication Helpers" href="auth.html" />
<link rel="prev" title="beanbag.v2 – REST API access" href="v2.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="auth.html" title="beanbag.auth – Authentication Helpers"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="v2.html" title="beanbag.v2 – REST API access"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">beanbag 1.9.2 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<span class="target" id="module-beanbag.v1"></span><div class="section" id="beanbag-v1-original-style-rest-api-access">
<h1>beanbag.v1 – Original-style REST API access<a class="headerlink" href="#beanbag-v1-original-style-rest-api-access" title="Permalink to this headline">¶</a></h1>
<p>Setup:</p>
<div class="code python highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">beanbag.v1</span> <span class="kn">as</span> <span class="nn">beanbag</span>
<span class="gp">>>> </span><span class="n">foo</span> <span class="o">=</span> <span class="n">beanbag</span><span class="o">.</span><span class="n">BeanBag</span><span class="p">(</span><span class="s2">"http://hostname/api/"</span><span class="p">)</span>
</pre></div>
</div>
<p>To do REST queries, then:</p>
<div class="code python highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">foo</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="n">p1</span><span class="o">=</span><span class="mf">3.14</span><span class="p">,</span> <span class="n">p2</span><span class="o">=</span><span class="mf">2.718</span><span class="p">)</span> <span class="c1"># GET request</span>
<span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">foo</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span> <span class="p">{</span><span class="s2">"a"</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">:</span> <span class="mi">7</span><span class="p">}</span> <span class="p">)</span> <span class="c1"># POST request</span>
<span class="gp">>>> </span><span class="k">del</span> <span class="n">foo</span><span class="o">.</span><span class="n">resource</span> <span class="c1"># DELETE request</span>
<span class="gp">>>> </span><span class="n">foo</span><span class="o">.</span><span class="n">resource</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"a"</span> <span class="p">:</span> <span class="mi">7</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span> <span class="c1"># PUT request</span>
<span class="gp">>>> </span><span class="n">foo</span><span class="o">.</span><span class="n">resource</span> <span class="o">+=</span> <span class="p">{</span><span class="s2">"a"</span> <span class="p">:</span> <span class="mi">7</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span> <span class="c1"># PATCH request</span>
</pre></div>
</div>
<p>You can chain paths as well:</p>
<div class="code python highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="o">.</span><span class="n">baz</span><span class="p">[</span><span class="mi">3</span><span class="p">][</span><span class="s2">"xyzzy"</span><span class="p">]</span><span class="o">.</span><span class="n">q</span><span class="p">)</span>
<span class="go">http://hostname/api/foo/bar/baz/3/xyzzy/q</span>
</pre></div>
</div>
<p>To do a request on a resource that requires a trailing slash:</p>
<div class="code python highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="o">.</span><span class="n">_</span><span class="p">)</span>
<span class="go">http://hostname/api/foo/bar/</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="p">[</span><span class="s2">""</span><span class="p">])</span>
<span class="go">http://hostname/api/foo/bar/</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="p">[</span><span class="s2">"/"</span><span class="p">])</span>
<span class="go">http://hostname/api/foo/bar/</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="p">[</span><span class="s2">"bar/"</span><span class="p">])</span>
<span class="go">http://hostname/api/foo/bar/</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="o">.</span><span class="n">_</span><span class="o">.</span><span class="n">x</span> <span class="o">==</span> <span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="p">[</span><span class="s2">"_"</span><span class="p">])</span>
<span class="go">http://hostname/api/foo/bar/_</span>
</pre></div>
</div>
<p>To access REST interfaces that require authentication, you need to
specify a session object. BeanBag supplies helpers to make Kerberos
and OAuth 1.0a authentication easier.</p>
<p>To setup oauth using OAuth1 directly:</p>
<div class="code python highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">requests</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">requests_oauth</span> <span class="kn">import</span> <span class="n">OAuth1</span>
<span class="gp">>>> </span><span class="n">session</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">session</span><span class="o">.</span><span class="n">auth</span> <span class="o">=</span> <span class="n">OAuth1</span><span class="p">(</span> <span class="n">consumer</span> <span class="n">creds</span><span class="p">,</span> <span class="n">user</span> <span class="n">creds</span> <span class="p">)</span>
<span class="gp">>>> </span><span class="n">foo</span> <span class="o">=</span> <span class="n">beanbag</span><span class="o">.</span><span class="n">BeanBag</span><span class="p">(</span><span class="s2">"http://hostname/api/"</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="n">session</span><span class="p">)</span>
</pre></div>
</div>
<p>Using the <code class="docutils literal"><span class="pre">OAuth10aDance</span></code> helper is probably a good plan though.</p>
<div class="section" id="beanbag-class">
<h2>BeanBag class<a class="headerlink" href="#beanbag-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="beanbag.v1.BeanBag">
<em class="property">class </em><code class="descclassname">beanbag.v1.</code><code class="descname">BeanBag</code><span class="sig-paren">(</span><em>base_url</em>, <em>ext=''</em>, <em>session=None</em>, <em>fmt='json'</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="beanbag.v1.BeanBag.__init__">
<code class="descname">__init__</code><span class="sig-paren">(</span><em>base_url</em>, <em>ext=''</em>, <em>session=None</em>, <em>fmt='json'</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a BeanBag referencing a base REST path.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>base_url</strong> – the base URL prefix for all resources</li>
<li><strong>ext</strong> – extension to add to resource URLs, eg ”.json”</li>
<li><strong>session</strong> – requests.Session instance used for this API. Useful
to set an auth procedure, or change verify parameter.</li>
<li><strong>fmt</strong> – either ‘json’ for json data, or a tuple specifying a
content-type string, encode function (for encoding the
request body) and a decode function (for decoding responses)</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__call__">
<code class="descname">__call__</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__call__" title="Permalink to this definition">¶</a></dt>
<dd><p>Make a GET, POST or generic request to a resource.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Example:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">BeanBag</span><span class="p">(</span><span class="s2">"http://host/api"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">x</span><span class="p">()</span> <span class="c1"># GET request</span>
<span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">x</span><span class="p">(</span><span class="n">p1</span><span class="o">=</span><span class="s1">'foo'</span><span class="p">,</span> <span class="n">p2</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># GET request with parameters passed via query string</span>
<span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">x</span><span class="p">(</span> <span class="p">{</span><span class="s1">'a'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'b'</span><span class="p">:</span> <span class="mi">2</span><span class="p">}</span> <span class="p">)</span> <span class="c1"># POST request</span>
<span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">x</span><span class="p">(</span> <span class="s2">"RANDOMIZE"</span><span class="p">,</span> <span class="p">{</span><span class="s1">'a'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'b'</span><span class="p">:</span> <span class="mi">2</span><span class="p">}</span> <span class="p">)</span> <span class="c1"># Custom HTTP verb with request body</span>
<span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">x</span><span class="p">(</span> <span class="s2">"OPTIONS"</span><span class="p">,</span> <span class="bp">None</span> <span class="p">)</span> <span class="c1"># Custom HTTP verb with empty request body</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__delattr__">
<code class="descname">__delattr__</code><span class="sig-paren">(</span><em>attr</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__delattr__" title="Permalink to this definition">¶</a></dt>
<dd><p>del self.attr</p>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__delitem__">
<code class="descname">__delitem__</code><span class="sig-paren">(</span><em>item</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__delitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>del self[item]</p>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__getattr__">
<code class="descname">__getattr__</code><span class="sig-paren">(</span><em>attr</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__getattr__" title="Permalink to this definition">¶</a></dt>
<dd><p>self.attr</p>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__getitem__">
<code class="descname">__getitem__</code><span class="sig-paren">(</span><em>item</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__getitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>self[attr]</p>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__iadd__">
<code class="descname">__iadd__</code><span class="sig-paren">(</span><em>val</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__iadd__" title="Permalink to this definition">¶</a></dt>
<dd><p>Make a PATCH request to a resource.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Example:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">BeanBag</span><span class="p">(</span><span class="s2">"http://host/api"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">x</span> <span class="o">+=</span> <span class="p">{</span><span class="s2">"op"</span><span class="p">:</span> <span class="s2">"replace"</span><span class="p">,</span> <span class="s2">"path"</span><span class="p">:</span> <span class="s2">"/a"</span><span class="p">,</span> <span class="s2">"value"</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__setattr__">
<code class="descname">__setattr__</code><span class="sig-paren">(</span><em>attr</em>, <em>val</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__setattr__" title="Permalink to this definition">¶</a></dt>
<dd><p>self.attr = val</p>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__setitem__">
<code class="descname">__setitem__</code><span class="sig-paren">(</span><em>item</em>, <em>val</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__setitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>self[item] = val</p>
</dd></dl>
<dl class="method">
<dt id="beanbag.v1.BeanBag.__str__">
<code class="descname">__str__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBag.__str__" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain the URL of a resource</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="beanbagexception">
<h2>BeanBagException<a class="headerlink" href="#beanbagexception" title="Permalink to this headline">¶</a></h2>
<dl class="exception">
<dt id="beanbag.v1.BeanBagException">
<em class="property">exception </em><code class="descclassname">beanbag.v1.</code><code class="descname">BeanBagException</code><span class="sig-paren">(</span><em>response</em>, <em>msg</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBagException" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception thrown when a BeanBag request fails.</p>
<dl class="docutils">
<dt>Data members:</dt>
<dd><ul class="first last simple">
<li>msg – exception string, brief and human readable</li>
<li>response – response object</li>
</ul>
</dd>
</dl>
<p>You can get the original request via bbe.response.request.</p>
<dl class="method">
<dt id="beanbag.v1.BeanBagException.__init__">
<code class="descname">__init__</code><span class="sig-paren">(</span><em>response</em>, <em>msg</em><span class="sig-paren">)</span><a class="headerlink" href="#beanbag.v1.BeanBagException.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a BeanBagException</p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">beanbag.v1 – Original-style REST API access</a><ul>
<li><a class="reference internal" href="#beanbag-class">BeanBag class</a></li>
<li><a class="reference internal" href="#beanbagexception">BeanBagException</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="v2.html"
title="previous chapter">beanbag.v2 – REST API access</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="auth.html"
title="next chapter">beanbag.auth – Authentication Helpers</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/v1.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="auth.html" title="beanbag.auth – Authentication Helpers"
>next</a> |</li>
<li class="right" >
<a href="v2.html" title="beanbag.v2 – REST API access"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">beanbag 1.9.2 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2015, Anthony Towns.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
</div>
</body>
</html>
|