Initial commit.
This commit is contained in:
commit
f847d5dc01
2 changed files with 71 additions and 0 deletions
30
README.md
Normal file
30
README.md
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Ubuntu One SyncDaemon REST API Server
|
||||||
|
|
||||||
|
## What's it do?
|
||||||
|
|
||||||
|
Creates a RESTful interface to Ubuntu One's DBus interface that lives on port 3000 and can be utlized to build client side web applications on top of Ubuntu One.
|
||||||
|
|
||||||
|
## Why does this exist?
|
||||||
|
|
||||||
|
This little server is the result of fighting with the PHP DBus bindings and trying it to work in the local user space. This is a rewrite of a Node.js version I wrote previously to utilize actual DBus bindings instead of relying on parsing the output of dbus-send
|
||||||
|
|
||||||
|
## How do I run it?
|
||||||
|
|
||||||
|
Assuming you already have Python (and any additional libraries) on your system and are running Ubuntu (Only OS I'll be testing this one) then all you need to do is run:
|
||||||
|
|
||||||
|
./ubuntuone.py
|
||||||
|
|
||||||
|
## How do I talk to it?
|
||||||
|
|
||||||
|
Communicating with the server can be done by pointing your web browser to http://localhost:3000/status/current_status
|
||||||
|
|
||||||
|
The format of the URI is /objectPath/method
|
||||||
|
|
||||||
|
The data is returned as JSON
|
||||||
|
|
||||||
|
## What's the future hold?
|
||||||
|
|
||||||
|
* Documentation page when calling the server with no path
|
||||||
|
* Support for the root object path's methods (connect, disconnect, et cetera)
|
||||||
|
* POST methods to push as well as pull data
|
||||||
|
* Potentially spinning off this server into a more generic DBus web interface
|
41
ubuntuone.py
Executable file
41
ubuntuone.py
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||||
|
import urlparse
|
||||||
|
import dbus
|
||||||
|
import json
|
||||||
|
|
||||||
|
bus = dbus.SessionBus()
|
||||||
|
|
||||||
|
class GetHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
parts = self.path.lower().split('/')
|
||||||
|
|
||||||
|
payload = '{"error": "invalid request"}'
|
||||||
|
|
||||||
|
if len(parts) == 3:
|
||||||
|
interface = parts[1]
|
||||||
|
method = parts[2]
|
||||||
|
|
||||||
|
u1_object = bus.get_object('com.ubuntuone.SyncDaemon', '/' + interface)
|
||||||
|
u1_interface = dbus.Interface(u1_object, 'com.ubuntuone.SyncDaemon.' + interface.capitalize())
|
||||||
|
|
||||||
|
try:
|
||||||
|
func = getattr(u1_interface, method)
|
||||||
|
except AttributeError:
|
||||||
|
payload = '{"error": "unknown method"}'
|
||||||
|
else:
|
||||||
|
payload = json.dumps(func())
|
||||||
|
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-Type', 'application/json')
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(payload)
|
||||||
|
return
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from BaseHTTPServer import HTTPServer
|
||||||
|
server = HTTPServer(('', 3000), GetHandler)
|
||||||
|
print 'Starting server, use <Ctrl-C> to stop'
|
||||||
|
server.serve_forever()
|
Loading…
Add table
Add a link
Reference in a new issue