-
-
Notifications
You must be signed in to change notification settings - Fork 669
Share articles on Twitter #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3eef476
Install twitter notifications
joedixon 9a4bad3
Add command to post to twitter
joedixon f31ce64
Add twitter handle to user
joedixon 044552a
Use handle in tweets
joedixon 631f522
Apply PHP CS Fixer changes
joedixon b83328c
Update tweet content
joedixon 4d35ed6
Update code style
joedixon f68c31c
Rename twitter_handle field
joedixon 124a0da
Update factory call
joedixon e8412f1
Update factory
joedixon 5270914
Apply fixes from StyleCI
joedixon 7a5d1da
Invert null check
joedixon 02592b0
Update sharing schedule
joedixon b159ab7
Remove example env vars
joedixon dab8308
Update code style
joedixon 9189100
Rename migration
joedixon 037ce64
Format template
joedixon 036a320
Apply fixes from StyleCI
joedixon b34115b
Store tweet id
joedixon 5274982
Apply fixes from StyleCI
joedixon 058f8d9
Update code style
joedixon d5a29a4
Apply fixes from StyleCI
joedixon 614d3b2
Update readme
joedixon 95ff455
Update Kernel.php
driesvints 7d91fa6
Update _user_info.blade.php
driesvints File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| <?php | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Models\Article; | ||
| use App\Notifications\PostArticleToTwitter as PostArticleToTwitterNotification; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Notifications\AnonymousNotifiable; | ||
|
|
||
| final class PostArticleToTwitter extends Command | ||
| { | ||
| protected $signature = 'post-article-to-twitter'; | ||
|
|
||
| protected $description = 'Posts the latest unshared article to Twitter'; | ||
|
|
||
| private $notifiable; | ||
|
|
||
| public function __construct(AnonymousNotifiable $notifiable) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->notifiable = $notifiable; | ||
| } | ||
|
|
||
| public function handle(): void | ||
| { | ||
| if ($article = Article::nextForSharing()) { | ||
| $this->notifiable->notify(new PostArticleToTwitterNotification($article)); | ||
|
|
||
| $article->markAsShared(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Listeners; | ||
|
|
||
| use App\Notifications\PostArticleToTwitter; | ||
| use Illuminate\Notifications\Events\NotificationSent; | ||
|
|
||
| final class StoreTweetIdentifier | ||
| { | ||
| public function handle(NotificationSent $event): void | ||
| { | ||
| if ($event->notification instanceof PostArticleToTwitter) { | ||
| $event->notification->article()->update([ | ||
| 'tweet_id' => $event->response->id, | ||
| ]); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,46 @@ | ||
| <?php | ||
|
|
||
| namespace App\Notifications; | ||
|
|
||
| use App\Models\Article; | ||
| use Illuminate\Bus\Queueable; | ||
| use Illuminate\Notifications\Notification; | ||
| use NotificationChannels\Twitter\TwitterChannel; | ||
| use NotificationChannels\Twitter\TwitterStatusUpdate; | ||
|
|
||
| class PostArticleToTwitter extends Notification | ||
| { | ||
| use Queueable; | ||
|
|
||
| private $article; | ||
|
|
||
| public function __construct(Article $article) | ||
| { | ||
| $this->article = $article; | ||
| } | ||
|
|
||
| public function via($notifiable) | ||
| { | ||
| return [TwitterChannel::class]; | ||
| } | ||
|
|
||
| public function toTwitter($notifiable) | ||
| { | ||
| return new TwitterStatusUpdate($this->generateTweet()); | ||
| } | ||
|
|
||
| public function generateTweet() | ||
| { | ||
| $title = $this->article->title(); | ||
| $url = route('articles.show', $this->article->slug()); | ||
| $author = $this->article->author(); | ||
| $author = $author->twitter() ? "@{$author->twitter()}" : $author->name(); | ||
|
|
||
| return "{$title} by {$author}\n\n{$url}"; | ||
| } | ||
|
|
||
| public function article() | ||
| { | ||
| return $this->article; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.