diff --git a/docs/source/guides/module.rst b/docs/source/guides/module.rst index e681202aa558c2bd47e43544fc337373ceb8d75b..5f9bd2f636bcf58cfbf180e18734af806a5934dc 100644 --- a/docs/source/guides/module.rst +++ b/docs/source/guides/module.rst @@ -111,6 +111,9 @@ Module class Edit ``module.py``. It contains the main class of the module derived from :class:`Module ` class:: + from weboob.tools.backend import Module + from weboob.capabilities.bank import CapBank + class ExampleModule(Module, CapBank): NAME = 'example' # The name of module DESCRIPTION = u'Example bank website' # Description of your module @@ -153,8 +156,9 @@ Available parameters of :class:`Value ` are: For example:: + from weboob.tools.backend import Module, BackendConfig + from weboob.capabilities.bank import CapBank from weboob.tools.value import Value, ValueBool, ValueInt, ValueBackendPassword - from weboob.tools.backend import BackendConfig # ... class ExampleModule(Module, CapBank): @@ -173,6 +177,9 @@ Implement capabilities You need to implement each method of all of the capabilities your module implements. For example, in our case:: + from weboob.tools.backend import Module + from weboob.capabilities.bank import CapBank + # ... class ExampleModule(Module, CapBank): # ... @@ -274,7 +281,9 @@ Each time you will go on the home page, ``IndexPage`` will be instanced and set For example, we can now implement some methods in ``ExampleBrowser``:: - class ExampleBrowser(PagesBrowserr): + from weboob.browser import PagesBrowser + + class ExampleBrowser(PagesBrowser): # ... def go_home(self): self.home.go() @@ -297,6 +306,9 @@ Use it in backend Now you have a functional browser, you can use it in your class ``ExampleModule`` by defining it with the ``BROWSER`` attribute:: + from weboob.tools.backend import Module + from weboob.capabilities.bank import CapBank + from .browser import ExampleBrowser # ... @@ -319,6 +331,9 @@ Login management When the website requires to be authenticated, you have to give credentials to the constructor of the browser. You can redefine the method :func:`create_default_browser `:: + from weboob.tools.backend import Module + from weboob.capabilities.bank import CapBank + class ExampleModule(Module, CapBank): # ... def create_default_browser(self): @@ -327,6 +342,9 @@ the method :func:`create_default_browser ` and to implement the function :func:`do_login `:: + from weboob.browser import LoginBrowser + from weboob.exceptions import BrowserIncorrectPassword + class ExampleBrowser(LoginBrowser): login = URL('/login', LoginPage) # ... @@ -343,6 +361,8 @@ You may provide a custom :func:`do_logout `:: + from weboob.browser import LoginBrowser, URL + from weboob.browser import need_login + class ExampleBrowser(LoginBrowser): accounts = URL('/accounts$', ListPage) @@ -368,6 +391,7 @@ decorated method. You can either define it yourself, as a class boolean attribute or as a property, or inherit your class from :class:`LoggedPage `. In the latter case, remember that Python inheritance requires the :class:`LoggedPage ` to be placed first such as in:: + from weboob.browser.pages import LoggedPage, HTMLPage class OnlyForLoggedUserPage(LoggedPage, HTMLPage): # ... @@ -393,9 +417,11 @@ construct the object. For example:: + from weboob.browser.pages import LoggedPage, HTMLPage from weboob.browser.filters.html import Attr from weboob.browser.filters.standard import CleanDecimal, CleanText from weboob.capabilities.bank import Account + from weboob.browser.elements import method, ListElement, ItemElement class ListPage(LoggedPage, HTMLPage): @method @@ -529,6 +555,9 @@ method associated to the type of the object. To define what objects are supported to be filled, and what method to call, define the ``OBJECTS`` class attribute in your ``ExampleModule``:: + from weboob.tools.backend import Module + from weboob.capabilities.video import CapVideo + class ExampleModule(Module, CapVideo): # ... @@ -540,6 +569,9 @@ The prototype of the function might be:: Then, the function might, for each requested fields, fetch the right data and fill the object. For example:: + from weboob.tools.backend import Module + from weboob.capabilities.video import CapVideo + class ExampleModule(Module, CapVideo): # ...