Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
Signed-off-by: flashdagger <flashdagger@googlemail.com>
  • Loading branch information
flashdagger committed Dec 11, 2023
1 parent 39b2c59 commit 5481e31
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ an object-oriented Zammad REST API Client for Python
.. toctree::
:maxdepth: 2

intro.rst
intro
tutorial/index
contributing
api/index
history
Expand Down
8 changes: 8 additions & 0 deletions docs/tutorial/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
========
Tutorial
========

.. toctree::
:maxdepth: 1

resources
28 changes: 28 additions & 0 deletions docs/tutorial/resources.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Objects can be lazy
===================

| Consider the following example:
| We enable logging and create a ticket object
by its id. Then we print the ticket id, number and title.
.. code-block:: python
import logging
logging.basicConfig(level=logging.INFO)
ticket = client.tickets(1)
print(f"ticket id: {ticket.id}")
print(f"ticket number: #{ticket.number}")
print(f"ticket title: {ticket.title!r}")
# ticket id: 1
# INFO:zammadoo:HTTP:GET https://localhost/api/v1/tickets/1
# ticket number: #67001
# ticket title: 'Welcome to Zammad!'
What happened? Before printing the ticket number the client made a server request
to fetch the ticket data. This means if we instantiate an object it only contains
its id. The first time we get an attribute or perform a method which requires attributes
the data is queried from the server. This is called lazy object initialization and applies
to most resources.

0 comments on commit 5481e31

Please sign in to comment.