AnyEvent-Superfeedr

 view release on metacpan or  search on metacpan

eg/import-opml.pl  view on Meta::CPAN

#!/usr/bin/perl
use strict;
use AnyEvent::Superfeedr;
use XML::OPML::LibXML;

my($opml, $jid, $pass) = @ARGV;
$opml && $jid && $pass or die "Usage: $0 OPML JID password";

my $parser = XML::OPML::LibXML->new;
my $doc = $parser->parse_file($opml);

my @feeds;
$doc->walkdown(sub { push @feeds, $_[0]->xml_url if defined $_[0]->xml_url });

my $superfeedr = AnyEvent::Superfeedr->new(
    debug => $ENV{ANYEVENT_SUPERFEEDR_DEBUG},
    jid => $jid,
    password => $pass,
);

my $end = AnyEvent->condvar;
$end->begin for @feeds;
$superfeedr->connect( sub {
    $superfeedr->subscribe(
        @feeds => sub {
            print STDERR "Subscribed to $_[0]\n";
            $end->send;
        }

eg/print_feed_titles.pl  view on Meta::CPAN

use Encode;

die "$0 <jid> <pass>" unless @ARGV >= 2;

binmode STDOUT, ":utf8";

my $end = AnyEvent->condvar;
my $sf = AnyEvent::Superfeedr->new(
    debug => $ENV{DEBUG},
    jid => shift,
    password => shift,
    # bogus for my tests
    #subscription => {
    #    interval => 5,
    #    sub_cb => sub { [ "firehoser.superfeedr.com" ] },
    #    unsub_cb => sub { [ "", undef, '""', "*" ] },
    #},
    on_notification => sub { 
        my $notification = shift;
        warn $notification->as_xml;
        printf "%s: %s\n", $notification->title, $notification->feed_uri;

eg/status_feed.pl  view on Meta::CPAN

use AnyEvent::Superfeedr;
use Encode;

die "$0 <jid> <pass>" unless @ARGV >= 2;

binmode STDOUT, ":utf8";

my $end = AnyEvent->condvar;
my $sf = AnyEvent::Superfeedr->new(
    jid => shift,
    password => shift,
    on_notification => sub { 
        my $notification = shift;
        printf "Fetched '%s' %s [status=%s], next at %s\n",
            $notification->title,
            $notification->feed_uri,
            $notification->http_status,
            $notification->next_fetch;
    },
);
$sf->connect;

lib/AnyEvent/Superfeedr.pm  view on Meta::CPAN

# debug
# tests? worthwhile?
#
# Also, maybe more direct callbacks for sub/unsub

sub new {
    my $class = shift;
    my %param = @_;

    my %filtered;
    for ( qw{ jid password debug
              on_notification on_connect on_disconnect on_error }) {
        $filtered{$_} = delete $param{$_};
    }
    croak "Unknown option(s): " . join ", ", keys %param if keys %param;

    my $superfeedr = bless {
        debug    => $filtered{debug} || 0,
        jid      => $filtered{jid},
        password => $filtered{password},
    }, ref $class || $class;

    ## can be passed to connect() too
    $superfeedr->{on_connect} = $filtered{on_connect}
        if $filtered{on_connect};

    my $on_error = $filtered{on_error} || sub {
        my ($cl, $acc, $err) = @_;
        if (Scalar::Util::blessed($err)) {
            if ($err->isa('AnyEvent::XMPP::Error')) {
                $err = $err->string;
            }
        }
        warn "Error: " . $err;
    };

    my $cl   = AnyEvent::XMPP::Client->new(
        debug => $superfeedr->{debug},
    );
    my $pass = $superfeedr->{password};
    my $jid  = $superfeedr->{jid}
        or croak "You need to specify your jid";

    $cl->add_account($jid, $pass, undef, undef, {
        dont_retrieve_roster => 1,
    });
    $cl->add_extension(my $ps = AnyEvent::XMPP::Ext::Superfeedr->new);
    $superfeedr->{xmpp_pubsub} = $ps;

    $cl->reg_cb(

lib/AnyEvent/Superfeedr.pm  view on Meta::CPAN

      my $next_fetch  = $notification->next_fetch;
      printf "status %s for %s. next: %s\n",
              $http_status, $feed_uri, $next_fetch;
      for my XML::Atom::Entry $entry ($notification->entries) {
          printf "Got: %s\n" $entry->title;
      }
  };

  my $superfeedr = AnyEvent::Superfeedr->new(
      jid => $jid,
      password => $password
      on_notification => $callback,
  );
  $superfeedr->connect;
  AnyEvent->condvar->recv;

  # Subsribe upon connection
  my $superfeedr = AnyEvent::Superfeedr->new(
      jid => $jid,
      password => $password,
  );
  $superfeedr->connect(sub { $superfeedr->subscribe($feed_uri) });

  # Periodically fetch new URLs from database and subscribe
  my $timer = AnyEvent->timer(
      after => 5,
      interval => 5 * 60,
      cb => sub {
          my @new_feeds = get_new_feeds_from_database() or return;
          $superfeedr->subscribe(@new_feeds);



( run in 1.290 second using v1.01-cache-2.11-cpan-49f99fa48dc )