Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit 36048f5

Browse files
committed
more docs
1 parent 2c8923a commit 36048f5

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

atomx/models.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222

2323
class AtomxModel(object):
24-
"""Atomx model for {model}. test
25-
:param session: session
26-
:param attributes: attributes
27-
:return: model.{model}
24+
"""A generic atomx model that the other models from :mod:`atomx.models` inherit from.
25+
26+
:param atomx.Atomx session: The :class:`atomx.Atomx` session to use for the api requests.
27+
:param attributes: model attributes
2828
"""
2929
def __init__(self, session=None, **attributes):
3030
"""Atomx model for {model}. test
@@ -77,9 +77,17 @@ def _dirty_json(self):
7777

7878
@property
7979
def json(self):
80+
"""Returns the model attributes as :class:`dict`."""
8081
return self._attributes
8182

8283
def create(self, session=None):
84+
"""`POST` the model to the api and populates attributes with api response.
85+
86+
:param session: The :class:`atomx.Atomx` session to use for the api call.
87+
(Optional if you specified a `session` at initialization)
88+
:return: ``self``
89+
:rtype: :class:`.AtomxModel`
90+
"""
8391
session = session or self.session
8492
if not session:
8593
raise NoSessionError
@@ -88,9 +96,17 @@ def create(self, session=None):
8896
return self
8997

9098
def update(self, session=None):
99+
"""Alias for :meth:`.AtomxModel.save`."""
91100
return self.save(session)
92101

93102
def save(self, session=None):
103+
"""`PUT` the model to the api and update attributes with api response.
104+
105+
:param session: The :class:`atomx.Atomx` session to use for the api call.
106+
(Optional if you specified a `session` at initialization)
107+
:return: ``self``
108+
:rtype: :class:`.AtomxModel`
109+
"""
94110
session = session or self.session
95111
if not session:
96112
raise NoSessionError
@@ -106,6 +122,16 @@ def delete(self, session=None):
106122
"Set `state` to `INACTIVE` to deactivate it.")
107123

108124
def reload(self, session=None):
125+
"""Reload the model from the api and update attributes with the response.
126+
127+
This is useful if you have not all attributes loaded like when you made
128+
an api request with the `attributes` parameter or you used :meth:`atomx.Atomx.search`.
129+
130+
:param session: The :class:`atomx.Atomx` session to use for the api call.
131+
(Optional if you specified a `session` at initialization)
132+
:return: ``self``
133+
:rtype: :class:`.AtomxModel`
134+
"""
109135
session = session or self.session
110136
if not session:
111137
raise NoSessionError
@@ -123,6 +149,8 @@ def reload(self, session=None):
123149

124150

125151
class Report(object):
152+
"""Represents a `report` you get back from :meth:`atomx.Atomx.report`."""
153+
126154
def __init__(self, session, query, fast, id, lines, error, link,
127155
started, finished, is_ready, duration, **kwargs):
128156
self.session = session
@@ -141,6 +169,7 @@ def __init__(self, session, query, fast, id, lines, error, link,
141169

142170
@property
143171
def is_ready(self):
172+
"""Returns ``True`` if the :class:`.Report` is ready, ``False`` otherwise."""
144173
if hasattr(self, '_is_ready'):
145174
return self._is_ready
146175
report_status = self.session.report_status(self)
@@ -154,11 +183,13 @@ def is_ready(self):
154183
return False
155184

156185
def reload(self, session=None):
186+
"""Reload the `report` status. (alias for :meth:`Report.status`)."""
157187
self.session = session or self.session
158188
return self.status
159189

160190
@property
161191
def status(self):
192+
"""Reload the :class:`Report` status"""
162193
if not self.session:
163194
raise NoSessionError
164195
if not hasattr(self, 'id'):
@@ -170,12 +201,14 @@ def status(self):
170201

171202
@property
172203
def content(self):
204+
"""Returns the content (csv) of the `report`."""
173205
if not self.is_ready:
174206
raise ReportNotReadyError()
175207
return self.session.report_get(self)
176208

177209
@property
178210
def pandas(self):
211+
"""Returns the content of the `report` as a pandas data frame."""
179212
try:
180213
import pandas as pd
181214
except ImportError:

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Models
1919
.. automodule:: atomx.models
2020
:members:
2121

22+
.. autoclass:: atomx.models.Report
23+
:members:
24+
2225

2326
Exceptions
2427
----------

0 commit comments

Comments
 (0)