File tree Expand file tree Collapse file tree 4 files changed +39
-11
lines changed Expand file tree Collapse file tree 4 files changed +39
-11
lines changed Original file line number Diff line number Diff line change 1- __version__ = "2.4 .0"
1+ __version__ = "2.5 .0"
Original file line number Diff line number Diff 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 ):
Original file line number Diff line number Diff line change 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.
66from Adafruit_IO import Client , Feed
1919aio = Client (ADAFRUIT_IO_USERNAME , ADAFRUIT_IO_KEY )
2020
2121# List all of your feeds
22+ print ("Obtaining user's feeds..." )
2223feeds = aio .feeds ()
23- print (feeds )
24+ print ('Feeds: ' , feeds )
2425
2526# Create a new feed
27+ print ("Creating new feed..." )
2628feed = Feed (name = "PythonFeed" )
2729response = 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
3633aio .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 )
Original file line number Diff line number Diff 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' )
You can’t perform that action at this time.
0 commit comments