Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Feb 7, 2018
2 parents 089caa4 + a3145c8 commit 5f7f03e
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ sftp-config.json

test.php
/cache


### PhpStorm+all Patch ###
# Ignores the whole idea folder
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# mixedfeed
A PHP library to get social networks feeds and merge them

> A PHP library to rule them all, to entangle them with magic, a PHP library to gather them and bind them in darkness
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/ed3544de-7d64-4ef9-a551-c61a66fb668d/mini.png)](https://insight.sensiolabs.com/projects/ed3544de-7d64-4ef9-a551-c61a66fb668d)
![License](http://img.shields.io/:license-mit-blue.svg)

## Install
## Install

```shell
composer require rezozero/mixedfeed
Expand Down Expand Up @@ -32,6 +33,9 @@ $feed = new MixedFeed([
'twitter_access_token',
'twitter_access_token_secret',
// you can add a doctrine cache provider
// exclude replies true/false
// include retweets true/false
// extended mode true/false
),
new TwitterSearchFeed(
[
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"rezo zero"
],
"require": {
"abraham/twitteroauth": "^0.6.1",
"doctrine/cache": "^1.4",
"guzzlehttp/guzzle": "~5.0"
"abraham/twitteroauth": "^0.7.4",
"doctrine/cache": "^1.6.2",
"guzzlehttp/guzzle": "~5.0 || ~6.0"
},
"autoload": {
"psr-4": {"RZ\\MixedFeed\\": "src/"}
Expand Down
7 changes: 6 additions & 1 deletion src/AbstractFeedProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
namespace RZ\MixedFeed;

use RZ\MixedFeed\Exception\FeedProviderErrorException;
use RZ\MixedFeed\FeedProviderInterface;

/**
* Implements a basic feed provider with
Expand All @@ -36,6 +35,12 @@ abstract class AbstractFeedProvider implements FeedProviderInterface
{
protected $ttl = 7200;

/**
* @param int $count
* @return array
*/
protected abstract function getFeed($count = 5);

/**
* {@inheritdoc}
*/
Expand Down
21 changes: 12 additions & 9 deletions src/AbstractFeedProvider/AbstractTwitterFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@

use Abraham\TwitterOAuth\TwitterOAuth;
use Doctrine\Common\Cache\CacheProvider;
use RZ\MixedFeed\AbstractFeedProvider;
use RZ\MixedFeed\Exception\CredentialsException;
use RZ\MixedFeed\AbstractFeedProvider as BaseFeedProvider;
use RZ\MixedFeed\Exception\CredentialsException;

/**
* Get a Twitter tweets abstract feed.
*/
class AbstractTwitterFeed extends BaseFeedProvider
abstract class AbstractTwitterFeed extends BaseFeedProvider
{
protected $accessToken;
protected $cacheProvider;
Expand All @@ -44,12 +43,12 @@ class AbstractTwitterFeed extends BaseFeedProvider

/**
*
* @param array $queryParams
* @param string $consumerKey
* @param string $consumerSecret
* @param string $accessToken
* @param string $accessTokenSecret
* @param string $consumerKey
* @param string $consumerSecret
* @param string $accessToken
* @param string $accessTokenSecret
* @param CacheProvider|null $cacheProvider
* @throws CredentialsException
*/
public function __construct(
$consumerKey,
Expand Down Expand Up @@ -105,7 +104,11 @@ public function getDateTime($item)
*/
public function getCanonicalMessage($item)
{
return $item->text;
if (isset($item->text)) {
return $item->text;
}

return $item->full_text;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/CredentialsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
*/
namespace RZ\MixedFeed\Exception;

use Throwable;

class CredentialsException extends \Exception
{
public function __construct($message = "Unsufficient authentification data found.")
public function __construct($message = "Unsufficient authentification data found.", $code = 0, Throwable $previous = null)
{
parent::__construct($message, 1);
parent::__construct($message, $code, $previous);
}
}
17 changes: 12 additions & 5 deletions src/FacebookPageFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
namespace RZ\MixedFeed;

use Doctrine\Common\Cache\CacheProvider;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use RZ\MixedFeed\AbstractFeedProvider;
use RZ\MixedFeed\Exception\CredentialsException;

/**
Expand All @@ -42,17 +42,24 @@ class FacebookPageFeed extends AbstractFeedProvider
protected $cacheProvider;
protected $cacheKey;
protected $fields;
/**
* @var \DateTime|null
*/
protected $since = null;
/**
* @var \DateTime|null
*/
protected $until = null;

protected static $timeKey = 'created_time';

/**
*
* @param string $pageId
* @param string $accessToken Your App Token
* @param string $pageId
* @param string $accessToken Your App Token
* @param CacheProvider|null $cacheProvider
* @param array $fields
* @param array $fields
* @throws CredentialsException
*/
public function __construct(
$pageId,
Expand Down Expand Up @@ -85,7 +92,7 @@ protected function getFeed($count = 5)
return $this->cacheProvider->fetch($countKey);
}

$client = new \GuzzleHttp\Client();
$client = new Client();
$params = [
'query' => [
'access_token' => $this->accessToken,
Expand Down
7 changes: 4 additions & 3 deletions src/GithubCommitsFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

use Doctrine\Common\Cache\CacheProvider;
use GuzzleHttp\Exception\ClientException;
use RZ\MixedFeed\AbstractFeedProvider;
use RZ\MixedFeed\Exception\CredentialsException;

/**
Expand All @@ -45,9 +44,11 @@ class GithubCommitsFeed extends AbstractFeedProvider

/**
*
* @param string $repository
* @param string $accessToken
* @param string $repository
* @param string $accessToken
* @param CacheProvider|null $cacheProvider
* @param int $page
* @throws CredentialsException
*/
public function __construct(
$repository,
Expand Down
1 change: 0 additions & 1 deletion src/InstagramFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

use Doctrine\Common\Cache\CacheProvider;
use GuzzleHttp\Exception\ClientException;
use RZ\MixedFeed\AbstractFeedProvider;
use RZ\MixedFeed\Exception\CredentialsException;

/**
Expand Down
14 changes: 11 additions & 3 deletions src/MixedFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
*/
namespace RZ\MixedFeed;

use RZ\MixedFeed\AbstractFeedProvider;
use RZ\MixedFeed\Exception\FeedProviderErrorException;
use RZ\MixedFeed\MockObject\ErroredFeedItem;

/**
* Combine feed providers and sort them antechronological.
* Combine feed providers and sort them ante-chronological.
*/
class MixedFeed extends AbstractFeedProvider
{
protected $providers;

/**
* Create a mixed feed composed of hetergeneous feed
* Create a mixed feed composed of heterogeneous feed
* providers.
*
* @param array $providers
Expand All @@ -62,6 +61,7 @@ public function getItems($count = 5)
if (count($this->providers) > 0) {
$perProviderCount = floor($count / count($this->providers));

/** @var FeedProviderInterface $provider */
foreach ($this->providers as $provider) {
try {
$list = array_merge($list, $provider->getItems($perProviderCount));
Expand Down Expand Up @@ -126,4 +126,12 @@ public function getErrors($feed)
{
return '';
}

/**
* @inheritDoc
*/
protected function getFeed($count = 5)
{
trigger_error('getFeed method must not be called in MixedFeed.', E_USER_ERROR);
}
}
9 changes: 5 additions & 4 deletions src/PinterestBoardFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
namespace RZ\MixedFeed;

use Doctrine\Common\Cache\CacheProvider;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use RZ\MixedFeed\AbstractFeedProvider;
use RZ\MixedFeed\Exception\CredentialsException;

/**
Expand All @@ -46,9 +46,10 @@ class PinterestBoardFeed extends AbstractFeedProvider

/**
*
* @param string $boardId
* @param string $accessToken Your App Token
* @param string $boardId
* @param string $accessToken Your App Token
* @param CacheProvider|null $cacheProvider
* @throws CredentialsException
*/
public function __construct(
$boardId,
Expand Down Expand Up @@ -77,7 +78,7 @@ protected function getFeed($count = 5)
return $this->cacheProvider->fetch($countKey);
}

$client = new \GuzzleHttp\Client();
$client = new Client();
$response = $client->get('https://api.pinterest.com/v1/boards/' . $this->boardId . '/pins/', [
'query' => [
'access_token' => $this->accessToken,
Expand Down
25 changes: 17 additions & 8 deletions src/TwitterFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ class TwitterFeed extends AbstractTwitterFeed
protected $includeRts;

protected static $timeKey = 'created_at';
/**
* @var bool
*/
protected $extended;

/**
*
* @param string $userId
* @param string $consumerKey
* @param string $consumerSecret
* @param string $accessToken
* @param string $accessTokenSecret
* @param string $userId
* @param string $consumerKey
* @param string $consumerSecret
* @param string $accessToken
* @param string $accessTokenSecret
* @param CacheProvider|null $cacheProvider
* @param boolean $excludeReplies
* @param boolean $includeRts
* @param boolean $excludeReplies
* @param boolean $includeRts
* @param bool $extended
* @throws Exception\CredentialsException
*/
public function __construct(
$userId,
Expand All @@ -63,7 +69,8 @@ public function __construct(
$accessTokenSecret,
CacheProvider $cacheProvider = null,
$excludeReplies = true,
$includeRts = false
$includeRts = false,
$extended = false
) {

parent::__construct(
Expand All @@ -77,6 +84,7 @@ public function __construct(
$this->userId = $userId;
$this->excludeReplies = $excludeReplies;
$this->includeRts = $includeRts;
$this->extended = $extended;
$this->cacheKey = $this->getFeedPlatform() . $this->userId;
}

Expand All @@ -94,6 +102,7 @@ protected function getFeed($count = 5)
"count" => $count,
"exclude_replies" => $this->excludeReplies,
'include_rts' => $this->includeRts,
'tweet_mode' => ($this->extended ? 'extended' : '')
]);
if (null !== $this->cacheProvider) {
$this->cacheProvider->save(
Expand Down
Loading

0 comments on commit 5f7f03e

Please sign in to comment.