Skip to content

Commit

Permalink
Merge pull request #85 from moondayapp/master
Browse files Browse the repository at this point in the history
Add interfaces for the Feed and the Client
  • Loading branch information
tbarbugli committed Oct 13, 2019
2 parents f066d86 + b9a179c commit 4783725
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/GetStream/Stream/Activities.php
Expand Up @@ -10,11 +10,11 @@ class Activities extends Feed
protected $token;

/**
* @param Client $client
* @param ClientInterface $client
* @param string $api_key
* @param string $token
*/
public function __construct($client, $api_key, $token)
public function __construct(ClientInterface $client, $api_key, $token)
{
$this->client = $client;
$this->api_key = $api_key;
Expand Down
4 changes: 2 additions & 2 deletions lib/GetStream/Stream/ActivityUpdateOperation.php
Expand Up @@ -10,11 +10,11 @@ class ActivityUpdateOperation extends Feed
protected $token;

/**
* @param Client $client
* @param ClientInterface $client
* @param string $api_key
* @param string $token
*/
public function __construct($client, $api_key, $token)
public function __construct(ClientInterface $client, $api_key, $token)
{
$this->client = $client;
$this->api_key = $api_key;
Expand Down
4 changes: 2 additions & 2 deletions lib/GetStream/Stream/Analytics.php
Expand Up @@ -12,11 +12,11 @@ class Analytics extends Feed
protected $token;

/**
* @param Client $client
* @param ClientInterface $client
* @param string $api_key
* @param string $token
*/
public function __construct($client, $api_key, $token)
public function __construct(ClientInterface $client, $api_key, $token)
{
$this->client = $client;
$this->api_key = $api_key;
Expand Down
8 changes: 4 additions & 4 deletions lib/GetStream/Stream/BaseFeed.php
Expand Up @@ -2,7 +2,7 @@

namespace GetStream\Stream;

class BaseFeed
class BaseFeed implements BaseFeedInterface
{
/**
* @var string
Expand Down Expand Up @@ -35,20 +35,20 @@ class BaseFeed
protected $api_key;

/**
* @var Client
* @var ClientInterface
*/
protected $client;

/**
* @param Client $client
* @param ClientInterface $client
* @param string $feed_slug
* @param string $user_id
* @param string $api_key
* @param string $token
*
* @throws StreamFeedException
*/
public function __construct($client, $feed_slug, $user_id, $api_key, $token)
public function __construct(ClientInterface $client, $feed_slug, $user_id, $api_key, $token)
{
if (!$this->validFeedSlug($feed_slug)) {
throw new StreamFeedException('feed_slug can only contain alphanumeric characters or underscores');
Expand Down
140 changes: 140 additions & 0 deletions lib/GetStream/Stream/BaseFeedInterface.php
@@ -0,0 +1,140 @@
<?php

namespace GetStream\Stream;

interface BaseFeedInterface
{
/**
* @param string $feed_slug
*
* @return bool
*/
public function validFeedSlug($feed_slug);

/**
* @param string $user_id
*
* @return bool
*/
public function validUserId($user_id);

/**
* @return string
*/
public function getReadonlyToken();

/**
* @return string
*/
public function getToken();

/**
* @return string
*/
public function getId();

/**
* @return string
*/
public function getSlug();

/**
* @return string
*/
public function getUserId();

/**
* @param array $to
*
* @return array
*/
public function signToField($to);

/**
* @param array $activity
* @return mixed
*
* @throws StreamFeedException
*/
public function addActivity($activity);

/**
* @param array $activities
* @return mixed
*
* @throws StreamFeedException
*/
public function addActivities($activities);

/**
* @param int $activity_id
* @param bool $foreign_id
* @return mixed
*
* @throws StreamFeedException
*/
public function removeActivity($activity_id, $foreign_id = false);

/**
* @param int $offset
* @param int $limit
* @param array $options
* @return mixed
*
* @throws StreamFeedException
*/
public function getActivities($offset = 0, $limit = 20, $options = [], $enrich = false, $reactions = null);

/**
* @param string $targetFeedSlug
* @param string $targetUserId
* @param int $activityCopyLimit
*
* @return mixed
*
* @throws StreamFeedException
*/
public function follow($targetFeedSlug, $targetUserId, $activityCopyLimit = 300);

/**
* @param int $offset
* @param int $limit
* @return mixed
*
* @throws StreamFeedException
*/
public function followers($offset = 0, $limit = 25);

/**
* @param int $offset
* @param int $limit
* @param array $filter
* @return mixed
*
* @throws StreamFeedException
*/
public function following($offset = 0, $limit = 25, $filter = []);

/**
* @param string $targetFeedSlug
* @param string $targetUserId
* @param bool $keepHistory
*
* @return mixed
*
* @throws StreamFeedException
*/
public function unfollow($targetFeedSlug, $targetUserId, $keepHistory = false);

/**
* @param string $foreign_id
* @param string $time
* @param array $new_targets
* @param array $added_targets
* @param array $removed_targets
* @return mixed
*
* @throws StreamFeedException
*/
public function updateActivityToTargets($foreign_id, $time, $new_targets = [], $added_targets = [], $removed_targets = []);
}
4 changes: 2 additions & 2 deletions lib/GetStream/Stream/Batcher.php
Expand Up @@ -12,11 +12,11 @@ class Batcher extends Feed
private $signer;

/**
* @param Client $client
* @param ClientInterface $client
* @param Signer $signer
* @param string $api_key
*/
public function __construct($client, Signer $signer, $api_key)
public function __construct(ClientInterface $client, Signer $signer, $api_key)
{
$this->client = $client;
$this->signer = $signer;
Expand Down
6 changes: 3 additions & 3 deletions lib/GetStream/Stream/Client.php
Expand Up @@ -6,7 +6,7 @@

const VERSION = '2.6.0';

class Client
class Client implements ClientInterface
{
const API_ENDPOINT = 'stream-io-api.com/api';

Expand Down Expand Up @@ -131,7 +131,7 @@ public function createUserToken($user_id, array $extra_data=null)
}

/**
* @param BaseFeed $feed
* @param BaseFeedInterface $feed
* @param string $resource
* @param string $action
* @return string
Expand All @@ -146,7 +146,7 @@ public function createFeedJWTToken($feed, $resource, $action)
* @param string $feed_slug
* @param string $user_id
* @param string|null $token
* @return Feed
* @return FeedInterface
*/
public function feed($feed_slug, $user_id, $token = null)
{
Expand Down
101 changes: 101 additions & 0 deletions lib/GetStream/Stream/ClientInterface.php
@@ -0,0 +1,101 @@
<?php

namespace GetStream\Stream;

interface ClientInterface
{
/**
* @param string $protocol
*/
public function setProtocol($protocol);

/**
* @param string $location
*/
public function setLocation($location);

/**
* @param string $user_id
* @param array $extra_data
* @return string
*/
public function createUserSessionToken($user_id, array $extra_data = null);

/**
* @param string $user_id
* @param array $extra_data
* @return string
*/
public function createUserToken($user_id, array $extra_data = null);

/**
* @param BaseFeedInterface $feed
* @param string $resource
* @param string $action
* @return string
*/
public function createFeedJWTToken($feed, $resource, $action);

/**
* @param string $feed_slug
* @param string $user_id
* @param string|null $token
* @return FeedInterface
*/
public function feed($feed_slug, $user_id, $token = null);

/**
* @return Batcher
*/
public function batcher();

/**
* @return Personalization
*/
public function personalization();

/**
* @return Collections
*/
public function collections();

/**
* @return Reactions
*/
public function reactions();

/**
* @return Users
*/
public function users();

/**
* @return string
*/
public function getBaseUrl();

/**
* @param string $uri
* @return string
*/
public function buildRequestUrl($uri);

public function getActivities($ids = null, $foreign_id_times = null);

public function batchPartialActivityUpdate($data);

public function doPartialActivityUpdate($id = null, $foreign_id = null, $time = null, $set = null, $unset = null);

public function updateActivities($activities);

public function updateActivity($activity);

/**
* Creates a redirect url for tracking the given events in the context of
* getstream.io/personalization
* @param string $targetUrl
* @param array $events
* @return string
*/
public function createRedirectUrl($targetUrl, $events);
}
7 changes: 3 additions & 4 deletions lib/GetStream/Stream/Collections.php
Expand Up @@ -3,7 +3,6 @@
namespace GetStream\Stream;

use Firebase\JWT\JWT;
use GetStream\Stream\Client as StreamClient;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\HandlerStack;
Expand All @@ -12,7 +11,7 @@
class Collections
{
/**
* @var Client
* @var ClientInterface
*/
private $client;

Expand All @@ -27,11 +26,11 @@ class Collections
private $apiSecret;

/**
* @param \GetStream\Stream\Client $streamClient
* @param ClientInterface $streamClient
* @param string $apiKey
* @param string $apiSecret
*/
public function __construct(StreamClient $streamClient, $apiKey, $apiSecret)
public function __construct(ClientInterface $streamClient, $apiKey, $apiSecret)
{
$this->apiKey = $apiKey;
$this->apiSecret = $apiSecret;
Expand Down
2 changes: 1 addition & 1 deletion lib/GetStream/Stream/Feed.php
Expand Up @@ -7,7 +7,7 @@
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Uri;

class Feed extends BaseFeed
class Feed extends BaseFeed implements FeedInterface
{
/**
* @var string
Expand Down

0 comments on commit 4783725

Please sign in to comment.