Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe4e51b

Browse files
authored
Merge pull request GetStream#61 from GetStream/change-to-targets
Change to targets
2 parents ae4838a + 4e38b1c commit fe4e51b

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

CHANGELOG

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Change history
33
================
44

5+
2.4.0
6+
======
7+
:release-date: 2017-08-31
8+
:by: Tommaso Barbugli
9+
10+
* Added support for To target update endpoint
11+
512
2.3.11
613
======
714
:release-date: 2017-05-22

stream/exceptions.py

+71
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,77 @@ class SiteSuspendedException(StreamApiException):
7070
status_code = 401
7171
code = 7
7272

73+
class InvalidPaginationException(StreamApiException):
74+
75+
'''
76+
Raised when there is an issue with your Access Key
77+
'''
78+
status_code = 401
79+
code = 8
80+
81+
82+
class MissingRankingException(FeedConfigException):
83+
'''
84+
Raised when you didn't configure the ranking for the given feed
85+
'''
86+
status_code = 400
87+
code = 12
88+
89+
90+
class MissingUserException(MissingRankingException):
91+
status_code = 400
92+
code = 10
93+
94+
95+
class RankingException(FeedConfigException):
96+
'''
97+
Raised when there is a runtime issue with ranking the feed
98+
'''
99+
status_code = 400
100+
code = 11
101+
102+
103+
class RateLimitReached(StreamApiException):
104+
105+
'''
106+
Raised when too many requests are performed
107+
'''
108+
status_code = 429
109+
code = 9
110+
111+
112+
class OldStorageBackend(StreamApiException):
113+
'''
114+
Raised if you try to perform an action which only works with the new storage
115+
'''
116+
status_code = 400
117+
code = 13
118+
119+
120+
class BestPracticeException(StreamApiException):
121+
'''
122+
Raised if best practices are enforced and you do something that
123+
would break a high volume integration
124+
'''
125+
status_code = 400
126+
code = 15
127+
128+
129+
class DoesNotExistException(StreamApiException):
130+
'''
131+
Raised when the requested resource could not be found.
132+
'''
133+
status_code = 404
134+
code = 16
135+
136+
137+
class NotAllowedException(StreamApiException):
138+
'''
139+
Raised when the requested action is not allowed for some reason.
140+
'''
141+
status_code = 403
142+
code = 17
143+
73144

74145
def get_exceptions():
75146
from stream import exceptions

stream/feed.py

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, client, feed_slug, user_id, token):
1919
self.token = token
2020

2121
self.feed_url = 'feed/%s/' % self.id.replace(':', '/')
22+
self.feed_targets_url = 'feed_targets/%s/' % self.id.replace(':', '/')
2223
self.feed_together = self.id.replace(':', '')
2324
self.signature = self.feed_together + ' ' + self.token
2425

@@ -211,3 +212,23 @@ def add_to_signature(self, recipients):
211212
feed = self.client.feed(feed_slug, user_id)
212213
data.append("%s %s" % (recipient, feed.token))
213214
return data
215+
216+
def update_activity_to_targets(self, foreign_id, time,
217+
new_targets=None, added_targets=None,
218+
removed_targets=None):
219+
data = {
220+
'foreign_id': foreign_id,
221+
'time': time,
222+
}
223+
224+
if new_targets is not None:
225+
data['new_targets'] = new_targets
226+
if added_targets is not None:
227+
data['added_targets'] = added_targets
228+
if removed_targets is not None:
229+
data['removed_targets'] = removed_targets
230+
231+
url = self.feed_targets_url + 'activity_to_targets/'
232+
233+
token = self.create_scope_token('feed_targets', 'write')
234+
return self.client.post(url, data=data, signature=token)

stream/tests.py

+25
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,31 @@ def test_do_i_follow(self):
565565
self.assertEqual(followings['results'][0]['feed_id'], social.id)
566566
self.assertEqual(followings['results'][0]['target_id'], 'user:apy')
567567

568+
def test_update_activity_to_targets(self):
569+
time = datetime.datetime.utcnow().isoformat()
570+
foreign_id = 'user:1'
571+
activity_data = {
572+
'actor': 1,
573+
'verb': 'tweet',
574+
'object': 1,
575+
'foreign_id': foreign_id,
576+
'time': time,
577+
}
578+
activity_data['to'] = ['user:1', 'user:2']
579+
self.user1.add_activity(activity_data)
580+
581+
ret = self.user1.update_activity_to_targets(foreign_id, time, new_targets=['user:3', 'user:2'])
582+
self.assertEqual(len(ret['activity']['to']), 2)
583+
self.assertTrue('user:2' in ret['activity']['to'])
584+
self.assertTrue('user:3' in ret['activity']['to'])
585+
586+
ret = self.user1.update_activity_to_targets(foreign_id, time, added_targets=['user:4', 'user:5'], removed_targets=['user:3'])
587+
self.assertEqual(len(ret['activity']['to']), 3)
588+
self.assertTrue('user:2' in ret['activity']['to'])
589+
self.assertTrue('user:4' in ret['activity']['to'])
590+
self.assertTrue('user:5' in ret['activity']['to'])
591+
592+
568593
def test_get(self):
569594
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
570595
activity_id = self.user1.add_activity(activity_data)['id']

0 commit comments

Comments
 (0)