-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Cornatul/wip
Wip
- Loading branch information
Showing
33 changed files
with
1,805 additions
and
790 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Cornatul\Feeds\Clients; | ||
|
||
use Cornatul\Feeds\Connectors\FeedlyConnector; | ||
use Cornatul\Feeds\Connectors\NlpConnector; | ||
use Cornatul\Feeds\Contracts\ArticleManager; | ||
use Cornatul\Feeds\Contracts\FeedManager; | ||
use Cornatul\Feeds\Contracts\FeedFinderInterface; | ||
use Cornatul\Feeds\DTO\ArticleDto; | ||
use Cornatul\Feeds\Requests\FeedlyTopicRequest; | ||
use Cornatul\Feeds\Requests\GetArticleRequest; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use JsonException; | ||
use Cornatul\Feeds\DTO\FeedDto; | ||
use Saloon\Exceptions\InvalidResponseClassException; | ||
use Saloon\Exceptions\PendingRequestException; | ||
use Spatie\SchemaOrg\Contracts\ArticleContract; | ||
|
||
|
||
class FeedLaminasClient implements \Laminas\Feed\Reader\Http\ClientInterface | ||
{ | ||
|
||
private int $statusCode = 200; | ||
|
||
private string $body = ''; | ||
|
||
/** | ||
* @method get | ||
* @throws GuzzleException | ||
*/ | ||
public final function get($url) | ||
{ | ||
$client = new Client(); | ||
|
||
$response = $client->get($url); | ||
|
||
$this->body = $response->getBody()->getContents(); | ||
|
||
$this->statusCode = $response->getStatusCode(); | ||
|
||
return $this; | ||
} | ||
|
||
public final function getStatusCode(): int | ||
{ | ||
return $this->statusCode; | ||
} | ||
|
||
public final function getBody(): string | ||
{ | ||
return $this->body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Cornatul\Feeds\Clients; | ||
|
||
use Cornatul\Feeds\Connectors\FeedlyConnector; | ||
use Cornatul\Feeds\Connectors\NlpConnector; | ||
use Cornatul\Feeds\Contracts\ArticleManager; | ||
use Cornatul\Feeds\Contracts\FeedManager; | ||
use Cornatul\Feeds\Contracts\FeedFinderInterface; | ||
use Cornatul\Feeds\DTO\ArticleDto; | ||
use Cornatul\Feeds\Requests\FeedlyTopicRequest; | ||
use Cornatul\Feeds\Requests\GetArticleRequest; | ||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use JsonException; | ||
use Cornatul\Feeds\DTO\FeedDto; | ||
use Saloon\Exceptions\InvalidResponseClassException; | ||
use Saloon\Exceptions\PendingRequestException; | ||
use Spatie\SchemaOrg\Contracts\ArticleContract; | ||
|
||
|
||
class NLPClient implements ArticleManager | ||
{ | ||
/** | ||
* @method find | ||
*/ | ||
public final function find(string $url, string $language = "en"): ArticleDto | ||
{ | ||
|
||
try { | ||
|
||
$nlpConnector = new NlpConnector(); | ||
|
||
$response = $nlpConnector->send(new GetArticleRequest($topic)); | ||
|
||
return ArticleDto::from($response->json()); | ||
|
||
} catch (GuzzleException|\ReflectionException|InvalidResponseClassException|PendingRequestException $exception) { | ||
|
||
logger($exception->getMessage()); | ||
} | ||
|
||
return ArticleDto::from([]); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Cornatul\Feeds\Console; | ||
|
||
use Cornatul\Feeds\Clients\FeedLaminasClient; | ||
use Cornatul\Feeds\Connectors\FeedlyConnector; | ||
use Cornatul\Feeds\Connectors\NlpConnector; | ||
use Cornatul\Feeds\Jobs\FeedArticleExtractor; | ||
use Cornatul\Feeds\Models\Feed; | ||
use Cornatul\Feeds\Requests\FeedlyTopicRequest; | ||
use Cornatul\Feeds\Requests\GetArticleRequest; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Config; | ||
use Laminas\Feed\Reader\Reader; | ||
use Saloon\Exceptions\InvalidResponseClassException; | ||
use Saloon\Exceptions\PendingRequestException; | ||
|
||
class FeedEntriesExtractor extends Command | ||
{ | ||
|
||
protected $signature = 'feed:extract {url}'; | ||
|
||
protected $description = 'Extract the full list of articles from a given feed'; | ||
|
||
/** | ||
* @throws \ReflectionException | ||
* @throws InvalidResponseClassException | ||
* @throws PendingRequestException | ||
* @throws \JsonException | ||
*/ | ||
public function handle(): void | ||
{ | ||
$url = $this->argument('url'); | ||
|
||
$client = new FeedLaminasClient(); | ||
|
||
Reader::setHttpClient($client); | ||
|
||
$data = Reader::import($url); | ||
|
||
$feed = Feed::first(); | ||
|
||
foreach ($data as $entity) | ||
{ | ||
dispatch(new FeedArticleExtractor($entity->getLink(), $feed))->onQueue("article-extractor"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Cornatul\Feeds\Contracts; | ||
|
||
use Cornatul\Feeds\DTO\ArticleDto; | ||
use Cornatul\Feeds\DTO\FeedDto; | ||
|
||
interface ArticleManager | ||
{ | ||
public function extract(string $url): ArticleDto; | ||
|
||
|
||
} |
4 changes: 2 additions & 2 deletions
4
src/Interfaces/FeedFinderInterface.php → src/Contracts/FeedManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Cornatul\Feeds\Interfaces; | ||
namespace Cornatul\Feeds\Contracts; | ||
|
||
use Cornatul\Feeds\DTO\FeedDto; | ||
|
||
interface FeedFinderInterface | ||
interface FeedManager | ||
{ | ||
public function find(string $topic): FeedDto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.