diff options
author | drebs <drebs@riseup.net> | 2017-10-06 08:28:17 -0300 |
---|---|---|
committer | drebs <drebs@riseup.net> | 2017-10-06 08:28:17 -0300 |
commit | 4a0f4f804616c169e7a186d83583754430e935d6 (patch) | |
tree | b79fed365ca777152ca083dff93e67b46c7ce842 | |
parent | 203812621587a71c98f97730e67991b3653f6198 (diff) |
[doc] improve client usage example
-rw-r--r-- | docs/client.rst | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/docs/client.rst b/docs/client.rst index 0129e6fc..0baba7e8 100644 --- a/docs/client.rst +++ b/docs/client.rst @@ -41,6 +41,7 @@ Once all pieces are in place, you can instantiate the client as following: .. code-block:: python from leap.soledad.client import Soledad + client = Soledad( uuid, passphrase, @@ -59,18 +60,27 @@ you will need to make sure a `reactor <http://twistedmatrix.com/documents/current/core/howto/reactor-basics.html>`_ is running. -Creation of a document and synchronization is done as follows: +An example of usage of Soledad Client for creating a document and Creation of +a document and synchronization is done as follows: .. code-block:: python - yield client.create_doc({'my': 'doc'}, doc_id='some-id') - doc = yield client.get_doc('some-id') - yield client.sync() - -The document can be modified and synchronized again: - -.. code-block:: python - - doc.content = {'new': 'content'} - yield client.put_doc(doc) - yield client.sync() + from twisted.internet import defer, reactor + + @defer.inlineCallbacks + def client_usage_example(): + + # create a document and sync it with the server + yield client.create_doc({'my': 'doc'}, doc_id='some-id') + doc = yield client.get_doc('some-id') + yield client.sync() + + # modify the document and sync again + doc.content = {'new': 'content'} + yield client.put_doc(doc) + yield client.sync() + + d = client_usage_example() + d.addCallback(lambda _: reactor.stop()) + + reactor.run() |