Skip to content

Instantly share code, notes, and snippets.

@Porter97
Created February 13, 2020 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Porter97/c5fad93025e6990ccf0e3800d0329c7c to your computer and use it in GitHub Desktop.
Save Porter97/c5fad93025e6990ccf0e3800d0329c7c to your computer and use it in GitHub Desktop.
#...
class Collection(db.Model):
#...
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("User", str(self.author_id)).add_activity({'actor': client.users.create_reference(str(self.author_id)),
'verb': 'create',
'object': 'Collection:' + str(self.id),
'create': self.name,
'foreign_id': 'Collection:' + str(self.id),
'description': self.description,
'time': self.timestamp
})
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.author_id)),
'verb': 'create',
'object': 'Collection:' + str(self.id),
'create': self.name,
'foreign_id': 'Collection:' + str(self.id),
'description': self.description,
'time': self.timestamp
})
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('User', str(self.author_id))
user_feed.remove_activity(foreign_id="Collection:" + 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