Skip to content

Commit 10886ef

Browse files
authored
Merge pull request #76 from GetStream/task/release-3.0
Task/release 3.0
2 parents 75b806a + fefe851 commit 10886ef

6 files changed

Lines changed: 191 additions & 144 deletions

File tree

CHANGELOG

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
Change history
33
================
44

5+
3.0.0
6+
=====
7+
:release-date: 2019-02-11
8+
:by: Peter van Kampen
9+
10+
* Add support for users, collections, reactions, enrichment
11+
* Add `Client::doPartiallyUpdateActivity`
12+
* Add `Client::batchPartialActivityUpdate` methods
13+
* Add `Client::getActivities` methods
14+
* Remove deprecated methods on Feed Class
15+
516
2.9.1
617
=====
718
:release-date: 2018-12-03

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014-2017 Stream.io Inc, and individual contributors.
1+
Copyright (c) 2014-2019 Stream.io Inc, and individual contributors.
22

33
All rights reserved.
44

lib/GetStream/Stream/BaseFeed.php

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ public function removeActivity($activity_id, $foreign_id = false)
203203
*
204204
* @throws StreamFeedException
205205
*/
206-
public function getActivities($offset = 0, $limit = 20, $options = [], $enrich=false)
206+
public function getActivities($offset = 0, $limit = 20, $options = [], $enrich=false, $reactions = null)
207207
{
208+
if($options === null){
209+
$options = [];
210+
}
208211
$query_params = ['offset' => $offset, 'limit' => $limit];
209212
if (array_key_exists('mark_read', $options) && is_array($options['mark_read'])) {
210213
$options['mark_read'] = implode(',', $options['mark_read']);
@@ -214,6 +217,24 @@ public function getActivities($offset = 0, $limit = 20, $options = [], $enrich=f
214217
}
215218
$query_params = array_merge($query_params, $options);
216219

220+
if($reactions !== null){
221+
if(!is_array($reactions)){
222+
throw new StreamFeedException("reactions argument should be an associative array");
223+
}
224+
if(isset($reactions["own"]) && $reactions["own"]){
225+
$query_params["withOwnReactions"] = true;
226+
$enrich = true;
227+
}
228+
if(isset($reactions["recent"]) && $reactions["recent"]){
229+
$query_params["withRecentReactions"] = true;
230+
$enrich = true;
231+
}
232+
if(isset($reactions["counts"]) && $reactions["counts"]){
233+
$query_params["withReactionCounts"] = true;
234+
$enrich = true;
235+
}
236+
}
237+
217238
$prefix_enrich = $enrich ? 'enrich/' : '';
218239

219240
return $this->makeHttpRequest("{$prefix_enrich}{$this->base_feed_url}/", 'GET', null, $query_params, 'feed', 'read');
@@ -242,22 +263,6 @@ public function follow($targetFeedSlug, $targetUserId, $activityCopyLimit = 300)
242263
return $this->makeHttpRequest("{$this->base_feed_url}/follows/", 'POST', $data, null, 'follower', 'write');
243264
}
244265

245-
/**
246-
* @deprecated Will be removed in version 3.0.0
247-
*
248-
* @param string $targetFeedSlug
249-
* @param string $targetUserId
250-
* @param int $activityCopyLimit
251-
*
252-
* @return mixed
253-
*
254-
* @throws StreamFeedException
255-
*/
256-
public function followFeed($targetFeedSlug, $targetUserId, $activityCopyLimit = 300)
257-
{
258-
return $this->follow($targetFeedSlug, $targetUserId, $activityCopyLimit);
259-
}
260-
261266
/**
262267
* @param int $offset
263268
* @param int $limit
@@ -312,36 +317,6 @@ public function unfollow($targetFeedSlug, $targetUserId, $keepHistory = false)
312317
return $this->makeHttpRequest("{$this->base_feed_url}/follows/{$targetFeedId}/", 'DELETE', null, $queryParams, 'follower', 'delete');
313318
}
314319

315-
/**
316-
* @deprecated Will be removed in version 3.0.0
317-
*
318-
* @param string $targetFeedSlug
319-
* @param string $targetUserId
320-
* @param bool $keepHistory
321-
*
322-
* @return mixed
323-
*
324-
* @throws StreamFeedException
325-
*/
326-
public function unfollowFeed($targetFeedSlug, $targetUserId, $keepHistory = false)
327-
{
328-
return $this->unfollow($targetFeedSlug, $targetUserId, $keepHistory);
329-
}
330-
331-
/**
332-
* @deprecated Will be removed in version 3.0.0
333-
*
334-
* No need to clean up, one should just use different feed ids.
335-
*
336-
* @return mixed
337-
*
338-
* @throws StreamFeedException
339-
*/
340-
public function delete()
341-
{
342-
return $this->makeHttpRequest("{$this->base_feed_url}/", 'DELETE', null, null, 'feed', 'delete');
343-
}
344-
345320
/**
346321
* @param string $foreign_id
347322
* @param string $time
@@ -362,13 +337,13 @@ public function updateActivityToTargets($foreign_id, $time, $new_targets = [], $
362337
if ($new_targets) {
363338
$data['new_targets'] = $new_targets;
364339
}
365-
340+
366341
if ($added_targets) {
367-
$data['added_targets'] = $added_targets;
342+
$data['added_targets'] = $added_targets;
368343
}
369-
344+
370345
if ($removed_targets) {
371-
$data['removed_targets'] = $removed_targets;
346+
$data['removed_targets'] = $removed_targets;
372347
}
373348
return $this->makeHttpRequest("feed_targets/{$this->slug}/{$this->user_id}/activity_to_targets/", 'POST', $data, null, 'feed_targets', 'write');
374349
}

lib/GetStream/Stream/Collections.php

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ private function doRequest($method, $endpoint, $params=null)
5050
if( $method === 'POST' || $method === 'PUT' ){
5151
$params = ['json' => $params];
5252
}
53+
if( $method === 'GET' && $params !== null ){
54+
55+
$endpoint .= '?' . http_build_query($params);
56+
}
5357
try {
5458
$response = $this->client->request($method, $endpoint, $params);
5559
} catch (ClientException $e) {
@@ -62,6 +66,22 @@ private function doRequest($method, $endpoint, $params=null)
6266
return $response;
6367
}
6468

69+
/**
70+
* @param string $collectionName
71+
* @param array $data
72+
* @param string $id (optional)
73+
* @param string $user_id (optional)
74+
*
75+
* @return array
76+
*/
77+
public function add($collectionName, array $data, $id=null, $user_id=null)
78+
{
79+
$payload = ["id" => $id, "data" => $data, "user_id" => $user_id];
80+
$response = $this->doRequest('POST', 'collections/' . $collectionName . '/', $payload);
81+
$body = $response->getBody()->getContents();
82+
return json_decode($body, true);
83+
}
84+
6585
/**
6686
* @param string $collectionName
6787
* @param string $id
@@ -73,6 +93,48 @@ public function createReference($collectionName, $id)
7393
return "SO:".$collectionName.":".$id;
7494
}
7595

96+
/**
97+
* @param string $collectionName
98+
* @param string $id
99+
*
100+
* @return array
101+
*/
102+
public function delete($collectionName, $id)
103+
{
104+
105+
$response = $this->doRequest('DELETE', 'collections/' . $collectionName . '/' . $id . '/');
106+
$body = $response->getBody()->getContents();
107+
return json_decode($body, true);
108+
}
109+
110+
/**
111+
* @param string $collectionName
112+
* @param array $ids
113+
*
114+
* @return array
115+
*/
116+
public function deleteMany($collectionName, array $ids)
117+
{
118+
$ids = join(',', $ids);
119+
$queryParams = ['collection_name' => $collectionName, 'ids' => $ids];
120+
$response = $this->client->request('DELETE', 'collections/?'.http_build_query($queryParams));
121+
$body = $response->getBody()->getContents();
122+
return json_decode($body, true);
123+
}
124+
125+
/**
126+
* @param string $collectionName
127+
* @param string $id
128+
*
129+
* @return array
130+
*/
131+
public function get($collectionName, $id)
132+
{
133+
$response = $this->doRequest('GET', 'collections/' . $collectionName . '/' . $id . '/');
134+
$body = $response->getBody()->getContents();
135+
return json_decode($body, true);
136+
}
137+
76138
/**
77139
* @param string $collectionName
78140
* @param array $ids
@@ -92,40 +154,29 @@ public function select($collectionName, array $ids)
92154

93155
/**
94156
* @param string $collectionName
157+
* @param string $id
95158
* @param array $data
96159
*
97160
* @return array
98161
*/
99-
public function upsert($collectionName, array $data)
162+
public function update($collectionName, $id, array $data)
100163
{
101-
$response = $this->doRequest('POST', 'meta/', ['data' => [$collectionName => array($data)]]);
164+
$payload = ["data" => $data];
165+
$response = $this->doRequest('PUT', 'collections/' . $collectionName . '/' . $id . '/', $payload);
102166
$body = $response->getBody()->getContents();
103167
return json_decode($body, true);
104168
}
105169

106170
/**
107171
* @param string $collectionName
108-
* @param array $ids
172+
* @param array $data
109173
*
110174
* @return array
111175
*/
112-
public function delete($collectionName, array $ids)
176+
public function upsert($collectionName, array $data)
113177
{
114-
$ids = join(',', $ids);
115-
$queryParams = ['collection_name' => $collectionName, 'ids' => $ids];
116-
117-
try {
118-
$response = $this->client->request('DELETE', 'meta/?'.http_build_query($queryParams));
119-
} catch (ClientException $e) {
120-
$response = $e->getResponse();
121-
$msg = $response->getBody();
122-
$code = $response->getStatusCode();
123-
$previous = $e;
124-
throw new StreamFeedException($msg, $code, $previous);
125-
}
126-
178+
$response = $this->doRequest('POST', 'meta/', ['data' => [$collectionName => array($data)]]);
127179
$body = $response->getBody()->getContents();
128-
129180
return json_decode($body, true);
130181
}
131182

lib/GetStream/Stream/Reactions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ private function doRequest($method, $endpoint, $params=null)
5050
if( $method === 'POST' || $method === 'PUT' ){
5151
$params = ['json' => $params];
5252
}
53+
if( $method === 'GET' && $params !== null ){
54+
55+
$endpoint .= '?' . http_build_query($params);
56+
}
5357
try {
5458
$response = $this->client->request($method, $endpoint, $params);
5559
} catch (ClientException $e) {

0 commit comments

Comments
 (0)