Clean up the API main documentation a bit.

(imported from commit 7f9dc5f98ac50be6e7e6d4ce69716cb9477099f0)
This commit is contained in:
Tim Abbott 2013-08-08 14:08:09 -04:00
parent 06d6d14fd7
commit e3bd106397
1 changed files with 10 additions and 12 deletions

View File

@ -57,7 +57,7 @@ to pull out the resulting HTML :)
<div class="codehilite"><pre>curl https://api.zulip.com/v1/messages <span class="se">\</span>
-u BOT_EMAIL_ADDRESS:BOT_API_KEY <span class="se">\</span>
-d <span class="s2">"type=private"</span> <span class="se">\</span>
-d <span class="s2">"to=wdaher@example.com"</span> <span class="se">\</span>
-d <span class="s2">"to=hamlet@example.com"</span> <span class="se">\</span>
-d <span class="s2">"content=I come not, friends, to steal away your hearts."</span></pre>
</div>
@ -69,25 +69,23 @@ to pull out the resulting HTML :)
<span class="kn">import</span> <span class="nn">zulip</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="c"># Keyword arguments 'email' and 'api_key' are optional if you are using ~/.zuliprc</span>
<span class="c"># Keyword arguments 'email' and 'api_key' are not required if you are using ~/.zuliprc</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">zulip</span><span class="o">.</span><span class="n">Client</span><span class="p">(</span><span class="p">email</span><span class="o">=</span><span class="s">"othello-bot@example.com"</span><span class="p">,</span>
<span class="n">api_key</span><span class="o">=</span><span class="s">"a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5"</span><span class="p">)</span>
<span class="n">stream_message</span> <span class="o">=</span> <span class="p">{</span>
<span class="c"># Send a stream message</span>
<span class="n">client</span><span class="o">.</span><span class="n">send_message</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="p">})</span></span>
<span class="c"># Send a private message</span>
<span class="n">client</span><span class="o">.</span><span class="n">send_message</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@example.com"</span><span class="p">,</span>
<span class="s">"to"</span><span class="p">:</span> <span class="s">"hamlet@example.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>
<span class="p">})</span>
<span class="c"># Print each message the user receives</span>
<span class="n">client</span><span class="o">.</span><span class="n">call_on_each_message</span><span class="p">(</span><span class="k">lambda</span> <span class="n">msg</span><span class="p">:</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> <span class="o">+</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">))</span>
@ -103,7 +101,7 @@ to pull out the resulting HTML :)
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5</pre></div>
<h4>Private message</h4>
<div class="codehilite"><pre>zulip-send wdaher@example.com --user othello-bot@example.com \
<div class="codehilite"><pre>zulip-send hamlet@example.com --user othello-bot@example.com \
--api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
</pre></div>