From bb8f124aa84e87d6f2fe255dc788a27fba2955a9 Mon Sep 17 00:00:00 2001 From: Matt Stauffer Date: Mon, 17 Aug 2015 00:34:49 -0400 Subject: [PATCH] Add github markdown parsing --- app/GitHubMarkdownParser.php | 28 ++++++++++++++++++ app/Http/routes.php | 30 ++++++++++++++++---- app/Jobs/NotifyUserOfNewGistComment.php | 5 +++- resources/views/emails/new-comment.blade.php | 2 +- 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 app/GitHubMarkdownParser.php diff --git a/app/GitHubMarkdownParser.php b/app/GitHubMarkdownParser.php new file mode 100644 index 0000000..6668170 --- /dev/null +++ b/app/GitHubMarkdownParser.php @@ -0,0 +1,28 @@ +client = $client; + $this->client->authenticate($user->token, Client::AUTH_HTTP_TOKEN); + } + + public function parse($markdown) + { + $body = json_encode([ + 'text' => $markdown + ]); + + $response = $this->client->getHttpClient()->post('markdown', $body); + + return ResponseMediator::getContent($response); + } +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 115e63b..8c58bb2 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -16,10 +16,28 @@ Route::post('sign-up', 'SignupController@stripePostback'); }); -// Route::get('test', function (\Illuminate\Contracts\Bus\Dispatcher $bus) { -// $bus->dispatch(new \App\Jobs\NotifyUserOfNewGistComments( -// \App\User::first() -// )); +Route::get('test', function (\Illuminate\Contracts\Bus\Dispatcher $bus) { + $message = "# Hello world!\n*this* is _great_ :+1:\nyup yup"; + // $body = json_encode([ + // 'text' => $message + // ]); -// return rand(); -// }); + $user = \App\User::first(); + $parser = app('App\GitHubMarkdownParser', [$user]); + + // $client = new Github\Client(); + // $client->authenticate($user->token, \Github\Client::AUTH_HTTP_TOKEN); + // $response = $client->getHttpClient()->post('markdown', $body); + // $output = \Github\HttpClient\Message\ResponseMediator::getContent($response); + // dd($output); + dd($parser->parse($message)); + + // $client = app('Github\Client'); + // $user = \App\User::first(); + // $client->authenticate($user->token, \Github\Client::AUTH_HTTP_TOKEN); + $bus->dispatch(new \App\Jobs\NotifyUserOfNewGistComments( + \App\User::first() + )); + + return rand(); +}); diff --git a/app/Jobs/NotifyUserOfNewGistComment.php b/app/Jobs/NotifyUserOfNewGistComment.php index 9386be8..d1a67e6 100644 --- a/app/Jobs/NotifyUserOfNewGistComment.php +++ b/app/Jobs/NotifyUserOfNewGistComment.php @@ -46,12 +46,15 @@ public function handle() private function sendNotificationEmail($comment, $gist, $user) { + $parser = app('App\GitHubMarkdownParser', [$user]); + Mail::send( 'emails.new-comment', [ 'comment' => $comment, 'gist' => $gist, - 'user' => $user + 'user' => $user, + 'body' => $parser->parse($comment['body']) ], function ($message) use ($user) { $message diff --git a/resources/views/emails/new-comment.blade.php b/resources/views/emails/new-comment.blade.php index 74bcd41..8a1326f 100644 --- a/resources/views/emails/new-comment.blade.php +++ b/resources/views/emails/new-comment.blade.php @@ -16,7 +16,7 @@ {{ $date->diffForHumans() }}
- {!! str_replace("\n", "
", $comment['body']) !!} + {!! $body !!}