forked from miyagawa/AnyEvent-FriendFeed-Realtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a0e584
Showing
14 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
META.yml | ||
Makefile | ||
inc/ | ||
pm_to_blib | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |