Skip to content

Commit 4783725

Browse files
authored
Merge pull request #85 from moondayapp/master
Add interfaces for the Feed and the Client
2 parents f066d86 + b9a179c commit 4783725

14 files changed

Lines changed: 298 additions & 31 deletions

lib/GetStream/Stream/Activities.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class Activities extends Feed
1010
protected $token;
1111

1212
/**
13-
* @param Client $client
13+
* @param ClientInterface $client
1414
* @param string $api_key
1515
* @param string $token
1616
*/
17-
public function __construct($client, $api_key, $token)
17+
public function __construct(ClientInterface $client, $api_key, $token)
1818
{
1919
$this->client = $client;
2020
$this->api_key = $api_key;

lib/GetStream/Stream/ActivityUpdateOperation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class ActivityUpdateOperation extends Feed
1010
protected $token;
1111

1212
/**
13-
* @param Client $client
13+
* @param ClientInterface $client
1414
* @param string $api_key
1515
* @param string $token
1616
*/
17-
public function __construct($client, $api_key, $token)
17+
public function __construct(ClientInterface $client, $api_key, $token)
1818
{
1919
$this->client = $client;
2020
$this->api_key = $api_key;

lib/GetStream/Stream/Analytics.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class Analytics extends Feed
1212
protected $token;
1313

1414
/**
15-
* @param Client $client
15+
* @param ClientInterface $client
1616
* @param string $api_key
1717
* @param string $token
1818
*/
19-
public function __construct($client, $api_key, $token)
19+
public function __construct(ClientInterface $client, $api_key, $token)
2020
{
2121
$this->client = $client;
2222
$this->api_key = $api_key;

lib/GetStream/Stream/BaseFeed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GetStream\Stream;
44

5-
class BaseFeed
5+
class BaseFeed implements BaseFeedInterface
66
{
77
/**
88
* @var string
@@ -35,20 +35,20 @@ class BaseFeed
3535
protected $api_key;
3636

3737
/**
38-
* @var Client
38+
* @var ClientInterface
3939
*/
4040
protected $client;
4141

4242
/**
43-
* @param Client $client
43+
* @param ClientInterface $client
4444
* @param string $feed_slug
4545
* @param string $user_id
4646
* @param string $api_key
4747
* @param string $token
4848
*
4949
* @throws StreamFeedException
5050
*/
51-
public function __construct($client, $feed_slug, $user_id, $api_key, $token)
51+
public function __construct(ClientInterface $client, $feed_slug, $user_id, $api_key, $token)
5252
{
5353
if (!$this->validFeedSlug($feed_slug)) {
5454
throw new StreamFeedException('feed_slug can only contain alphanumeric characters or underscores');
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
namespace GetStream\Stream;
4+
5+
interface BaseFeedInterface
6+
{
7+
/**
8+
* @param string $feed_slug
9+
*
10+
* @return bool
11+
*/
12+
public function validFeedSlug($feed_slug);
13+
14+
/**
15+
* @param string $user_id
16+
*
17+
* @return bool
18+
*/
19+
public function validUserId($user_id);
20+
21+
/**
22+
* @return string
23+
*/
24+
public function getReadonlyToken();
25+
26+
/**
27+
* @return string
28+
*/
29+
public function getToken();
30+
31+
/**
32+
* @return string
33+
*/
34+
public function getId();
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getSlug();
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getUserId();
45+
46+
/**
47+
* @param array $to
48+
*
49+
* @return array
50+
*/
51+
public function signToField($to);
52+
53+
/**
54+
* @param array $activity
55+
* @return mixed
56+
*
57+
* @throws StreamFeedException
58+
*/
59+
public function addActivity($activity);
60+
61+
/**
62+
* @param array $activities
63+
* @return mixed
64+
*
65+
* @throws StreamFeedException
66+
*/
67+
public function addActivities($activities);
68+
69+
/**
70+
* @param int $activity_id
71+
* @param bool $foreign_id
72+
* @return mixed
73+
*
74+
* @throws StreamFeedException
75+
*/
76+
public function removeActivity($activity_id, $foreign_id = false);
77+
78+
/**
79+
* @param int $offset
80+
* @param int $limit
81+
* @param array $options
82+
* @return mixed
83+
*
84+
* @throws StreamFeedException
85+
*/
86+
public function getActivities($offset = 0, $limit = 20, $options = [], $enrich = false, $reactions = null);
87+
88+
/**
89+
* @param string $targetFeedSlug
90+
* @param string $targetUserId
91+
* @param int $activityCopyLimit
92+
*
93+
* @return mixed
94+
*
95+
* @throws StreamFeedException
96+
*/
97+
public function follow($targetFeedSlug, $targetUserId, $activityCopyLimit = 300);
98+
99+
/**
100+
* @param int $offset
101+
* @param int $limit
102+
* @return mixed
103+
*
104+
* @throws StreamFeedException
105+
*/
106+
public function followers($offset = 0, $limit = 25);
107+
108+
/**
109+
* @param int $offset
110+
* @param int $limit
111+
* @param array $filter
112+
* @return mixed
113+
*
114+
* @throws StreamFeedException
115+
*/
116+
public function following($offset = 0, $limit = 25, $filter = []);
117+
118+
/**
119+
* @param string $targetFeedSlug
120+
* @param string $targetUserId
121+
* @param bool $keepHistory
122+
*
123+
* @return mixed
124+
*
125+
* @throws StreamFeedException
126+
*/
127+
public function unfollow($targetFeedSlug, $targetUserId, $keepHistory = false);
128+
129+
/**
130+
* @param string $foreign_id
131+
* @param string $time
132+
* @param array $new_targets
133+
* @param array $added_targets
134+
* @param array $removed_targets
135+
* @return mixed
136+
*
137+
* @throws StreamFeedException
138+
*/
139+
public function updateActivityToTargets($foreign_id, $time, $new_targets = [], $added_targets = [], $removed_targets = []);
140+
}

lib/GetStream/Stream/Batcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class Batcher extends Feed
1212
private $signer;
1313

1414
/**
15-
* @param Client $client
15+
* @param ClientInterface $client
1616
* @param Signer $signer
1717
* @param string $api_key
1818
*/
19-
public function __construct($client, Signer $signer, $api_key)
19+
public function __construct(ClientInterface $client, Signer $signer, $api_key)
2020
{
2121
$this->client = $client;
2222
$this->signer = $signer;

lib/GetStream/Stream/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const VERSION = '2.6.0';
88

9-
class Client
9+
class Client implements ClientInterface
1010
{
1111
const API_ENDPOINT = 'stream-io-api.com/api';
1212

@@ -131,7 +131,7 @@ public function createUserToken($user_id, array $extra_data=null)
131131
}
132132

133133
/**
134-
* @param BaseFeed $feed
134+
* @param BaseFeedInterface $feed
135135
* @param string $resource
136136
* @param string $action
137137
* @return string
@@ -146,7 +146,7 @@ public function createFeedJWTToken($feed, $resource, $action)
146146
* @param string $feed_slug
147147
* @param string $user_id
148148
* @param string|null $token
149-
* @return Feed
149+
* @return FeedInterface
150150
*/
151151
public function feed($feed_slug, $user_id, $token = null)
152152
{
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace GetStream\Stream;
4+
5+
interface ClientInterface
6+
{
7+
/**
8+
* @param string $protocol
9+
*/
10+
public function setProtocol($protocol);
11+
12+
/**
13+
* @param string $location
14+
*/
15+
public function setLocation($location);
16+
17+
/**
18+
* @param string $user_id
19+
* @param array $extra_data
20+
* @return string
21+
*/
22+
public function createUserSessionToken($user_id, array $extra_data = null);
23+
24+
/**
25+
* @param string $user_id
26+
* @param array $extra_data
27+
* @return string
28+
*/
29+
public function createUserToken($user_id, array $extra_data = null);
30+
31+
/**
32+
* @param BaseFeedInterface $feed
33+
* @param string $resource
34+
* @param string $action
35+
* @return string
36+
*/
37+
public function createFeedJWTToken($feed, $resource, $action);
38+
39+
/**
40+
* @param string $feed_slug
41+
* @param string $user_id
42+
* @param string|null $token
43+
* @return FeedInterface
44+
*/
45+
public function feed($feed_slug, $user_id, $token = null);
46+
47+
/**
48+
* @return Batcher
49+
*/
50+
public function batcher();
51+
52+
/**
53+
* @return Personalization
54+
*/
55+
public function personalization();
56+
57+
/**
58+
* @return Collections
59+
*/
60+
public function collections();
61+
62+
/**
63+
* @return Reactions
64+
*/
65+
public function reactions();
66+
67+
/**
68+
* @return Users
69+
*/
70+
public function users();
71+
72+
/**
73+
* @return string
74+
*/
75+
public function getBaseUrl();
76+
77+
/**
78+
* @param string $uri
79+
* @return string
80+
*/
81+
public function buildRequestUrl($uri);
82+
83+
public function getActivities($ids = null, $foreign_id_times = null);
84+
85+
public function batchPartialActivityUpdate($data);
86+
87+
public function doPartialActivityUpdate($id = null, $foreign_id = null, $time = null, $set = null, $unset = null);
88+
89+
public function updateActivities($activities);
90+
91+
public function updateActivity($activity);
92+
93+
/**
94+
* Creates a redirect url for tracking the given events in the context of
95+
* getstream.io/personalization
96+
* @param string $targetUrl
97+
* @param array $events
98+
* @return string
99+
*/
100+
public function createRedirectUrl($targetUrl, $events);
101+
}

lib/GetStream/Stream/Collections.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace GetStream\Stream;
44

55
use Firebase\JWT\JWT;
6-
use GetStream\Stream\Client as StreamClient;
76
use GuzzleHttp\Client as GuzzleClient;
87
use GuzzleHttp\Exception\ClientException;
98
use GuzzleHttp\HandlerStack;
@@ -12,7 +11,7 @@
1211
class Collections
1312
{
1413
/**
15-
* @var Client
14+
* @var ClientInterface
1615
*/
1716
private $client;
1817

@@ -27,11 +26,11 @@ class Collections
2726
private $apiSecret;
2827

2928
/**
30-
* @param \GetStream\Stream\Client $streamClient
29+
* @param ClientInterface $streamClient
3130
* @param string $apiKey
3231
* @param string $apiSecret
3332
*/
34-
public function __construct(StreamClient $streamClient, $apiKey, $apiSecret)
33+
public function __construct(ClientInterface $streamClient, $apiKey, $apiSecret)
3534
{
3635
$this->apiKey = $apiKey;
3736
$this->apiSecret = $apiSecret;

lib/GetStream/Stream/Feed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use GuzzleHttp\HandlerStack;
88
use GuzzleHttp\Psr7\Uri;
99

10-
class Feed extends BaseFeed
10+
class Feed extends BaseFeed implements FeedInterface
1111
{
1212
/**
1313
* @var string

0 commit comments

Comments
 (0)