Skip to content

Commit 1605121

Browse files
author
Zach Moody
authored
Merge pull request #368 from digitalocean/update-docs
update docs
2 parents 297bc5b + 905fb5f commit 1605121

File tree

3 files changed

+68
-16
lines changed

3 files changed

+68
-16
lines changed

docs/response.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ Response
22
========
33

44
.. autoclass:: pynetbox.core.response.Record
5-
:members:
5+
:members:
6+
7+
.. autoclass:: pynetbox.core.response.RecordSet
8+
:members:

pynetbox/core/endpoint.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,17 @@ def all(self, limit=0):
7979
:arg int,optional limit: Overrides the max page size on
8080
paginated returns.
8181
82-
:Returns: List of :py:class:`.Record` objects.
82+
:Returns: A :py:class:`.RecordSet` object.
8383
8484
:Examples:
8585
86-
>>> nb.dcim.devices.all()
87-
[test1-a3-oobsw2, test1-a3-oobsw3, test1-a3-oobsw4]
86+
>>> devices = nb.dcim.devices.all()
87+
>>> for device in devices:
88+
... print(device.name)
89+
...
90+
test1-leaf1
91+
test1-leaf2
92+
test1-leaf3
8893
>>>
8994
"""
9095
req = Request(
@@ -176,33 +181,50 @@ def filter(self, *args, **kwargs):
176181
:arg int,optional limit: Overrides the max page size on
177182
paginated returns.
178183
179-
:Returns: A list of :py:class:`.Record` objects.
184+
:Returns: A :py:class:`.RecordSet` object.
180185
181186
:Examples:
182187
183188
To return a list of objects matching a named argument filter.
184189
185-
>>> nb.dcim.devices.filter(role='leaf-switch')
186-
[test1-a3-tor1b, test1-a3-tor1c, test1-a3-tor1d, test1-a3-tor2a]
190+
>>> devices = nb.dcim.devices.filter(role='leaf-switch')
191+
>>> for device in devices:
192+
... print(device.name)
193+
...
194+
test1-leaf1
195+
test1-leaf2
196+
test1-leaf3
187197
>>>
188198
189199
Using a freeform query along with a named argument.
190200
191-
>>> nb.dcim.devices.filter('a3', role='leaf-switch')
192-
[test1-a3-tor1b, test1-a3-tor1c, test1-a3-tor1d, test1-a3-tor2a]
201+
>>> devices = nb.dcim.devices.filter('a3', role='leaf-switch')
202+
>>> for device in devices:
203+
... print(device.name)
204+
...
205+
test1-a3-leaf1
206+
test1-a3-leaf2
193207
>>>
194208
195209
Chaining multiple named arguments.
196210
197-
>>> nb.dcim.devices.filter(role='leaf-switch', status=True)
198-
[test1-leaf2]
211+
>>> devices = nb.dcim.devices.filter(role='leaf-switch', status=True)
212+
>>> for device in devices:
213+
... print(device.name)
214+
...
215+
test1-leaf2
199216
>>>
200217
201218
Passing a list as a named argument adds multiple filters of the
202219
same value.
203220
204-
>>> nb.dcim.devices.filter(role=['leaf-switch', 'spine-switch'])
205-
[test1-a3-spine1, test1-a3-spine2, test1-a3-leaf1]
221+
>>> device = nb.dcim.devices.filter(role=['leaf-switch', 'spine-switch'])
222+
>>> for device in devices:
223+
... print(device.name)
224+
...
225+
test1-a3-spine1
226+
test1-a3-spine2
227+
test1-a3-leaf1
206228
>>>
207229
"""
208230

@@ -251,10 +273,9 @@ def create(self, *args, **kwargs):
251273
252274
:Examples:
253275
254-
Creating an object on the `devices` endpoint you can lookup a
255-
device_role's name with:
276+
Creating an object on the `devices` endpoint:
256277
257-
>>> netbox.dcim.devices.create(
278+
>>> device = netbox.dcim.devices.create(
258279
... name='test',
259280
... device_role=1,
260281
... )

pynetbox/core/response.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,34 @@ class JsonField(object):
7171

7272

7373
class RecordSet(object):
74+
"""Iterator containing Record objects.
75+
76+
Returned by :py:meth:`.Endpoint.all()` and :py:meth:`.Endpoint.filter()` methods.
77+
Allows iteration of and actions to be taken on the results from the aforementioned
78+
methods. Contains :py:class:`.Record` objects.
79+
80+
:Examples:
81+
82+
To see how many results are in a query by calling ``len()``.
83+
84+
>>> x = nb.dcim.devices.all()
85+
>>> len(x)
86+
123
87+
>>>
88+
89+
Simple iteration of the results.
90+
91+
>>> devices = nb.dcim.devices.all()
92+
>>> for device in devices:
93+
... print(device.name)
94+
...
95+
test1-leaf1
96+
test1-leaf2
97+
test1-leaf3
98+
>>>
99+
100+
"""
101+
74102
def __init__(self, endpoint, request, **kwargs):
75103
self.endpoint = endpoint
76104
self.request = request

0 commit comments

Comments
 (0)