Skip to content

Commit

Permalink
Merge branch 'release/v4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Jan 21, 2022
2 parents 062da5e + d91d1e1 commit 02763b2
Show file tree
Hide file tree
Showing 35 changed files with 910 additions and 1,517 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ docker run -p 8080:80 \
rezozero/mixedfeed
```

or use `docker-compose`: copy `docker-compose.yml` to `docker-compose.test.yml` and fill your provider credentials in
it. Then execute `docker-compose -f docker-compose.test.yml up -d --force-recreate`, *Mixedfeed* will be available at
http://localhost:8080

### Available environment variables

| Name | Default value | Multiple? (comma separated) |
Expand All @@ -41,8 +45,6 @@ docker run -p 8080:80 \
| MF_FACEBOOK_ACCESS_TOKEN | | |
| MF_FACEBOOK_FIELDS | from,link,picture,full_picture,message,story,type,created_time,source,status_type ||
| MF_FACEBOOK_ENDPOINT | https://graph.facebook.com/v2.12/ | |
| MF_INSTAGRAM_USER_ID | ||
| MF_INSTAGRAM_ACCESS_TOKEN | | |
| MF_GRAPH_INSTAGRAM_USER_ID | ||
| MF_GRAPH_INSTAGRAM_ACCESS_TOKEN | ||
| MF_GITHUB_RELEASES_REPOSITORY | ||
Expand Down Expand Up @@ -145,7 +147,7 @@ return $feed->getAsyncCanonicalItems(12);

## Combine feeds

*mixedfeed* can combine multiple social feeds so you can loop over them and use some common data fields such as `feedItemPlatform`, `normalizedDate` and `canonicalMessage`. *mixedfeed* will sort all your feed items by *descending* `normalizedDate`, but you can configure it to sort *ascending*:
*mixedfeed* can combine multiple social feeds so you can loop over them and use some common data fields such as `feedItemPlatform`, `normalizedDate` and `canonicalMessage`. *mixedfeed* will sort all your feed items by *descending* `normalizedDate`, but you can configure it to sort *ascending*:

```php
new MixedFeed([…], MixedFeed::ASC);
Expand Down Expand Up @@ -181,11 +183,12 @@ object with essential data: `RZ\MixedFeed\Canonical\FeedItem`. *FeedItem* will p
- likeCount `int|null`
- shareCount `int|null`: Share, comments or retweet count depending on platform.
- images `Image[]`
- url `string`
- width `integer`
- height `integer`
- url `string`
- width `integer`
- height `integer`
- dateTime `DateTime`
- tags `array` (only used with `MediumFeed`)
- raw `stdClass` to access raw API object if canonical item fields are not enough

When FeedItem has images, `FeedItem::$images` will hold an array of `RZ\MixedFeed\Canonical\Image` objects to
have better access to its `url`, `width` and `height` if they're available.
Expand Down Expand Up @@ -221,12 +224,12 @@ There are plenty of APIs on the internet, and this tool won’t be able to handl
But this is not a problem, you can easily create your own feed provider in *mixedfeed*. You just have to create a new *class* that
will inherit from `RZ\MixedFeed\AbstractFeedProvider`. Then you will have to implement some methods from `FeedProviderInterface`:

