Skip to content

Commit 617c5a4

Browse files
authored
Merge pull request #125 from brentru/specify-feed-in-group
Add ability to create feed within a group
2 parents 9cc19e4 + 2c73315 commit 617c5a4

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

Diff for: Adafruit_IO/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.4.0"
1+
__version__ = "2.5.0"

Diff for: Adafruit_IO/client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,15 @@ def feeds(self, feed=None):
273273
path = "feeds/{0}".format(feed)
274274
return Feed.from_dict(self._get(path))
275275

276-
def create_feed(self, feed):
276+
def create_feed(self, feed, group_key=None):
277277
"""Create the specified feed.
278-
:param string feed: Name/Key/ID of Adafruit IO feed.
278+
:param string feed: Key of Adafruit IO feed.
279+
:param group_key group: Group to place new feed in.
279280
"""
280281
path = "feeds/"
282+
if group_key is not None: # create feed in a group
283+
path="/groups/%s/feeds"%group_key
284+
return Feed.from_dict(self._post(path, {"feed": feed._asdict()}))
281285
return Feed.from_dict(self._post(path, {"feed": feed._asdict()}))
282286

283287
def delete_feed(self, feed):

Diff for: examples/api/feeds.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Simple example of sending and receiving values from Adafruit IO with the REST
22
# API client.
3-
# Author: Tony Dicola, Justin Cooper
3+
# Author: Tony Dicola, Justin Cooper, Brent Rubell
44

55
# Import Adafruit IO REST client.
66
from Adafruit_IO import Client, Feed
@@ -19,18 +19,26 @@
1919
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
2020

2121
# List all of your feeds
22+
print("Obtaining user's feeds...")
2223
feeds = aio.feeds()
23-
print(feeds)
24+
print('Feeds: ', feeds)
2425

2526
# Create a new feed
27+
print("Creating new feed...")
2628
feed = Feed(name="PythonFeed")
2729
response = aio.create_feed(feed)
28-
print(response)
29-
30-
# List a specific feed
31-
feed = aio.feeds(response.key)
32-
print(feed)
33-
30+
print("New feed: ", response)
3431

3532
# Delete a feed
3633
aio.delete_feed(response.key)
34+
35+
# Create feed in a group
36+
feed = Feed(name="PythonGroupFeed")
37+
group_key = "example"
38+
print("Creating feed in group %s"%group_key)
39+
response = aio.create_feed(feed, group_key)
40+
print("New feed: ", response)
41+
42+
# Delete a feed within a group
43+
print("Deleting feed within group %s"%group_key)
44+
aio.delete_feed(response.key)

Diff for: tests/test_client.py

+16
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ def test_create_feed(self):
188188
result = io.create_feed(feed)
189189
self.assertEqual(result.name, 'testfeed')
190190

191+
def test_create_feed_in_group(self):
192+
"""Tests creating a feed within a group.
193+
194+
"""
195+
io = self.get_client()
196+
self.ensure_feed_deleted(io, 'testfeed')
197+
self.ensure_group_deleted(io, 'testgroup')
198+
199+
group = io.create_group(Group(name='testgroup'))
200+
feed = Feed(name='testfeed')
201+
result = io.create_feed(feed, "testgroup")
202+
self.assertEqual(result.key, "testgroup.testfeed")
203+
204+
io.delete_feed(result.key)
205+
io.delete_group('testgroup')
206+
191207
def test_feeds_returns_all_feeds(self):
192208
io = self.get_client()
193209
self.ensure_feed_deleted(io, 'testfeed')

0 commit comments

Comments
 (0)