Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Adafruit_IO/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.4.0"
__version__ = "2.5.0"
8 changes: 6 additions & 2 deletions Adafruit_IO/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,15 @@ def feeds(self, feed=None):
path = "feeds/{0}".format(feed)
return Feed.from_dict(self._get(path))

def create_feed(self, feed):
def create_feed(self, feed, group_key=None):
"""Create the specified feed.
:param string feed: Name/Key/ID of Adafruit IO feed.
:param string feed: Key of Adafruit IO feed.
:param group_key group: Group to place new feed in.
"""
path = "feeds/"
if group_key is not None: # create feed in a group
path="/groups/%s/feeds"%group_key
return Feed.from_dict(self._post(path, {"feed": feed._asdict()}))
return Feed.from_dict(self._post(path, {"feed": feed._asdict()}))

def delete_feed(self, feed):
Expand Down
24 changes: 16 additions & 8 deletions examples/api/feeds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Simple example of sending and receiving values from Adafruit IO with the REST
# API client.
# Author: Tony Dicola, Justin Cooper
# Author: Tony Dicola, Justin Cooper, Brent Rubell

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

# List all of your feeds
print("Obtaining user's feeds...")
feeds = aio.feeds()
print(feeds)
print('Feeds: ', feeds)

# Create a new feed
print("Creating new feed...")
feed = Feed(name="PythonFeed")
response = aio.create_feed(feed)
print(response)

# List a specific feed
feed = aio.feeds(response.key)
print(feed)

print("New feed: ", response)

# Delete a feed
aio.delete_feed(response.key)

# Create feed in a group
feed = Feed(name="PythonGroupFeed")
group_key = "example"
print("Creating feed in group %s"%group_key)
response = aio.create_feed(feed, group_key)
print("New feed: ", response)

# Delete a feed within a group
print("Deleting feed within group %s"%group_key)
aio.delete_feed(response.key)
16 changes: 16 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ def test_create_feed(self):
result = io.create_feed(feed)
self.assertEqual(result.name, 'testfeed')

def test_create_feed_in_group(self):
"""Tests creating a feed within a group.

"""
io = self.get_client()
self.ensure_feed_deleted(io, 'testfeed')
self.ensure_group_deleted(io, 'testgroup')

group = io.create_group(Group(name='testgroup'))
feed = Feed(name='testfeed')
result = io.create_feed(feed, "testgroup")
self.assertEqual(result.key, "testgroup.testfeed")

io.delete_feed(result.key)
io.delete_group('testgroup')

def test_feeds_returns_all_feeds(self):
io = self.get_client()
self.ensure_feed_deleted(io, 'testfeed')
Expand Down