BusyBird-Input-Lingr
view release on metacpan or search on metacpan
lib/BusyBird/Input/Lingr.pm view on Meta::CPAN
$time->year, $time->month, $time->day, $message->{id});
return {
id => $permalink,
created_at => BusyBird::DateTime::Format->format_datetime($time),
user => {
profile_image_url => $message->{icon_url},
screen_name => $message->{speaker_id},
name => $message->{nickname},
},
text => $message->{text},
busybird => {
status_permalink => $permalink
}
};
}
1;
__END__
=pod
lib/BusyBird/Input/Lingr.pm view on Meta::CPAN
use WebService::Lingr::Archives;
use BusyBird::Input::Lingr;
my $downloader = WebService::Lingr::Archives->new(
user => 'your lingr username',
passworkd => 'your lingr password',
);
my $input = BusyBird::Input::Lingr->new;
my @raw_messages = $downloader->get_archives("perl_jp");
my @busybird_statuses = $input->convert(@raw_messages);
timeline("perl_jp_chat")->add(\@busybird_statuses);
=head1 DESCRIPTION
L<BusyBird::Input::Lingr> converts text message objects obtained from Lingr (L<http://lingr.com/>) API into L<BusyBird> status objects.
Note that this module does not download messages from Lingr.
For that purpose, use L<WebService::Lingr::Archives> or L<AnyEvent::Lingr>.
=head1 CLASS METHODS
lib/BusyBird/Input/Lingr.pm view on Meta::CPAN
=over
=item C<api_base> => STR (optional, default: "http://lingr.com/api")
Lingr API base URL. This field is used to create permalinks.
=back
=head1 OBJECT METHODS
=head2 @busybird_statuses = $input->convert(@lingr_messages)
Convert Lingr message objects into L<BusyBird> status objects.
If called in scalar context, it returns the first status object.
If there is an invalid message in C<@lingr_messages>, this method croaks.
=head1 SEE ALSO
=over
my $got = $input->convert(message(10, '2014-05-21T05:23:33Z'));
cmp_deeply $got, sh(
id => 'http://lingr.com/room/sample_room/archives/2014/05/21#message-10',
created_at => 'Wed May 21 05:23:33 +0000 2014',
user => sh(
screen_name => 'toshioito',
name => 'Toshio Ito',
profile_image_url => 'http://hoge.com/avatar.png'
),
text => "ID: 10",
busybird => sh(
status_permalink => 'http://lingr.com/room/sample_room/archives/2014/05/21#message-10'
)
), "default setting OK";
}
{
my $api_base = "http://other.lingr.org/api";
my $exp_base = "http://other.lingr.org";
my $input = BusyBird::Input::Lingr->new(api_base => $api_base);
my @testcases = (
{ label => "single", input => [ message(143, '2014-07-24T22:12:00Z') ],
exp => [sh(
id => "$exp_base/room/sample_room/archives/2014/07/24#message-143",
created_at => "Thu Jul 24 22:12:00 +0000 2014",
user => sh(
screen_name => "toshioito",
name => 'Toshio Ito',
profile_image_url => 'http://hoge.com/avatar.png',
),
text => "ID: 143",
busybird => sh( status_permalink => "$exp_base/room/sample_room/archives/2014/07/24#message-143" )
)]},
{ label => "two", input => [message(200, '2014-07-07T10:00:03Z'), message(300, '2014-07-07T10:11:34Z', 't-ito', 'TITO')],
exp => [
sh(
id => "$exp_base/room/sample_room/archives/2014/07/07#message-200",
created_at => "Mon Jul 07 10:00:03 +0000 2014",
user => sh(
screen_name => "toshioito",
name => 'Toshio Ito',
profile_image_url => 'http://hoge.com/avatar.png',
),
text => "ID: 200",
busybird => sh( status_permalink => "$exp_base/room/sample_room/archives/2014/07/07#message-200" )
),
sh(
id => "$exp_base/room/sample_room/archives/2014/07/07#message-300",
created_at => "Mon Jul 07 10:11:34 +0000 2014",
user => sh(
screen_name => "t-ito",
name => 'TITO',
profile_image_url => 'http://hoge.com/avatar.png',
),
text => "ID: 300",
busybird => sh( status_permalink => "$exp_base/room/sample_room/archives/2014/07/07#message-300" )
),
]}
);
foreach my $case (@testcases) {
my $label = $case->{label};
my @got_list = $input->convert(@{$case->{input}});
cmp_deeply \@got_list, $case->{exp}, "$label: list result OK";
my $got_scalar = $input->convert(@{$case->{input}});
is_deeply $got_scalar, $got_list[0], "$label: scalar result OK";
( run in 0.371 second using v1.01-cache-2.11-cpan-87723dcf8b7 )