From 4a0f4f804616c169e7a186d83583754430e935d6 Mon Sep 17 00:00:00 2001 From: drebs Date: Fri, 6 Oct 2017 08:28:17 -0300 Subject: [doc] improve client usage example --- docs/client.rst | 34 ++++++++++++++++++++++------------ 1 file 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 `_ 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() -- cgit v1.2.3