Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Jul 13, 2009
0 parents commit 5a0e584
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
META.yml
Makefile
inc/
pm_to_blib
*~
2 changes: 2 additions & 0 deletions .shipit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
git.push_to = origin
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Revision history for Perl extension AnyEvent::FriendFeed::Realtime

0.01 Mon Jul 13 15:08:21 2009
- original version
31 changes: 31 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.gitignore
Changes
eg/track.pl
inc/Module/Install.pm
inc/Module/Install/AuthorTests.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Include.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Repository.pm
inc/Module/Install/TestBase.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
inc/Spiffy.pm
inc/Test/Base.pm
inc/Test/Base/Filter.pm
inc/Test/Builder.pm
inc/Test/Builder/Module.pm
inc/Test/More.pm
lib/AnyEvent/FriendFeed/Realtime.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/00_compile.t
xt/perlcritic.t
xt/pod.t
xt/podspell.t
xt/synopsis.t
14 changes: 14 additions & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\bRCS\b
\bCVS\b
\.svn/
\.git/
^MANIFEST\.
^Makefile$
~$
\.old$
^blib/
^pm_to_blib
^MakeMaker-\d
\.gz$
\.cvsignore
\.shipit
15 changes: 15 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use inc::Module::Install;
name 'AnyEvent-FriendFeed-Realtime';
all_from 'lib/AnyEvent/FriendFeed/Realtime.pm';

requires 'AnyEvent';
requires 'AnyEvent::HTTP';
requires 'JSON', '2.0';
requires 'URI';

build_requires 'Test::More';
use_test_base;
auto_include_deps;
author_tests('xt');
auto_set_repository;
WriteAll;
27 changes: 27 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This is Perl module AnyEvent::FriendFeed::Realtime.

INSTALLATION

AnyEvent::FriendFeed::Realtime installation is straightforward. If your CPAN shell is set up,
you should just be able to do

% cpan AnyEvent::FriendFeed::Realtime

Download it, unpack it, then build it as per the usual:

% perl Makefile.PL
% make && make test

Then install it:

% make install

DOCUMENTATION

AnyEvent::FriendFeed::Realtime documentation is available as in POD. So you can do:

% perldoc AnyEvent::FriendFeed::Realtime

to read the documentation online with your favorite pager.

Tatsuhiko Miyagawa
22 changes: 22 additions & 0 deletions eg/track.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/perl
use strict;
use AnyEvent::FriendFeed::Realtime;

my($user, $remote_key, $method) = @ARGV;
my $done = AnyEvent->condvar;

my $client = AnyEvent::FriendFeed::Realtime->new(
username => $user,
remote_key => $remote_key,
method => $method || "home",
on_entry => sub {
my $entry = shift;
warn "$entry->{user}{name}: $entry->{title}\n";
},
on_error => sub {
warn "ERROR: $_[0]";
$done->send;
},
);

$done->recv;
92 changes: 92 additions & 0 deletions lib/AnyEvent/FriendFeed/Realtime.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package AnyEvent::FriendFeed::Realtime;

use strict;
use 5.008_001;
our $VERSION = '0.01';

use AnyEvent;
use AnyEvent::HTTP;
use JSON;
use MIME::Base64;
use URI;

sub new {
my($class, %args) = @_;

my $token;
my $auth = MIME::Base64::encode( join(":", $args{username}, $args{remote_key}) );

my $uri = URI->new("http://friendfeed.com/api/updates"); # initialize token
$uri->query_form(token => $token, format => 'json');

my $timer;
my $long_poll; $long_poll = sub {
http_get $uri, headers => { Authorization => "Basic $auth" },
sub {
my($body, $headers) = @_;
my $res = JSON->new->decode($body);
for my $entry (@{$res->{entries}}) {
($args{on_entry} || sub {})->($entry);
}

if ($res->{update}) {
$token = $res->{update}{token};
$uri = URI->new("http://friendfeed.com/api/updates/$args{method}");
$uri->query_form(token => $token, format => 'json');
$timer = AnyEvent->timer(
after => 1, #$res->{update}{poll_interval},
cb => $long_poll,
);
}
}
};

$long_poll->();

bless { _timer => $timer }, $class;
}

1;
__END__
=encoding utf-8
=for stopwords
=head1 NAME
AnyEvent::FriendFeed::Realtime - Subscribe to FriendFeed Real-time API
=head1 SYNOPSIS
use AnyEvent::FriendFeed::Realtime;
my $client = AnyEvent::FriendFeed::Realtime->new(
username => $user, # optional
remote_key => $remote_key, # optional: https://friendfeed.com/account/api
method => "home", # "user/NICKNAME/friends", "list/NICKNAME", "room/NICKNAME", "user/NICKNAME"
on_update => sub {
my $entry = shift;
# See http://code.google.com/p/friendfeed-api/wiki/ApiDocumentation for the data structure
},
);
=head1 DESCRIPTION
AnyEvent::FriendFeed::Realtime is an AnyEvent consumer that subscribes
to FriendFeed Real-time API via JSON long-poll.
=head1 AUTHOR
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<AnyEvent::HTTP>, L<AnyEvent::Twitter::Stream>, L<http://code.google.com/p/friendfeed-api/wiki/ApiDocumentation>
=cut
4 changes: 4 additions & 0 deletions t/00_compile.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use strict;
use Test::More tests => 1;

BEGIN { use_ok 'AnyEvent::FriendFeed::Realtime' }
5 changes: 5 additions & 0 deletions xt/perlcritic.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use strict;
use Test::More;
eval q{ use Test::Perl::Critic };
plan skip_all => "Test::Perl::Critic is not installed." if $@;
all_critic_ok("lib");
4 changes: 4 additions & 0 deletions xt/pod.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use Test::More;
eval "use Test::Pod 1.00";
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
all_pod_files_ok();
9 changes: 9 additions & 0 deletions xt/podspell.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use Test::More;
eval q{ use Test::Spelling };
plan skip_all => "Test::Spelling is not installed." if $@;
add_stopwords(<DATA>);
set_spell_cmd("aspell -l en list");
all_pod_files_spelling_ok('lib');
__DATA__
Tatsuhiko
Miyagawa
4 changes: 4 additions & 0 deletions xt/synopsis.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use Test::More;
eval "use Test::Synopsis";
plan skip_all => "Test::Synopsis required" if $@;
all_synopsis_ok();

0 comments on commit 5a0e584

Please sign in to comment.