Created
February 13, 2020 19:42
-
-
Save Porter97/2fefd30f34ed490e927e1d3bc119df72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_to_stream(self): | |
# Initialize client and add activity to user feed | |
try: | |
client = stream.connect(current_app.config['STREAM_API_KEY'], current_app.config['STREAM_SECRET']) | |
client.feed("Collections", str(self.collection_id)).add_activity({'actor': client.users.create_reference(str(self.collection.author_id)), | |
'verb': 'post', | |
'object': 'Content:' + str(self.id), | |
'post': self.title, | |
'url': self.url, | |
'description': self.description, | |
'time': self.timestamp, | |
'collection': {'id': self.collection_id, | |
'name': self.collection.name}, | |
'foreign_id': 'Content:' + str(self.id) | |
}) | |
return True | |
except: | |
# If the Stream Client throws an exception or there is a network issue | |
return False | |
def update_stream(self): | |
# Initialize client and update activity | |
try: | |
client = stream.connect(current_app.config['STREAM_API_KEY'], current_app.config['STREAM_SECRET']) | |
client.update_activity({'actor': client.users.create_reference(str(self.collection.author_id)), | |
'verb': 'post', | |
'object': 'Content:' + str(self.id), | |
'post': self.title, | |
'url': self.url, | |
'description': self.description, | |
'time': self.timestamp, | |
'collection': {'id': self.collection_id, | |
'name': self.collection.name}, | |
'foreign_id': 'Content:' + str(self.id) | |
}) | |
return True | |
except: | |
return False | |
def delete_from_stream(self): | |
# Initialize client and delete activity | |
try: | |
client = stream.connect(current_app.config['STREAM_API_KEY'], current_app.config['STREAM_SECRET']) | |
user_feed = client.feed('Collections', str(self.collection_id)) | |
user_feed.remove_activity(foreign_id="Content:" + str(self.id)) | |
return True | |
except: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment