Skip to content

Commit

Permalink
Examples in documentation (close #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhadam committed Dec 28, 2020
1 parent 845b9c7 commit 755cf39
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Examples
--------

Create a client
===============
.. code-block:: python
client = Client()
List all fields of current torrents
===================================

.. code-block:: python
response: Response[TorrentAccessorResponse] = client.torrent.accessor(all_fields=True)
torrents: Sequence[TorrentAccessorObject] = response.arguments.torrents
print(torrents[0].dict(exclude_none=True))
Get specific fields of torrents
===============================

.. code-block:: python
fields: Set[TorrentAccessorField] = {"id", "status", "name"}
response: Response[TorrentAccessorResponse] = client.torrent.accessor(fields)
torrents: Sequence[TorrentAccessorObject] = response.arguments.torrents
torrent = torrents[0]
torrent_id, torrent_status, torrent_name = torrent.id, torrent.status, torrent.name
Remove torrents
===============

.. code-block:: python
response: Response[TorrentAccessorResponse] = client.torrent.remove(
torrent_id, delete_local_data=False
)
Add torrents
===============

.. code-block:: python
arguments: TorrentAddArguments = {
"filename": "/path/to/file",
"paused": True,
}
response: Response[TorrentAdd] = client.torrent.add(arguments)
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Version |release|.
:caption: Contents:

intro
examples
server_config
commands
modules
Expand Down

0 comments on commit 755cf39

Please sign in to comment.