Editing API

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 15: Line 15:
For instance, to open the door using curl:
For instance, to open the door using curl:


<source lang="bash">
<source lang="bash">   curl -X POST -d open=True http://api.noisebridge.net/gate/</source>
    curl -X POST -d open=True http://api.noisebridge.net/gate/
 
    alternatively:
 
    curl --resolve 'api.noisebridge.net:80:172.30.0.4' -X POST -d open=True http://api.noisebridge.net/gate/
</source>
=== GET /hello/[name] ===
=== GET /hello/[name] ===


Line 32: Line 26:
=== GET /gate/ ===
=== GET /gate/ ===


Gets interesting info about the gate. If you send a &quot;Accept: application/json&quot; header, you'll get a status object, which is currently:
Gets interesting stats about the gate. Currently:


<pre class="json">    {
<pre class="json">    {
Line 38: Line 32:
     }</pre>
     }</pre>
Where 'ringing' is true if the gate buzzer is ringing at that moment, or in the last few seconds, as users may push the button for a very short time. The amount of time that this state is cached is totally up to the Gateman daemon that runs to interact with the gate hardware.
Where 'ringing' is true if the gate buzzer is ringing at that moment, or in the last few seconds, as users may push the button for a very short time. The amount of time that this state is cached is totally up to the Gateman daemon that runs to interact with the gate hardware.
If you send a &quot;Accept: text/html&quot; header (as web browsers do), it will return with some useful gate web forms, including one for opening the door with a keycode, and another for getting a new keycode.


=== POST /gate/ ===
=== POST /gate/ ===
Line 56: Line 48:


With create=True and an existing, valid doorcode, redirects to a URL of the form /gate/key/[newdoorcode] which gives a valid new doorcode to open the door.
With create=True and an existing, valid doorcode, redirects to a URL of the form /gate/key/[newdoorcode] which gives a valid new doorcode to open the door.
''Note: Jake asked me to (temporarily?) disable this, so I have''


With preferred=[number] you can suggest a doorcode you'd like to use. It's not guaranteed that the preferred option will be returned.
With preferred=[number] you can suggest a doorcode you'd like to use. It's not guaranteed that the preferred option will be returned.


Requires comment=[contact email address for new number]
Suppose you have a doorcode 8499146, and you'd like to give a friend a new doorcode. She asks if she can have the number '7895473'


Suppose you have a doorcode 8499146, and you'd like to give a friend a new doorcode. She asks if she can have the number '7895473'
  curl -v -X POST -d create=True -d preferred=7895473 http://api.noisebridge.net/gate/key/8499146


<source lang="bash">
would return something like this:
curl -v -X POST -d create=True -d preferred=7895473 \
  POST /gate/key/8499146 HTTP/1.1 &gt;
    -d comment=&quot;I'm Dara, my email is new@example.com&quot; http://localhost:8080/gate/key/8499146
  HTTP/1.0 303 See Other &lt;  
</source>
  Date: Mon, 05 Nov 2012 05:07:29 GMT &lt;
would return something like this:
  Server: WSGIServer/0.1 Python/2.7.3rc2 &lt;
  Content-Length: 0 &lt; Content-Type: text/html; charset=UTF-8 &lt;
  Location: http://api.noisebridge.net/gate/key/7895473 &lt;


<pre class="text">
&gt; POST /gate/key/8499146 HTTP/1.1
&gt; User-Agent: curl/7.26.0
&gt; Host: localhost:8080
&gt; Accept: */*
&gt; Content-Length: 29
&gt; Content-Type: application/x-www-form-urlencoded
&gt;
* upload completely sent off: 29 out of 29 bytes
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.0, assume close after body
&lt; HTTP/1.0 303 See Other
&lt; Date: Mon, 05 Nov 2012 05:07:29 GMT
&lt; localhost - - [04/Nov/2012 21:07:29] &quot;POST /gate/key/8499146 HTTP/1.1&quot; 303 0
Server: WSGIServer/0.1 Python/2.7.3rc2
&lt; Content-Length: 0
&lt; Content-Type: text/html; charset=UTF-8
&lt; Location: http://localhost:8080/gate/key/7895473
&lt;
* Closing connection #0
</pre>
The Location header contains the new doorcode.
The Location header contains the new doorcode.


Line 104: Line 75:
Just add a function of the form:
Just add a function of the form:


<source lang="python">
@api_app.route(&quot;/myurl/&quot;)
@api_app.route(&quot;/myurl/&quot;)
def myfunc()
def myfunc()
     do_something_in_the_space()
     do_something_in_the_space()
     return { 'success' : True, 'OMG IT WORXORRED' }
     return { 'success' : True, 'OMG IT WORXORRED' }
</source>
 
== Deploying your new API ==
== Deploying your new API ==


You'll need sudo powers on minotaur. Check out the code using git:
You'll need sudo powers on minotaur. Check out the code using git:


<source lang="bash">
     git clone git@github.com:noisebridge/noise-api.git
     git clone git@github.com:noisebridge/noise-api.git
</source>
 
Make your changes, and test them locally using
Make your changes, and test them locally using


<source lang="bash">
   python api.py --debug
   python api.py --debug
</source>
 
When you're ready to deploy, change the Debian changelog in debian/changelog (the [http://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.man.git.dch.html git-dch] program can help with this), and commit the code to the github repository..
When you're ready to deploy, change the Debian changelog in debian/changelog , and commit the code to the github repository..


Log onto minotaur, clone the git repository, and make a Debian package. Install it using dpkg -i
Log onto minotaur, clone the git repository, and make a Debian package. Install it using dpkg -i


<source lang="bash">
   git clone git://github.com/noisebridge/noise-api.git
   git clone git://github.com/noisebridge/noise-api.git
   cd noise-api
   cd noise-api
   make package
   make package
   sudo dpkg -i ../noisebridge-api_0[whatever the version number is]*.deb
   sudo dpkg -i ../noisebridge-api_0[whatever the version number is]*.deb
</source>
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)