--- lib/Grep/Action/Fetch.pm 2007/02/17 23:32:33 9 +++ lib/Grep/Action/Fetch.pm 2007/02/18 20:45:59 25 @@ -11,6 +11,7 @@ use base qw/Grep::Action Jifty::Action/; use XML::Feed; +use LWP::UserAgent; use Data::Dump qw/dump/; @@ -37,6 +38,12 @@ }]; }; + param item_fragment => + label is 'Show', + render as 'select', + valid are qw/result result_short/, + available are qw/result result_short/; + }; =head2 take_action @@ -65,16 +72,25 @@ my $uri = $feed->uri; if ($uri =~ m/%s/) { - $uri = sprintf( $uri, $self->argument_value('q') ); + $uri = $feed->search_uri( $self->argument_value('q') ); Jifty->log->info("Searching ", $feed->title, " at $uri"); } else { Jifty->log->info("Fetching ", $feed->title, " at $uri"); } - my $xml_feed = XML::Feed->parse( URI->new($uri) ) - or die XML::Feed->errstr; + my $ua = LWP::UserAgent->new; + $ua->default_header( 'Cookie' => $feed->cookie ); + my $r = $ua->get( $uri ); + die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success ); + + my $content = $r->content; + + die "No content returned from $uri" unless length( $content ) > 1; - warn "fetching ", $xml_feed->title, "\n"; + my $xml_feed = XML::Feed->parse( \$content ) + or die $feed->title, " returned ", XML::Feed->errstr, " for $uri\n"; + + warn "getting entries from ", $xml_feed->title, "\n"; my @items; @@ -93,13 +109,16 @@ modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef, ); - die "can't create item from entry ", dump( $entry ) unless ( $i->id ); + if ( $i->id ) { + push @items, $i; - push @items, $i; + # Grep::Event::Result->new( $i )->publish; -# Grep::Event::Result->new( $i )->publish; + Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) ); + } else { + warn "can't create item from entry ", dump( $entry ) unless ( $i->id ); + } - Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) ); } if ( @items ) { @@ -113,12 +132,9 @@ } else { - $self->result->message( 'No results found' ); - - # with default sticky_on_failure, this will keep form data - $self->result->failure( 1 ); - + $self->result->error( 'No results found' ); return 0; + } }