Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
Add github markdown parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Aug 17, 2015
1 parent 7fd201c commit bb8f124
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
28 changes: 28 additions & 0 deletions app/GitHubMarkdownParser.php
@@ -0,0 +1,28 @@
<?php

namespace App;

use Github\Client;
use Github\HttpClient\Message\ResponseMediator;

class GitHubMarkdownParser
{
private $client;

public function __construct($user, Client $client)
{
$this->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);
}
}
30 changes: 24 additions & 6 deletions app/Http/routes.php
Expand Up @@ -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();
});
5 changes: 4 additions & 1 deletion app/Jobs/NotifyUserOfNewGistComment.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/new-comment.blade.php
Expand Up @@ -16,7 +16,7 @@
<a href="{{ $gist['html_url'] }}#gistcomment-{{ $comment['id'] }}" style="color: #555;" title="{{ $date->format('g:ia \o\n F j, Y') }} GMT">{{ $date->diffForHumans() }}</a>
</div>
<div style="padding: 1em;">
{!! str_replace("\n", "<br>", $comment['body']) !!}
{!! $body !!}
</div>
</div>
</td>
Expand Down

0 comments on commit bb8f124

Please sign in to comment.