mirror of https://github.com/zulip/zulip.git
119 lines
5.7 KiB
HTML
119 lines
5.7 KiB
HTML
|
{% extends "zephyr/portico.html" %}
|
||
|
|
||
|
{# API information page #}
|
||
|
|
||
|
{% block customhead %}
|
||
|
{{ block.super }}
|
||
|
<link rel="stylesheet" href="/static/styles/pygments.css" />
|
||
|
{% endblock %}
|
||
|
|
||
|
{% block portico_content %}
|
||
|
<div class="row-fluid">
|
||
|
<div class="span8">
|
||
|
<h2>We hear you like APIs...</h2>
|
||
|
|
||
|
<a href="https://humbughq.com/dist/api/python-humbug_0.1.0.tar.gz" class="btn btn-large btn-primary btn-block" type="button"><i class="icon-download icon-white"></i> Download Python bindings and examples</a>
|
||
|
<span class="pull-right muted">Version 0.1.0</span>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<h3>Installation instructions</h3>
|
||
|
<p>This package uses distutils, so you can just run <code>python setup.py install</code> after downloading.</p>
|
||
|
<p>You can find your API key on your <a href="/#settings" target="_blank">settings page</a>. Once you have it, create <code>~/.humbugrc</code> and add the following text to it:</p>
|
||
|
|
||
|
<div class="codehilite"><pre>[api]
|
||
|
key=YOUR_API_KEY
|
||
|
email=YOUR_EMAIL_ADDRESS</pre></div>
|
||
|
</p>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<h3>Usage examples</h3>
|
||
|
<ul class="nav nav-tabs" id="api-example-tabs">
|
||
|
<li class="active"><a href="#curl" data-toggle="tab">curl</a></li>
|
||
|
<li><a href="#python" data-toggle="tab">Python</a></li>
|
||
|
<li><a href="#commandline" data-toggle="tab">humbug-send</a></li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="tab-content">
|
||
|
|
||
|
<div class="tab-pane active" id="curl">
|
||
|
<p>No download required!</p>
|
||
|
|
||
|
{% comment %}
|
||
|
These code snippets are generated using our very own Humbug tool, by
|
||
|
sending them to myself in a code block, and then using the inspector
|
||
|
to pull out the resulting HTML :)
|
||
|
{% endcomment %}
|
||
|
|
||
|
<h4>Stream message</h4>
|
||
|
<div class="codehilite"><pre>curl https://humbughq.com/api/v1/send_message <span class="se">\</span>
|
||
|
-d <span class="s2">"api-key=YOUR_API_KEY"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"email=YOUR_EMAIL"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"type=stream"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"to=Denmark"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"subject=Castle"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"content=Something is rotten in the state of Denmark."</span>
|
||
|
</pre></div>
|
||
|
|
||
|
<h4>Private message</h4>
|
||
|
<div class="codehilite"><pre>curl https://humbughq.com/api/v1/send_message <span class="se">\</span>
|
||
|
-d <span class="s2">"api-key=YOUR_API_KEY"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"email=YOUR_EMAIL"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"type=private"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"to=wdaher@humbughq.com"</span> <span class="se">\</span>
|
||
|
-d <span class="s2">"content=I come not, friends, to steal away your hearts."</span>
|
||
|
</pre></div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div class="tab-pane" id="python">
|
||
|
<div class="codehilite"><pre><span class="c">#!/usr/bin/env python</span>
|
||
|
|
||
|
<span class="kn">import</span> <span class="nn">humbug</span>
|
||
|
<span class="n">client</span> <span class="o">=</span> <span class="n">humbug</span><span class="o">.</span><span class="n">Client</span><span class="p">(</span>
|
||
|
<span class="c"> # These options are only necessary if you didn't make a .humbugrc</span>
|
||
|
<span class="c"> # api_key=YOUR_API_KEY,</span>
|
||
|
<span class="c"> # email=YOUR_EMAIL_ADDRESS,</span>
|
||
|
<span class="n">verbose</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
||
|
|
||
|
<span class="n">stream_message</span> <span class="o">=</span> <span class="p">{</span>
|
||
|
<span class="s">"type"</span><span class="p">:</span> <span class="s">"stream"</span><span class="p">,</span>
|
||
|
<span class="s">"to"</span><span class="p">:</span> <span class="s">"Denmark"</span><span class="p">,</span>
|
||
|
<span class="s">"subject"</span><span class="p">:</span> <span class="s">"Castle"</span><span class="p">,</span>
|
||
|
<span class="s">"content"</span><span class="p">:</span> <span class="s">"Something is rotten in the state of Denmark."</span>
|
||
|
<span class="p">}</span>
|
||
|
|
||
|
<span class="n">private_message</span> <span class="o">=</span> <span class="p">{</span>
|
||
|
<span class="s">"type"</span><span class="p">:</span> <span class="s">"private"</span><span class="p">,</span>
|
||
|
<span class="s">"to"</span><span class="p">:</span> <span class="s">"wdaher@humbughq.com"</span><span class="p">,</span>
|
||
|
<span class="s">"content"</span><span class="p">:</span> <span class="s">"I come not, friends, to steal away your hearts."</span>
|
||
|
<span class="p">}</span>
|
||
|
|
||
|
<span class="k">print</span> <span class="n">client</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">stream_message</span><span class="p">)</span>
|
||
|
<span class="k">print</span> <span class="n">client</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">private_message</span><span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div class="tab-pane" id="commandline">
|
||
|
<p>You can use <code>humbug-send</code> (found in <code>bin/</code> in the tarball) to easily send Humbugs from the command-line, providing the message to be sent on STDIN.
|
||
|
|
||
|
<h4>Stream message</h4>
|
||
|
<div class="codehilite"><pre>humbug-send --stream Denmark --subject Castle</span></pre></div>
|
||
|
|
||
|
<h4>Private message</h4>
|
||
|
<div class="codehilite"><pre>humbug-send wdaher@humbughq.com</span>
|
||
|
</pre></div>
|
||
|
|
||
|
<h4>Passing in the message on the command-line</h4>
|
||
|
<p>If you'd like, you can also provide the message on the command-line with the <code>-m</code> flag, as follows:</p>
|
||
|
<div class="codehilite"><pre>humbug-send --stream Denmark --subject Castle -m <span class="s2">"Something is rotten in the state of Denmark."</span>
|
||
|
</pre></div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
{% endblock %}
|