diff --git a/Adafruit_IO/_version.py b/Adafruit_IO/_version.py index 3d67cd6..50062f8 100644 --- a/Adafruit_IO/_version.py +++ b/Adafruit_IO/_version.py @@ -1 +1 @@ -__version__ = "2.4.0" +__version__ = "2.5.0" diff --git a/Adafruit_IO/client.py b/Adafruit_IO/client.py index 515789a..7ffe7d3 100644 --- a/Adafruit_IO/client.py +++ b/Adafruit_IO/client.py @@ -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): diff --git a/examples/api/feeds.py b/examples/api/feeds.py index 4a9885b..848bdda 100644 --- a/examples/api/feeds.py +++ b/examples/api/feeds.py @@ -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 @@ -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) \ No newline at end of file diff --git a/tests/test_client.py b/tests/test_client.py index 5f4737c..c037411 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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')