Skip to content

Commit

Permalink
Merge pull request #42 from bryanheinz/unstable
Browse files Browse the repository at this point in the history
- Closes issue #24
- Closes issue #38
- Closes issue #25
- Closes issue #26
  • Loading branch information
bryanheinz committed Jan 17, 2022
2 parents 55cf523 + c9ef08b commit e255030
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
31 changes: 19 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# CHANGELOG

## v3.0.7
## [Unreleased]

### Changes

- Add method to download profiles
- Added ability to update the actual device name via SimpleMDM (#24, #38)
- Replaced get_logs() `id_override` input parameter with `starting_after` and `limit` (#25)
- Fixes calls that return a single item (#26)
- Add method to download profiles (#40)

### Issues

- Closes #40
- Closes issue #24
- Closes issue #38
- Closes issue #25
- Closes issue #26
- Closes issue #40

## v3.0.6
## [v3.0.6]

### PRs Included

Expand All @@ -22,7 +29,7 @@

- Add method to get all custom attributes for a device

## v3.0.5
## [v3.0.5]

### Issues

Expand All @@ -32,7 +39,7 @@

- CODEOWNERS

## v3.0.4
## [v3.0.4]

### Issues

Expand All @@ -49,7 +56,7 @@
- Merged with @MagerValp / simpleMDMpy @ [508540928](https://github.com/MagerValp/simpleMDMpy/commit/50854094bee2ac5306eded7c5614d76f3eab4c25)
- minor tweaks on the readme

## v3.0.3
## [v3.0.3]

### Issues

Expand All @@ -67,7 +74,7 @@
- default branch is now `main`
- remove `data` payload from Devices.delete_device

## v3.0.2
## [v3.0.2]

### Issues

Expand All @@ -83,7 +90,7 @@

- Changed paginaition to work without compounding to a `414`

## v3.0.1
## [v3.0.1]

### Issues

Expand All @@ -94,7 +101,7 @@
- Changed paginaition to work, now returns obj not response
- good catch @bryanheinz

## v3.0.0
## [v3.0.0]

- Closes #3

Expand All @@ -103,7 +110,7 @@
- removed forced encoding for `GET` responses
- added some pylint comments

## v2.1.0
## [v2.1.0]

### Issues

Expand All @@ -113,7 +120,7 @@

- fixed module names

## v2.0.0
## [v2.0.0]

### Issues

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class Devices(SimpleMDMpy.SimpleMDM.Connection)
| shutdown_device(self, device_id)
| This command sends a shutdown command to the device.
|
| update_device(self, name, device_id)
| update_device(self, device_id, name=None, device_name=None)
| Update the SimpleMDM name or device name of a device object.
|
| update_os(self, device_id)
Expand Down Expand Up @@ -376,7 +376,7 @@ class Logs(SimpleMDMpy.SimpleMDM.Connection)
|
| __init__(self, api_key)
|
| get_logs(self)
| get_logs(self, starting_after=None, limit=None)
| And I mean all the LOGS, before pagination
|

Expand Down
12 changes: 9 additions & 3 deletions SimpleMDMpy/Devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ def create_device(self, name, group_id):
data = {'name': name, 'group_id': group_id}
return self._post_data(self.url, data)

def update_device(self, name, device_id):
"""Update the SimpleMDM name or device name of a device object."""
def update_device(self, device_id, name=None, device_name=None):
"""Update the SimpleMDM name and/or device name of a device object."""
url = self.url + "/" + str(device_id)
data = {'name': name}
data = {}
if name is not None:
data.update({'name':name})
if device_name is not None:
data.update({'device_name':device_name})
if data == {}:
raise Exception(f"Missing name and/or device_name variables.")
return self._patch_data(url, data)

def delete_device(self, device_id):
Expand Down
25 changes: 20 additions & 5 deletions SimpleMDMpy/Logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@ class Logs(SimpleMDMpy.SimpleMDM.Connection):
def __init__(self, api_key):
SimpleMDMpy.SimpleMDM.Connection.__init__(self, api_key)
self.url = self._url("/logs")

def get_logs(self, id_override=0):
"""And I mean all the LOGS"""

def get_logs(self, starting_after=None, limit=None):
"""Returns logs, and I mean all the LOGS
Args:
starting_after (str, optional): set to the id of the log object you
want to start with. Defaults to the first object.
limit (str, optional): A limit on the number of objects that will be
returned per API call. Setting this will still return all logs.
Defaults to 100.
Returns:
array: An array of dictionary log objects.
"""
url = self.url
data = {}
return self._get_data(url, data, id_override=id_override)
params = {}
if starting_after:
params['starting_after'] = starting_after
if limit:
params['limit'] = limit
return self._get_data(url, params=params)
16 changes: 9 additions & 7 deletions SimpleMDMpy/SimpleMDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from builtins import str
from builtins import range
from builtins import object
import json
import requests

class ApiError(Exception):
Expand All @@ -24,24 +23,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 _get_xml(self, url, params=None):
"""GET call to SimpleMDM API"""
Expand Down

0 comments on commit e255030

Please sign in to comment.