Changeset 807

Show
Ignore:
Timestamp:
05/24/06 18:48:44
Author:
miyagawa
Message:

Now Plagger::UserAgent? and $plugin->cookie_jar can share cookies data with your browser. No need to set username and password to CustomFeed?::* plugins, etc.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin.pm

    r593 r807  
    55__PACKAGE__->mk_accessors( qw(conf rule rule_hook cache) ); 
    66 
     7use Plagger::Cookies; 
    78use Plagger::Crypt; 
    89use Plagger::Rule; 
     
    114115} 
    115116 
     117sub cookie_jar { 
     118    my $self = shift; 
     119 
     120    my $agent_conf = Plagger->context->conf->{user_agent} || {}; 
     121    if ($agent_conf->{cookies}) { 
     122        return Plagger::Cookies->create($agent_conf->{cookies}); 
     123    } 
     124 
     125    return $self->cache->cookie_jar; 
     126} 
     127 
    1161281; 
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Frepa.pm

    r650 r807  
    2525    my ($self, $context) = @_; 
    2626 
    27     $self->{mech} = WWW::Mechanize->new(cookie_jar => $self->cache->cookie_jar); # enbug??? 
     27    $self->{mech} = WWW::Mechanize->new(cookie_jar => $self->cookie_jar); 
    2828    $self->{mech}->agent_alias( "Windows IE 6" ); 
    2929 
     
    132132    return 0 unless $self->{mech}->success; 
    133133 
     134    open FOO, ">foo"; 
     135    print FOO $self->{mech}->content; 
     136 
    134137    if ($self->{mech}->content =~ /loginside/) { 
    135138        Plagger->context->log(debug => "cookie not found. logging in"); 
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Mixi.pm

    r677 r807  
    5454sub load { 
    5555    my($self, $context) = @_; 
     56 
     57    my $cookie_jar = $self->cookie_jar; 
     58    if (ref($cookie_jar) ne 'HTTP::Cookies') { 
     59        # using foreign cookies = don't have to set email/password. Fake them 
     60        $self->conf->{email}    ||= 'plagger@localhost'; 
     61        $self->conf->{password} ||= 'pl4gg5r'; 
     62    } 
     63 
    5664    $self->{mixi} = WWW::Mixi->new($self->conf->{email}, $self->conf->{password}); 
    57     $self->{mixi}->cookie_jar($self->cache->cookie_jar); 
     65    $self->{mixi}->cookie_jar($cookie_jar); 
    5866 
    5967    my $feed = Plagger::Feed->new; 
     
    7987    if ($response->content =~ /action=login\.pl/) { 
    8088        $context->log(debug => "Cookie not found. Logging in"); 
     89 
     90        if ($self->conf->{email} eq 'plagger@localhost') { 
     91            $context->log(error => 'email/password should be set to login'); 
     92        } 
     93 
    8194        $response = $self->{mixi}->post("http://mixi.jp/login.pl", { 
    8295            next_url => $next_url, 
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Yahoo360JP.pm

    r533 r807  
    3535    my $start = "http://360.yahoo.co.jp/"; 
    3636 
    37     my $mech = WWW::Mechanize->new(cookie_jar => $self->cache->cookie_jar); 
     37    my $mech = WWW::Mechanize->new(cookie_jar => $self->cookie_jar); 
    3838    $mech->agent_alias( 'Windows IE 6' ); 
    3939    $mech->get($start); 
  • trunk/plagger/lib/Plagger/Plugin/Notify/Campfire.pm

    r447 r807  
    5151    my $plugin = shift; 
    5252 
    53     my $mech = WWW::Mechanize->new(cookie_jar => $plugin->cache->cookie_jar); 
     53    my $mech = WWW::Mechanize->new(cookie_jar => $plugin->cookie_jar); 
    5454    $mech->agent_alias("Windows IE 6"); 
    5555 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/LivedoorReader.pm

    r794 r807  
    2525sub init_reader { 
    2626    my $self = shift; 
    27     $self->{mech} = WWW::Mechanize->new(cookie_jar => $self->cache->cookie_jar); 
     27    $self->{mech} = WWW::Mechanize->new(cookie_jar => $self->cookie_jar); 
    2828 
    2929    unless (defined($self->conf->{username}) && defined($self->conf->{password})) { 
  • trunk/plagger/lib/Plagger/UserAgent.pm

    r572 r807  
    33use base qw( LWP::UserAgent ); 
    44 
     5use Plagger::Cookies; 
    56use URI::Fetch 0.06; 
    67 
     
    1011    $self->agent("Plagger/$Plagger::VERSION (http://plagger.bulknews.net/)"); 
    1112    $self->timeout(15); # xxx to be config 
     13 
     14    my $conf = Plagger->context->conf->{user_agent}; 
     15    if ($conf->{cookies}) { 
     16        $self->cookie_jar( Plagger::Cookies->create($conf->{cookies}) ); 
     17    } 
     18 
    1219    $self; 
    1320}