Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Whim.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sub startup {
$r->get('/')->to('listen#default');
$r->post('/')->to('listen#receive');

$r->get('/wms')->to('display#json');
$r->get('/display_wms')->to('display#display');
$r->get('/summarize_wms')->to('display#summarize');

Expand Down
36 changes: 36 additions & 0 deletions lib/Whim/Controller/Display.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
package Whim::Controller::Display;
use Mojo::Base 'Mojolicious::Controller';
use Whim::Mention;
use List::Util qw/ pairmap /;

use Readonly;
Readonly my $BAD_REQUEST => 400;

sub serialize_wm {
my $wm = shift;

my $data = $wm->TO_JSON;

# TO_JSON doesn't put all the yumminess
# in the hash, so I augment with the
# other stuff I want

if( my $author = $wm->author ) {
$data->{author} = {
map { $_ => $author->$_ } qw/ name url photo /
}
}

if( $wm->author_photo_hash ) {
$data->{author}{local_photo} =
'/author_photos/' . $wm->author_photo_hash;
}

return $data;
}

sub json {
my $self = shift;

return unless $self->_get_wms;

my %mentions = pairmap {
$a => [ map { serialize_wm($_) } @$b ]
} %{ $self->stash->{webmentions} };

$self->render( json => \%mentions );
}

sub display {
my $self = shift;

Expand Down