* `getRequests($count = 5): \Generator` method which return a *Guzzle* `Request` generator to be transformed to a response. This is
* `getRequests($count = 5): \Generator` method which return a *Guzzle* `Request` generator to be transformed to a response. This is
the best option as it will enable **async request pooling**.
* `supportsRequestPool(): bool` method should return if your provider can be pooled to enhance performances. If you are using a third party library to fetch your data (such as some platform SDK), you should set it to `false`.
* `createFeedItemFromObject($item)` method which transform a raw feed object into a canonical `RZ\MixedFeed\Canonical\FeedItem` and `RZ\MixedFeed\Canonical\Image`
* `getDateTime` method to look for the critical datetime field in your feed.
* `getFeed` method to consume your API endpoint with a count limit and take care of caching your responses.
* `getFeed` method to consume your API endpoint with a count limit and take care of caching your responses.
This method **must convert your own feed items into `\stdClass` objects, not arrays.**
* `getCanonicalMessage` method to look for the important text content in your feed items.
* `getFeedPlatform` method to get a global text identifier for your feed items.
Expand Down Expand Up @@ -255,7 +258,7 @@ protected function getFeed($count = 5)
$object = new \stdClass();
$object->native = $article;
return $object;
},
},
$this->entityManager->getRepository(Article::class)->findBy(
[],
['datetime' => 'DESC'],
Expand All @@ -270,13 +273,13 @@ protected function createFeedItemFromObject($item)
$feedItem->setDateTime($this->getDateTime($item));
$feedItem->setMessage($this->getCanonicalMessage($item));
$feedItem->setPlatform($this->getFeedPlatform());

for ($item->images as $image) {
$feedItemImage = new RZ\MixedFeed\Canonical\Image();
$feedItemImage->setUrl($image->url);
$feedItem->addImage($feedItemImage);
}

return $feedItem;
}
```
Expand All @@ -299,7 +302,7 @@ public function getDateTime($item)
/**
* @inheritDoc
*/
public function getCanonicalMessage($item)
public function getCanonicalMessage(stdClass $item)
{
if ($item->native instanceof Article) {
return $item->native->getExcerpt();
Expand Down
48 changes: 28 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"name": "rezozero/mixedfeed",
"type": "library",
"description": "A PHP library to get social networks feeds and merge them",
"keywords": [
"feed",
"social",
"social networks",
"aggregator",
"rezo zero"
],
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Ambroise Maupate",
Expand All @@ -11,28 +18,29 @@
"role": "Lead developer"
}
],
"keywords": [
"feed",
"social",
"social networks",
"aggregator",
"rezo zero"
],
"require": {
"php": ">=7.2",
"abraham/twitteroauth": "^2.0.0",
"doctrine/cache": "^1.6.2",
"guzzlehttp/guzzle": "~6.0 || ~7.0",
"ext-json": "*"
},
"autoload": {
"psr-4": {"RZ\\MixedFeed\\": "src/"}
"php": "^7.4 || ^8.0",
"ext-json": "*",
"abraham/twitteroauth": "^3.0",
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/promises": "^1.5",
"guzzlehttp/psr7": "^2.1",
"psr/cache": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3",
"jms/serializer": "^2.1 || ^3.5",
"symfony/stopwatch": ">=4.2",
"symfony/dotenv": ">=4.2",
"phpstan/phpstan": "^0.12.14"
"phpstan/phpstan": "^1.0",
"squizlabs/php_codesniffer": "^3.3",
"symfony/cache": "^5.0",
"symfony/dotenv": "^5.0",
"symfony/stopwatch": "^5.0"
},
"autoload": {
"psr-4": {
"RZ\\MixedFeed\\": "src/"
}
},
"scripts": {
"analyze": "vendor/bin/phpstan"
}
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ services:
# MF_FACEBOOK_ACCESS_TOKEN: ""
# MF_FACEBOOK_FIELDS: "from,picture,full_picture,message,story,created_time,status_type,message_tags,shares,permalink_url"
# MF_FACEBOOK_ENDPOINT: "https://graph.facebook.com/v2.12/"
# MF_INSTAGRAM_USER_ID: ""
# MF_INSTAGRAM_ACCESS_TOKEN: ""
# MF_GRAPH_INSTAGRAM_USER_ID: ""
# MF_GRAPH_INSTAGRAM_ACCESS_TOKEN: ""

# MF_GITHUB_RELEASES_REPOSITORY: ""
# MF_GITHUB_COMMITS_REPOSITORY: ""
Expand Down
3 changes: 2 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<arg name="colors"/>
<arg name="extensions" value="php"/>

<rule ref="PSR2">
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength"/>
</rule>

<file>src/</file>
<exclude-pattern>*/node_modules</exclude-pattern>
</ruleset>
11 changes: 2 additions & 9 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
parameters:
level: 3
level: 8
checkMissingIterableValueType: false
paths:
- src
excludes_analyse:
- */node_modules/*
- */bower_components/*
- */static/*
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
Loading

0 comments on commit 02763b2

Please sign in to comment.