Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (40 sloc) 8.51 KB
<!DOCTYPE html> <html> <head> <title>growl-notifier.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="commands.html"> commands.js </a> <a class="source" href="fancy-connfu-application.html"> fancy-connfu-application.js </a> <a class="source" href="growl-notifier.html"> growl-notifier.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> growl-notifier.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <h2>Introduction</h2>
<p>This is a usage example of the <strong>connFu</strong> node DSL. This
application must be run from the command line in an OSX machine
with <em>Grow</em> and <code>growlnotifier</code> installed.</p>
<p>Once launched, it listens to all the configured events in the application
and shows them as a Growl notification</p>
<h2>Running this example</h2>
<ul>
<li><p>First of all, you have to register into <a href="https://connfu.com">connFu.com</a>
an application. You will receive an <strong>application token</strong> which will be very useful ;)</p></li>
<li><p>Then, install the <code>connFu</code> and <code>growl</code> npm packages:</p>
<pre><code> $ npm install growl connfu
</code></pre></li>
<li><p>Then get the source of this example from <a href="https://github.com/bluevialabs/connfu-node/blob/master/examples/growl-notifier.coffee">here</a>
and run it!</p>
<pre><code> $ coffee growl-notifier.coffee &lt;application_token&gt;
</code></pre></li>
</ul> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h2>Annotated source</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Require <code>connfu</code> and <code>growl</code> packages</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">connFu = </span><span class="nx">require</span> <span class="s1">&#39;connfu&#39;</span>
<span class="nv">growl = </span><span class="nx">require</span> <span class="s1">&#39;growl&#39;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Check that we receive the <code>application_token</code> as an argument</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="mi">3</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Usage: coffee grow-notifier.coffee &lt;application_token&gt;&quot;</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Check if we have <code>growlnotifier</code> installed. To install it, download the
<code>growl</code> installer from <a href="http://growl.info/">here</a> and execute the installer
within <code>Extras</code> folder</p>
<p>If <code>growlnotifier</code> is not installed, show an error</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">growl</span><span class="p">.</span><span class="nx">binVersion</span> <span class="nf">(err, version) -&gt;</span>
<span class="k">if</span> <span class="nx">err</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;&#39;growlnotifier&#39; is required in order to run this application&quot;</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Create the connFu application</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">connFu</span><span class="p">.</span><span class="nx">createApp</span>
<span class="nv">apiKey: </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="nv">handlers:</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>When receiving any kind of event, send a notification to Growl</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">voice:</span>
<span class="nv">join: </span><span class="nf">(call) -&gt;</span>
<span class="nx">growl</span><span class="p">.</span><span class="nx">notify</span> <span class="s2">&quot;The number #{call.from} joined to the conference with number #{call.to}&quot;</span>
<span class="nv">leave: </span><span class="nf">(call) -&gt;</span>
<span class="nx">growl</span><span class="p">.</span><span class="nx">notify</span> <span class="s2">&quot;The number #{call.from} left the conference with number #{call.to}&quot;</span>
<span class="nv">twitter:</span>
<span class="k">new</span><span class="o">:</span> <span class="nf">(tweet) -&gt;</span>
<span class="nx">growl</span><span class="p">.</span><span class="nx">notify</span> <span class="nx">tweet</span><span class="p">.</span><span class="nx">content</span><span class="p">,</span> <span class="nv">title: </span><span class="s2">&quot;New Tweet from #{tweet.from}&quot;</span>
<span class="nv">sms:</span>
<span class="k">new</span><span class="o">:</span> <span class="nf">(sms) -&gt;</span>
<span class="nx">growl</span><span class="p">.</span><span class="nx">notify</span> <span class="nx">sms</span><span class="p">.</span><span class="nx">content</span><span class="p">,</span> <span class="nv">title: </span><span class="s2">&quot;New SMS from #{sms.from}&quot;</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Listen to <code>connFu</code> events!</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">listen</span><span class="p">()</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>