summaryrefslogtreecommitdiffstats
path: root/docs/source/devguide/how-to
diff options
context:
space:
mode:
authorCalum Lind <calumlind@gmail.com>2018-10-05 09:33:26 +0100
committerCalum Lind <calumlind@gmail.com>2018-11-01 17:38:10 +0000
commit82ecf8a4168cafdc2bf0f5c37f7fa45d55e8d265 (patch)
treeefd52f493583a3c99853d6577660da0695e95fc8 /docs/source/devguide/how-to
parent9dcd90056d4225f65046fab4ed37a25e9caeda06 (diff)
downloaddeluge-82ecf8a4168cafdc2bf0f5c37f7fa45d55e8d265.tar.gz
deluge-82ecf8a4168cafdc2bf0f5c37f7fa45d55e8d265.tar.bz2
deluge-82ecf8a4168cafdc2bf0f5c37f7fa45d55e8d265.zip
[Docs] Reorganise and add sections from wiki
- Change the layout and contents of docs to be better organised and follow ideas from: https://www.divio.com/blog/documentation/ - Use markdown for non-technical documents to speed up writing. - Added new sections and imported documents from Trac wiki. Build fixes: - Added a patch to fix recommonmark 0.4 and doc referencing: https://github.com/rtfd/recommonmark/issues/93 - Set docs build in tox to Py2.7 since there are problems with autodoc mocking multiple inheritance on Python 3 resulting in metaclass errors. - Supressed warning about `modules.rst` not in the toctree by creating a static `modules.rst` with `:orphan:` file directive and add to git. Also skip creating this toc file with sphinx-apidoc in setup and tox. - Simplified finding exported RPC and JSON API methods by adding an autodoc custom class directive. Removed unneeded __rpcapi.py.
Diffstat (limited to 'docs/source/devguide/how-to')
-rw-r--r--docs/source/devguide/how-to/curl-jsonrpc.md162
-rw-r--r--docs/source/devguide/how-to/index.md8
2 files changed, 170 insertions, 0 deletions
diff --git a/docs/source/devguide/how-to/curl-jsonrpc.md b/docs/source/devguide/how-to/curl-jsonrpc.md
new file mode 100644
index 000000000..a89091141
--- /dev/null
+++ b/docs/source/devguide/how-to/curl-jsonrpc.md
@@ -0,0 +1,162 @@
+# How to connect to JSON-RPC with curl
+
+Before continuing make sure deluge-web or webui plugin is running.
+
+## Create a curl config
+
+To save a lot of typing and to keep the curl command short we shall create
+a `curl.cfg` files and put the following contents in it:
+
+ request = "POST"
+ compressed
+ cookie = "cookie_deluge.txt"
+ cookie-jar = "cookie_deluge.txt"
+ header = "Content-Type: application/json"
+ header = "Accept: application/json"
+ url = "http://localhost:8112/json"
+ write-out = "\n"
+
+To pretty-print the JSON result see: https://stackoverflow.com/q/352098/175584
+
+## Login to WebUI
+
+Login to the WebUI and get session cookie:
+
+ curl -d '{"method": "auth.login", "params": ["deluge"], "id": 1}' -K curl.cfg
+
+Result is `true` to signify that login was successful:
+
+ {
+ "error": null,
+ "id": 1,
+ "result": true
+ }
+
+Check the contents of the cookie file to verify session ID created.
+
+ cat cookie_deluge.txt
+ # Netscape HTTP Cookie File
+ # http://curl.haxx.se/docs/http-cookies.html
+ # This file was generated by libcurl! Edit at your own risk.
+
+ localhost FALSE /json FALSE 1540061203 _session_id <session_id>
+
+## Check connected to deluged
+
+Use the `web.connected` method to get a boolean response if the webui is
+connected to a deluged host:
+
+ curl -d '{"method": "web.connected", "params": [], "id": 1}' -K curl.cfg
+
+Result is `false` because WebUI is not yet connected to the daemon:
+
+ {
+ "error": null,
+ "id": 1,
+ "result": false
+ }
+
+## Get list of deluged hosts
+
+Use the `web.get_hosts` method:
+
+ curl -d '{"method": "web.get_hosts", "params": [], "id": 1}' -K curl.cfg
+
+The result contains the `<hostID>` for using in request `params` field.
+
+ {
+ "error": null,
+ "id": 1,
+ "result": [
+ [
+ "<hostID>",
+ "127.0.0.1",
+ 58846,
+ "localclient"
+ ]
+ ]
+ }
+
+## Get the deluged host status
+
+ curl -d '{"method": "web.get_host_status", \
+ "params": ["<hostID>"], "id": 1}' -K curl.cfg
+
+The result shows the version and status; _online_, _offline_ or _connected_.
+
+ {
+ "error": null,
+ "id": 1,
+ "result": [
+ "<hostID>",
+ "Online",
+ "2.0.0"
+ ]
+ }
+
+## Connect to deluged host
+
+To connect to deluged with `<hostID>`:
+
+ curl -d '{"method": "web.connect", \
+ "params": ["<hostID>"], "id": 1}' -K curl.cfg
+
+The result contains the full list of avaiable host methods:
+
+ {
+ "error": null,
+ "id": 1,
+ "result": [
+ "core.add_torrent_url",
+ ...
+ "core.upload_plugin"
+ ]
+ }
+
+## Disconnect from host
+
+ curl -d '{"method": "web.disconnect", "params": [], "id": 1}' -K curl.cfg
+
+A successful result:
+
+ {
+ "error": null,
+ "id": 1,
+ "result": "Connection was closed cleanly."
+ }
+
+## Add a torrent
+
+ curl -d '{"method": "web.add_torrents", "params": \
+ [[{"path":"/tmp/ubuntu-12.04.1-desktop-amd64.iso.torrent", \
+ "options":null}]], "id": 1}' -K curl.cfg
+
+## Add a magnet URI
+
+ curl-d '{"method": "core.add_torrent_magnet", \
+ "params": ["<magnet_uri>", {}], "id": 1}' -K curl.cfg
+
+## Get list of files for a torrent
+
+ curl -d '{"method": "web.get_torrent_files", \
+ "params": ["<torrentid>"], "id": 1}' -K curl.cfg
+
+## Set a core config option
+
+ curl -d '{"method": "core.set_config", \
+ "params":[{"max_upload_slots_global":"200"}], "id": 1}' -K curl.cfg
+
+ {"error": null, "result": null, "id": 1}
+
+## Useful curl config options
+
+For full list of options see man page `man curl` or help `curl --help`:
+
+ --cookie (-b) # Load cookie file with session id
+ --cookie-jar (-c) # Save cookie file with session id
+ --compressed # responses are gzipped
+ --include (-i) # Include the HTTP header in output (optional)
+ --header (-H) # HTTP header
+ --request (-X) # custom request method
+ --data (-d) # data to send in POST request '{"method": "", "params": [], "id": ""}'
+ --insecure (-k) # use with self-signed certs https
diff --git a/docs/source/devguide/how-to/index.md b/docs/source/devguide/how-to/index.md
new file mode 100644
index 000000000..da978c16b
--- /dev/null
+++ b/docs/source/devguide/how-to/index.md
@@ -0,0 +1,8 @@
+# How-to guides
+
+This is a collection of guides for specific issues or cover more details than
+the tutorials.
+
+## Web JSON-RPC
+
+- [Connect to JSON-RPC using curl](curl-jsonrpc.md)