def get_latest(self): """Retrieve the last messages sent for this thing""" if self.monitor_on is True: if self.pretty_print_on is True: print( json.dumps(ts_dweepy.get_latest_dweet_for(self.thing_name), indent=4, sort_keys=True)) else: print(ts_dweepy.get_latest_dweet_for(self.thing_name))
def test_get_latest_dweet_for_without_a_key(self): """`get_latest_dweet_for` without a key should raise an exception. """ try: ts_dweepy.get_latest_dweet_for(self.my_thing_id) except ts_dweepy.DweepyError as e: self.assertEqual(e.args[0], 'this thing is locked and requires a key') else: self.fail("shouldn't ever get called")
def test_get_latest_dweet_for_with_an_invalid_key(self): """`get_latest_dweet_for` with an invalid key should raise an exception. """ try: ts_dweepy.get_latest_dweet_for(self.my_thing_id, key='badkey') except ts_dweepy.DweepyError as e: self.assertEqual( e.args[0], 'the key you provided doesn\'t work with this thing') else: self.fail("shouldn't ever get called")
def listen(self): """Listen for a new message for this thing""" if self.monitor_on is True: while True: mess = ts_dweepy.get_latest_dweet_for(self.thing_name) if mess[0]["created"] != self.last_mess: self.last_mess = mess[0]["created"] if self.pretty_print_on is True: print( json.dumps(ts_dweepy.get_latest_dweet_for( self.thing_name), indent=4, sort_keys=True)) else: print(ts_dweepy.get_latest_dweet_for(self.thing_name)) time.sleep(self.polling_time)
def test_get_latest_dweet_for(self): """`get_latest_dweet_for` should return a valid response. """ ts_dweepy.dweet_for(self.my_thing_id, test_data) dweets = ts_dweepy.get_latest_dweet_for(self.my_thing_id) check_valid_get_response(self, dweets)
def test_get_latest_dweet_for_with_a_valid_key(self): """`get_latest_dweet_for` with a valid key should return a valid response. """ ts_dweepy.dweet_for(self.my_thing_id, test_data, key=test_key) dweets = ts_dweepy.get_latest_dweet_for(self.my_thing_id, key=test_key) check_valid_get_response(self, dweets)