Skip to content

Commit 0b512be

Browse files
committed
initial Device model implementation
1 parent a2b768e commit 0b512be

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/cbapi/defense/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from ..models import MutableBaseModel, CreatableModelMixin, NewBaseModel
2+
3+
4+
class Device(NewBaseModel):
5+
urlobject = "/integrationServices/v3/device"
6+
primary_key = "deviceId"
7+
8+
def __init__(self, cb, model_unique_id, initial_data=None):
9+
super(Device, self).__init__(cb, model_unique_id, initial_data)
10+
11+
def _parse(self, obj):
12+
if type(obj) == dict and "deviceInfo" in obj:
13+
return obj["deviceInfo"]
14+

src/cbapi/defense/rest_api.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def and_(self, q):
8787
return self.where(q)
8888

8989
def _count(self):
90+
# TODO: FIX
9091
args = {'limit': -1}
9192
if self._query:
9293
args['q'] = self._query
@@ -99,8 +100,9 @@ def _count(self):
99100
def _search(self, start=0, rows=0):
100101
# iterate over total result set, 1000 at a time
101102
args = {}
102-
args['fromRow'] = start
103-
args['maxRows'] = self._batch_size
103+
if start != 0:
104+
args['start'] = start
105+
args['rows'] = self._batch_size
104106

105107
current = start
106108
numrows = 0
@@ -114,18 +116,18 @@ def _search(self, start=0, rows=0):
114116
query_args = convert_query_params(args)
115117
result = self._cb.get_object(self._doc_class.urlobject, query_parameters=query_args)
116118

117-
if len(result) == 0:
118-
break
119+
self._total_results = result.get("totalResults", 0)
120+
self._count_valid = True
119121

120-
for item in result:
122+
for item in result.get("results", []):
121123
yield item
122124
current += 1
123125
numrows += 1
124126
if rows and numrows == rows:
125127
still_querying = False
126128
break
127129

128-
args['offset'] = current + 1
130+
args['start'] = current + 1
129131

130132
if len(result) < self._batch_size:
131133
break

0 commit comments

Comments
 (0)