Skip to content

Commit 6dc27ed

Browse files
author
Maria Korlotian
authored
Add device docs (#91)
1 parent 650def3 commit 6dc27ed

15 files changed

Lines changed: 75 additions & 31 deletions

README.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,50 @@ Events
154154

155155
List of Recognized Events can be found `here <https://github.com/castle/castle-python/tree/master/castle/events.py>`_ or in the `docs <https://docs.castle.io/api_reference/#list-of-recognized-events>`_.
156156

157+
Device management
158+
-----------------
159+
160+
This SDK allows issuing requests to `Castle's Device Management
161+
Endpoints <https://docs.castle.io/device_management_tool/>`__. Use these
162+
endpoints for admin-level management of end-user devices (i.e., for an
163+
internal dashboard).
164+
165+
Fetching device data, approving a device, reporting a device requires a
166+
valid ``device_token``.
167+
168+
.. code:: python
169+
170+
from castle.api.get_device import APIGetDevice
171+
172+
# Get device data
173+
APIGetDevice.call(device_token)
174+
175+
.. code:: python
176+
177+
from castle.api.approve_device import APIApproveDevice
178+
179+
# Approve a device
180+
APIApproveDevice.call(device_token)
181+
182+
.. code:: python
183+
184+
from castle.api.report_device import APIReportDevice
185+
186+
# Report a device
187+
APIReportDevice.call(device_token)
188+
189+
190+
Fetching available devices that belong to a given user requires a valid
191+
``user_id``.
192+
193+
.. code:: python
194+
195+
from castle.api.get_devices_for_user import APIGetDevicesForUser
196+
197+
# Get user's devices data
198+
APIGetDevicesForUser.call(user_id)
199+
200+
157201
Impersonation mode
158202
------------------
159203

castle/api/approve_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class APIApproveDevice(object):
66
@staticmethod
7-
def retrieve(device_token):
7+
def call(device_token):
88
return APIRequest().call(CommandsApproveDevice.build(device_token))

castle/api/get_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class APIGetDevice(object):
66
@staticmethod
7-
def retrieve(device_token):
7+
def call(device_token):
88
return APIRequest().call(CommandsGetDevice.build(device_token))

castle/api/get_devices.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

castle/api/get_devices_for_user.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from castle.api_request import APIRequest
2+
from castle.commands.get_devices_for_user import CommandsGetDevicesForUser
3+
4+
5+
class APIGetDevicesForUser(object):
6+
@staticmethod
7+
def call(user_id):
8+
return APIRequest().call(CommandsGetDevicesForUser.build(user_id))

castle/api/report_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class APIReportDevice(object):
66
@staticmethod
7-
def retrieve(device_token):
7+
def call(device_token):
88
return APIRequest().call(CommandsReportDevice.build(device_token))

castle/api/review.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class APIReview(object):
66
@staticmethod
7-
def retrieve(review_id):
7+
def call(review_id):
88
return APIRequest().call(CommandsReview.build(review_id))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from castle.validators.present import ValidatorsPresent
33

44

5-
class CommandsGetDevices(object):
5+
class CommandsGetDevicesForUser(object):
66

77
@staticmethod
88
def build(user_id):

castle/test/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
TEST_MODULES = [
88
'castle.test.api.approve_device_test',
99
'castle.test.api.get_device_test',
10-
'castle.test.api.get_devices_test',
10+
'castle.test.api.get_devices_for_user_test',
1111
'castle.test.api.report_device_test',
1212
'castle.test.api.review_test',
1313
'castle.test.api_request_test',
@@ -17,7 +17,7 @@
1717
'castle.test.commands.approve_device_test',
1818
'castle.test.commands.authenticate_test',
1919
'castle.test.commands.get_device_test',
20-
'castle.test.commands.get_devices_test',
20+
'castle.test.commands.get_devices_for_user_test',
2121
'castle.test.commands.identify_test',
2222
'castle.test.commands.impersonate_test',
2323
'castle.test.commands.report_device_test',

castle/test/api/approve_device_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def tearDown(self):
1414
configuration.api_secret = None
1515

1616
@responses.activate
17-
def test_retrieve(self):
17+
def test_call(self):
1818
# pylint: disable=line-too-long
1919
response_text = "{\"token\":\"token\",\"created_at\":\"2020-08-13T11:26:47.401Z\",\"last_seen_at\":\"2020-10-18T18:37:22.855Z\",\"user_id\":\"4\",\"approved_at\":\"2020-11-18T12:48:41.112Z\",\"escalated_at\":null,\"mitigated_at\":null,\"context\":{\"ip\":\"127.0.0.1\",\"location\":{\"country_code\":\"PL\",\"country\":\"Poland\"},\"user_agent\":{\"raw\":\"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.75 Safari\/537.36\",\"browser\":\"Chrome\",\"version\":\"86.0.4240\",\"os\":\"Mac OS X 10.15.6\",\"mobile\":false,\"platform\":\"Mac OS X\",\"device\":\"Mac\",\"family\":\"Chrome\"},\"properties\":{},\"type\":\"desktop\"},\"is_current_device\":false}"
2020
responses.add(
@@ -24,4 +24,4 @@ def test_retrieve(self):
2424
status=200
2525
)
2626
device_token = '1234'
27-
self.assertEqual(APIApproveDevice.retrieve(device_token), json.loads(response_text))
27+
self.assertEqual(APIApproveDevice.call(device_token), json.loads(response_text))

0 commit comments

Comments
 (0)