Skip to content

Commit 71fbed2

Browse files
author
James Dalessio
committed
Add delete methods to sdk.
1 parent 70c44cb commit 71fbed2

File tree

10 files changed

+147
-8
lines changed

10 files changed

+147
-8
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ device = exp.create_device({ 'subtype': 'scala:device:player' })
245245

246246
Returns an iterable of devices matching the given query parameters. `params` is a dictionary of query parameters. Iterable also has attributes matching the raw API response document properties (i.e. `total` and `results`).
247247

248+
**`exp.delete_device(uuid=None)`**
249+
250+
Deletes the device with the given uuid.
251+
248252
**`device.get_location()`**
249253

250254
Returns the device's [location](#locations) or `None`.
@@ -258,6 +262,7 @@ Returns a list of the device's [zones](#zones).
258262
Returns the device's [experience](#experiences) or `None`
259263

260264

265+
261266
## Things
262267

263268
Things inherit all [common resource methods and attributes](#resources).
@@ -278,6 +283,12 @@ thing = exp.create_thing({ 'subtype': 'scala:thing:rfid', 'id': '[rfid]', 'name'
278283

279284
Returns an iterable of things matching the given query parameters. `params` is a dictionary of query parameters. Iterable also has attributes matching the raw API response document properties (i.e. `total` and `results`).
280285

286+
287+
**`exp.delete_thing(uuid=None)`**
288+
289+
Deletes the thing with the given uuid.
290+
291+
281292
**`thing.get_location()`**
282293

283294
Returns the thing's [location](#locations) or `None`.
@@ -291,6 +302,8 @@ Returns a list of the thing's [#zones](#zones).
291302
Returns the device's [experience](#experiences) or `None`
292303

293304

305+
306+
294307
## Experiences
295308

296309
Experiences inherit all [common resource methods and attributes](#resources).
@@ -316,6 +329,7 @@ Returns an iterable of experiences matching the given query parameters. `params`
316329
Returns an iterable of [devices](#devices) that are part of this experience. `params` is a dictionary of query parameters. Iterable also has attributes matching the raw API response document properties (i.e. `total` and `results`).
317330

318331

332+
319333
## Locations
320334
Locations inherit all [common resource methods and attributes](#resources).
321335

@@ -336,6 +350,11 @@ Returns a location created based on the supplied document.
336350
Returns an iterable of locations matching the given query parameters. `params` is a dictionary of query parameters. Iterable also has attributes matching the raw API response document properties (i.e. `total` and `results`).
337351

338352

353+
**`exp.delete_location(uuid=None)`**
354+
355+
Deletes the location with the given uuid.
356+
357+
339358
**`location.get_devices(params=None)`**
340359

341360
Returns an iterable of [devices](#devices) that are part of this location. `params` is a dictionary of query parameters. Iterable also has attributes matching the raw API response document properties (i.e. `total` and `results`).
@@ -353,6 +372,7 @@ Returns a list of [zones](#zones) that are part of this location.
353372
Returns a url pointing to the location's layout image.
354373

355374

375+
356376
## Zones
357377
Zones inherit the [common resource methods and attributes](#resources) `save()`, `refresh()`, and `get_channel()`.
358378

@@ -404,14 +424,21 @@ Returns an iterable of feeds matching the given query parameters. `params` is a
404424
feeds = exp.find_feeds({ 'subtype': 'scala:feed:facebook' })
405425
```
406426

427+
428+
**`exp.delete_feed(uuid=None)`**
429+
430+
Deletes the feed with the given uuid.
431+
432+
407433
**`feed.get_data(**params)`**
408434

409435
Returns the feed's data. For dynamic feeds specify key value query params in `params`.
410436

411437

438+
412439
## Data
413440

414-
Data items inherit the [common resource methods and attributes](#resources) `save()`, `refresh()`, and `get_channel()`.
441+
Data items inherit the [common resource methods and attributes](#resources) `save()`, `refresh()`, `delete()`, and `get_channel()`.
415442
There is a limit of 16MB per data document.
416443

417444
*Note that data values must be a javascript object, but can contain other primitives.*
@@ -442,6 +469,11 @@ Returns an iterable of data items matching the given query parameters. `params`
442469
items = exp.find_data({ 'group': 'cats' })
443470
```
444471

472+
**`exp.delete_data(group=None, key=None)`**
473+
474+
Deletes the data item with the given group and key.
475+
476+
445477
**`data.key`**
446478

447479
The data item's key. Settable.
@@ -455,6 +487,7 @@ The data item's group. Settable
455487
The data item's value. Settable.
456488

457489

490+
458491
## Content
459492
Content items inherit all [common resource methods and attributes](#resources) except `save()`.
460493

@@ -534,6 +567,11 @@ channel = experience.get_channel()
534567
channel.broadcast('hello?')
535568
```
536569

570+
**`resource.delete()`**
571+
572+
Deletes the resource.
573+
574+
537575
## Custom Requests
538576

539577
These methods all users to send custom authenticated API calls. `params` is a dictionary of url params, `payload` is a JSON serializable type, and `timeout` is the duration, in seconds, to wait for the request to complete. `path` is relative to the api host root. All methods will return a JSON serializable type.

exp_sdk/api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def _get_channel_name (self):
6868
def _get_resource_path (self):
6969
return '{0}/{1}'.format(self._collection_path, self.uuid)
7070

71+
@classmethod
72+
def delete_ (cls, uuid, sdk):
73+
if not uuid or not isinstance(uuid, basestring):
74+
return None
75+
path = '{0}/{1}'.format(cls._collection_path, uuid)
76+
return sdk.api.delete(path)
77+
78+
def delete (self):
79+
return self._sdk.api.delete(self._get_resource_path())
80+
7181
@classmethod
7282
def get (cls, uuid, sdk):
7383
if not uuid or not isinstance(uuid, basestring):
@@ -318,7 +328,13 @@ def save (self):
318328
def _get_channel_name (self):
319329
return 'data:{0}:{1}'.format(self.group, self.key)
320330

331+
@classmethod
332+
def delete_ (cls, group, key, sdk):
333+
path = '{0}/{1}/{2}'.format(cls._collection_path, group, key)
334+
sdk.api.delete(path)
321335

336+
def delete (self):
337+
self._sdk.api.delete(self._get_resource_path())
322338

323339

324340
class Content (CommonResource):

exp_sdk/exp.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def find_devices (self, params=None):
143143
def create_device (self, document=None):
144144
return self._sdk.api.Device.create(document, self._sdk)
145145

146+
def delete_device (self, uuid=None):
147+
return self._sdk.api.Device.delete_(uuid, self._sdk)
148+
146149

147150
def get_thing (self, uuid=None):
148151
return self._sdk.api.Thing.get(uuid, self._sdk)
@@ -153,6 +156,9 @@ def find_things (self, params=None):
153156
def create_thing (self, document=None):
154157
return self._sdk.api.Thing.create(document, self._sdk)
155158

159+
def delete_thing (self, uuid=None):
160+
return self._sdk.api.Thing.delete_(uuid, self._sdk)
161+
156162

157163
def get_experience (self, uuid=None):
158164
return self._sdk.api.Experience.get(uuid, self._sdk)
@@ -166,6 +172,9 @@ def find_experiences (self, params=None):
166172
def create_experience (self, document=None):
167173
return self._sdk.api.Experience.create(document, self._sdk)
168174

175+
def delete_experience (self, uuid=None):
176+
return self._sdk.api.Experience.delete_(uuid, self._sdk)
177+
169178

170179
def get_location (self, uuid=None):
171180
return self._sdk.api.Location.get(uuid, self._sdk)
@@ -176,13 +185,15 @@ def get_current_location(self):
176185
def get_current_zones(self):
177186
return self._sdk.api.Zone.get_current(self._sdk)
178187

179-
180188
def find_locations (self, params=None):
181189
return self._sdk.api.Location.find(params, self._sdk)
182190

183191
def create_location (self, document=None):
184192
return self._sdk.api.Location.create(document, self._sdk)
185193

194+
def delete_location (self, uuid=None):
195+
return self._sdk.api.Location.delete_(uuid, self._sdk)
196+
186197

187198
def get_feed (self, uuid=None):
188199
return self._sdk.api.Feed.get(uuid, self._sdk)
@@ -193,6 +204,9 @@ def find_feeds (self, params=None):
193204
def create_feed (self, document=None):
194205
return self._sdk.api.Feed.create(document, self._sdk)
195206

207+
def delete_feed (self, uuid=None):
208+
return self._sdk.api.Feed.delete_(uuid, self._sdk);
209+
196210

197211
def get_data (self, group='default', key=None):
198212
return self._sdk.api.Data.get(group, key, self._sdk)
@@ -203,6 +217,9 @@ def find_data (self, params=None):
203217
def create_data (self, group=None, key=None, value=None):
204218
return self._sdk.api.Data.create(group, key, value, self._sdk)
205219

220+
def delete_data(self, group=None, key=None):
221+
return self._sdk.api.Data.delete_(group, key, self._sdk)
222+
206223

207224
def get_content (self, uuid=None):
208225
return self._sdk.api.Content.get(uuid, self._sdk)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
setup(
44
name='exp-sdk',
55
packages= ['exp_sdk'],
6-
version='1.0.6',
6+
version='1.0.7',
77
description='EXP Python SDK',
88
author='Scala',
99
author_email='[email protected]',
1010
url='https://github.com/scalainc/exp-python2-sdk',
11-
download_url='https://github.com/scalainc/exp-python2-sdk/tarball/1.0.6',
11+
download_url='https://github.com/scalainc/exp-python2-sdk/tarball/1.0.7',
1212
install_requires=["requests", "socketIO_client"],
1313
license='MIT',
1414
keywords=['scala', 'exp', 'sdk', 'signage'],

tests/test_data.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,17 @@ def test_update (self):
3636
data = self.exp.get_data(data.group, data.key)
3737
if data.value['test2'] != 'a':
3838
raise Exception
39+
40+
def test_delete (self):
41+
data = self.create_valid()
42+
key = data.key
43+
group = data.group
44+
data.delete()
45+
if self.exp.get_data(group, key):
46+
raise Exception
47+
data = self.create_valid()
48+
key = data.key
49+
group = data.group
50+
self.exp.delete_data(group, key)
51+
if self.exp.get_data(group, key):
52+
raise Exception

tests/test_devices.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,15 @@ def test_get_current (self):
4747
exp = self.exp_sdk.start(**self.user_credentials)
4848
if exp.get_current_device():
4949
raise Exception()
50-
51-
50+
51+
def test_delete (self):
52+
device = self.create_valid()
53+
uuid = device.uuid
54+
device.delete()
55+
if self.exp.get_device(uuid):
56+
raise Exception
57+
device = self.create_valid()
58+
uuid = device.uuid
59+
self.exp.delete_device(uuid)
60+
if self.exp.get_device(uuid):
61+
raise Exception

tests/test_experiences.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ def test_get_current (self):
3939
exp = self.exp_sdk.start(**self.user_credentials)
4040
if exp.get_current_experience():
4141
raise Exception()
42-
42+
43+
def test_delete (self):
44+
experience = self.create_valid()
45+
uuid = experience.uuid
46+
experience.delete()
47+
if self.exp.get_experience(uuid):
48+
raise Exception
49+
experience = self.create_valid()
50+
uuid = experience.uuid
51+
self.exp.delete_experience(uuid)
52+
if self.exp.get_experience(uuid):
53+
raise Exception

tests/test_feeds.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ def test_dynamic (self):
2424
data = feed.get_data(searchValue='19713')
2525
if data['search']['search'] != '19713':
2626
raise Exception
27+
28+
def test_delete (self):
29+
feed = self.create_valid()
30+
feed.delete()
31+
if self.exp.get_feed(uuid):
32+
raise Exception
33+
feed = self.create_valid()
34+
uuid = feed.uuid
35+
self.exp.delete_feed(uuid)
36+
if self.exp.get_feed(uuid):
37+
raise Exception

tests/test_locations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ def test_get_current (self):
5454
exp = self.exp_sdk.start(**self.user_credentials)
5555
if exp.get_current_location():
5656
raise Exception()
57+
58+
def test_delete (self):
59+
location = self.create_valid()
60+
uuid = location.uuid
61+
location.delete()
62+
if self.exp.get_location(uuid):
63+
raise Exception
64+
location = self.create_valid()
65+
uuid = location.uuid
66+
self.exp.delete_location(uuid)
67+
if self.exp.get_location(uuid):
68+
raise Exception

tests/test_things.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import unittest
32

43
from . import utils
@@ -32,3 +31,14 @@ def test_get_zones (self):
3231
if zones[0].key != 'key_2':
3332
raise Exception
3433

34+
def test_delete (self):
35+
thing = self.create_valid()
36+
uuid = thing.uuid
37+
thing.delete()
38+
if self.exp.get_thing(uuid):
39+
raise Exception
40+
thing = self.create_valid()
41+
uuid = thing.uuid
42+
self.exp.delete_thing(uuid)
43+
if self.exp.get_thing(uuid):
44+
raise Exception

0 commit comments

Comments
 (0)