Editing API
Jump to navigation
Jump to search
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: | ||
< | <tt>bash curl -X POST -d open=True http://api.noisebridge.net/gate/</tt> | ||
curl -X POST -d open=True http://api.noisebridge.net/gate/ | |||
=== GET /hello/[name] === | === GET /hello/[name] === | ||
Line 32: | Line 27: | ||
=== GET /gate/ === | === GET /gate/ === | ||
Gets interesting | Gets interesting stats about the gate. Currently: | ||
<tt>json { ringing: boolean }</tt> | |||
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. | ||
=== POST /gate/ === | === POST /gate/ === | ||
Line 45: | Line 37: | ||
With open=True, opens the door. Returns a 300 error if unsuccessful, and the following additions to the /gate/ stats if successful: | With open=True, opens the door. Returns a 300 error if unsuccessful, and the following additions to the /gate/ stats if successful: | ||
< | <tt>json { open : True message: string }</tt> | ||
open : True | |||
message: string | |||
}</ | |||
== Adding to the API == | == Adding to the API == | ||
Line 104: | Line 45: | ||
Just add a function of the form: | Just add a function of the form: | ||
< | <tt>python @api_app.route("/myurl/") def myfunc() do_something_in_the_space() return { 'success' : True, 'OMG IT WORXORRED' }</tt> | ||
@api_app.route("/myurl/") | |||
def myfunc() | |||
do_something_in_the_space() | |||
return { 'success' : True, 'OMG IT WORXORRED' } | |||
</ | |||
== Deploying your new API == | == Deploying your new API == | ||
You'll need sudo powers on | You'll need sudo powers on pony. Check out the code using git: | ||
<tt>bash git clone /var/local/noise_api/</tt> | |||
Make your changes, and test them locally using | Make your changes, and test them locally using | ||
< | <tt>bash python api.py --debug</tt> | ||
</ | |||
When you're ready to deploy, commit the code, then pull it out to the runningversion of api.py. | |||
< | <tt>bash cd /var/local/noise_api/ sudo git pull [your cloned directory goes here] sudo make install</tt> | ||
</ |