AnyEvent-Feed

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for AnyEvent::Feed

0.3     Tue Mar  1 07:53:57 CET 2011
        - fixed typo in the synopsis.
        - applied patch for encode_base64 issue, which trashes
          the HTTP headers. Thanks to Michael Stapelberg for spotting.

0.2     Fri Jul 24 14:40:48 CEST 2009
        - added note about encoding problems with XML::Atom.
        - added 'headers' field to constructor for additional http headers.
        - added 'username' and 'password' field to constructor,
          for HTTP Basic Auth.
        - added googlemail unread messages example script.
        - added 'If-Modified-Since' header support for a great deal of
          bandwidth savings.

0.1     Fri Jul  3 00:57:01 CEST 2009
        - initial release.

README  view on Meta::CPAN

            seconds and call the callback given by "on_fetch" with the
            result.

        headers => $http_hdrs
            Additional HTTP headers for each GET request can be passed in
            the $http_hdrs hash reference, just like you would pass it to
            the "headers" argument of the "http_get" request of
            AnyEvent::HTTP.

        username => $http_user
        password => $http_pass
            These are the HTTP username and password that will be used for
            Basic HTTP Authentication with the HTTP server when fetching the
            feed. This is mostly sugar for you so you don't have to encode
            them yourself and pass them to the "headers" argument above.

        on_fetch => $cb->($feed_reader, $new_entries, $feed_obj, $error)
            This callback is called if the "interval" parameter is given
            (see above) with the same arguments as the callback given to the
            "fetch" method (see below).

        entry_ages => $hash

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

callback given by C<on_fetch> with the result.

=item headers => $http_hdrs

Additional HTTP headers for each GET request can be passed in the C<$http_hdrs>
hash reference, just like you would pass it to the C<headers> argument of
the C<http_get> request of L<AnyEvent::HTTP>.

=item username => $http_user

=item password => $http_pass

These are the HTTP username and password that will be used for Basic HTTP
Authentication with the HTTP server when fetching the feed. This is mostly
sugar for you so you don't have to encode them yourself and pass them to the
C<headers> argument above.

=item on_fetch => $cb->($feed_reader, $new_entries, $feed_obj, $error)

This callback is called if the C<interval> parameter is given (see above)
with the same arguments as the callback given to the C<fetch> method (see below).

=item entry_ages => $hash

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

sub _get_headers {
   my ($self, %hdrs) = @_;

   my %hdrs = %{$self->{headers} || {}};

   if (defined $self->{last_mod}) {
      $hdrs{'If-Modified-Since'} = $self->{last_mod};
   }

   $hdrs{Authorization} =
     "Basic " . encode_base64 (join ':', $self->{username}, $self->{password}, '')
        if defined $self->{username};

   \%hdrs
}

sub fetch {
   my ($self, $cb) = @_;

   unless (defined $cb) {
      croak "no callback given to fetch!";

samples/gmail_unread_feed  view on Meta::CPAN

use AnyEvent::Feed;
use AnyEvent;

$XML::Atom::ForceUnicode = 1;

my $cv = AnyEvent->condvar;

my $f = AnyEvent::Feed->new (
      url      => 'https://mail.google.com/mail/feed/atom/unread/',
      username => $ARGV[0],
      password => $ARGV[1],
      interval => 60,
      on_fetch => sub {
         my ($fee, $ent, $feed, $er) = @_;

         if (defined $er) {
            warn "ERROR: $er\n";
            $cv->send;
            return;
         }



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