/[Grep]/lib/Grep/Action/AddFeed.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/Grep/Action/AddFeed.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations)
Sun Feb 18 15:07:03 2007 UTC (17 years, 3 months ago) by dpavlin
File size: 1754 byte(s)
Bookmarklet is now designed to work on html results page (to capture cookies so that
Grep will later be able to fetch feeds with user credentials creating single sign-on
scenario :-), and it will automatically (using new requirement Feed::Find) find feed
on that page.

For that to work, new action AddFeed was added.
1 use strict;
2 use warnings;
3
4 =head1 NAME
5
6 Grep::Action::AddFeed
7
8 =cut
9
10 package Grep::Action::AddFeed;
11 use base qw/Grep::Action::CreateFeed/;
12
13 use Feed::Find;
14 use LWP::UserAgent;
15 use Data::Dump qw/dump/;
16
17 =head2 canonicalize_uri
18
19 Replace C<grep>' with C<%s> in URI arguments
20
21 =cut
22
23 sub canonicalize_uri {
24 my $self = shift;
25 my $value = shift;
26 warn "uri: $value";
27 if ($value =~ s/=grep/=%s/) {
28 $self->canonicalization_note( uri => 'Replaced grep with %s' );
29 }
30 return $value;
31 }
32
33 =head2 take_action
34
35 =cut
36
37 sub take_action {
38 my $self = shift;
39
40 my @ARGS = @_;
41
42 # Custom action code
43
44 my $ua = LWP::UserAgent->new;
45
46 my $cookie = $self->argument_value('cookie');
47 if ($cookie =~ s/{x!(26|3b)}/chr(hex($1))/gei) {
48 $self->argument_value('cookie', $cookie);
49 }
50
51 Jifty->log->debug("using cookie: $cookie");
52 $ua->default_header( 'Cookie' => $cookie );
53
54 my $search_moniker = 'grep';
55
56 my $uri = $self->argument_value('uri');
57 $uri =~ s/{x!(26|3b)}/chr(hex($1))/gei;
58
59 Jifty->log->debug("trying to find feed on $uri");
60
61 my @feeds = Feed::Find->find( sprintf( $uri, $search_moniker ), $ua );
62
63 if (@feeds) {
64
65 Jifty->log->info("found possible feeds: ", dump( @feeds ));
66
67 @feeds = map {
68 my $t = $_;
69 $t =~ s/=$search_moniker/=%s/;
70 $t
71 } grep(/=$search_moniker/,@feeds);
72
73 $self->result->message('Found ' . @feeds . ' feeds, using first one. ' . join(" ", @feeds) );
74
75 $uri = shift @feeds;
76
77 $self->argument_value('uri', $uri);
78
79 Jifty->log->debug("calling parent take_action with new uri $uri");
80
81 $self->SUPER::take_action( @ARGS );
82
83 return 1;
84
85 } else {
86
87 my $r = $ua->get( sprintf( $uri, $search_moniker ) );
88 warn "no feeds in ", $r->content;
89
90 $self->result->error('No feeds found on supplied URI');
91 return 0;
92 }
93
94 }
95
96 1;
97

  ViewVC Help
Powered by ViewVC 1.1.26