Skip to content

Commit

Permalink
Merge 'return_one' into dev - Potentially code breaking changes
Browse files Browse the repository at this point in the history
- Return single items without wrapping in list
- Fix calls that return a single item.
- Resolves issue macadmins#26
  • Loading branch information
bryanheinz committed Nov 5, 2021
2 parents 6539f94 + cd39657 commit f3c929c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions SimpleMDMpy/SimpleMDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ def _url(self, path): #pylint: disable=no-self-use
"""base api url"""
return 'https://a.simplemdm.com/api/v1' + path

def _get_data(self, url, params=None):
def _get_data(self, base_url, params=None):
"""GET call to SimpleMDM API"""
start_id = 0
has_more = True
resp_data = []
base_url = url
list_data = []
while has_more:
url = base_url + "?limit=100&starting_after=" + str(start_id)
resp = requests.get(url, params, auth=(self.api_key, ""), proxies=self.proxyDict)
if not 200 <= resp.status_code <= 207:
raise ApiError(f"API returned status code {resp.status_code}")
resp_json = resp.json()
data = resp_json['data']
resp_data.extend(data)
has_more = resp_json.get('has_more', None)
# If the response isn't a list, return the single item.
if not isinstance(data, list):
return data
# If it's a list we save it and see if there is more data coming.
list_data.extend(data)
has_more = resp_json.get('has_more', False)
if has_more:
start_id = data[-1].get('id')
return resp_data
return list_data

def _patch_data(self, url, data, files=None):
"""PATCH call to SimpleMDM API"""
Expand Down

0 comments on commit f3c929c

Please sign in to comment.