Changeset 1559
- Timestamp:
- 08/21/06 15:01:01
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/hackathon-summary/plagger/lib/Plagger/Plugin/Summary/HatenaBookmark.pm
r1556 r1559 5 5 use Plagger::UserAgent; 6 6 use URI; 7 use XML::LibXML;8 7 9 8 sub register { … … 18 17 my($self, $context, $args) = @_; 19 18 20 my $uri = URI->new("http://b.hatena.ne.jp/atomfeed"); 21 $uri->query_form(url => $args->{entry}->permalink); 19 my $permalink = $args->{entry}->permalink; 20 $permalink =~ s/\#/%23/; 21 my $uri = "http://b.hatena.ne.jp/entry/rss/$permalink"; 22 22 23 23 my $agent = Plagger::UserAgent->new; 24 my $res = $agent->fetch($uri); 25 if ($res->is_error) { 26 $context->log(warn => "Fetch $uri failed: ", $res->status); 24 my $summary; 25 eval { 26 my $feed = $agent->fetch_parse($uri); 27 $summary = $feed->tagline; 28 }; 29 30 if ($@) { 31 $context->log(warn => "Fetch $uri failed: $@"); 27 32 return; 28 33 } 29 34 30 my $doc = XML::LibXML->new->parse_string($res->content); 31 my($node) = $doc->findnodes("/*[local-name()='entry']/*[local-name()='summary']"); 32 33 return $node->textContent if $node && $node->textContent; 34 return; 35 return $summary; 35 36 } 36 37 … … 49 50 50 51 This plugin calls Hatena Bookmark Feed API (atomfeed) to get summary 51 from a certain web page. Since Hatena Bookmark I<atomfeed> endpoint 52 requires either Cookie or WSSE based authentication, you need to share 53 cookies using L<Plagger::Cookies>. 54 55 =head1 TODO 56 57 Make I<UserAgent::AuthenRequest::WSSE> to transparently do WSSE authentication. 52 from a certain web page. 58 53 59 54 =head1 AUTHOR … … 63 58 =head1 SEE ALSO 64 59 65 L<Plagger> , L<Plagger::Cookies>60 L<Plagger> 66 61 67 62 =cut branches/hackathon-summary/plagger/t/plugins/Summary-HatenaBookmark/base.t
r1556 r1559 4 4 test_requires_network; 5 5 test_plugin_deps; 6 test_requires('HTTP::Cookies::w3m');7 8 my $cookie = "$ENV{HOME}/.w3m/cookie";9 unless (-e $cookie and slurp_file($cookie) =~ /\.hatena\.ne\.jp/) {10 plan skip_all => "This plugin requires w3m cookies";11 }12 6 13 7 plan 'no_plan'; … … 16 10 __END__ 17 11 18 === Loading Summary::HatenaBookmark19 --- input config20 plugins:21 - module: Summary::HatenaBookmark22 --- expected23 ok 1, $block->name;24 25 12 === use Hatebu Atom feed to get summary 26 13 --- input config 27 global:28 user_agent:29 cookies: $ENV{HOME}/.w3m/cookie30 14 plugins: 31 15 - module: CustomFeed::Debug … … 42 26 === Something bogus 43 27 --- input config 44 global:45 user_agent:46 cookies: $ENV{HOME}/.w3m/cookie47 28 plugins: 48 29 - module: CustomFeed::Debug
