Changeset 5817
- Timestamp:
- 01/30/08 00:51:19 (5 years ago)
- Location:
- lang/perl/WWW-HatenaDiary/trunk
- Files:
-
- 4 modified
-
. (modified) (1 prop)
-
Makefile.PL (modified) (1 diff)
-
lib/WWW/HatenaDiary.pm (modified) (13 diffs)
-
t/97_podspell.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/WWW-HatenaDiary/trunk
-
lang/perl/WWW-HatenaDiary/trunk/Makefile.PL
r4595 r5817 9 9 JSON::Syck 10 10 /); 11 requires WWW::HatenaLogin => 0.02; 11 12 12 13 build_requires 'Test::More'; -
lang/perl/WWW-HatenaDiary/trunk/lib/WWW/HatenaDiary.pm
r4606 r5817 7 7 use WWW::Mechanize; 8 8 use JSON::Syck 'Load'; 9 use WWW::HatenaLogin; 9 10 10 11 our $VERSION = '0.01'; 11 12 my $login_uri = 'https://www.hatena.ne.jp/login';13 12 14 13 sub new { … … 19 18 base => $base, 20 19 group => $args->{group}, 21 username => $args->{username}, 22 password => $args->{password}, 23 mech => WWW::Mechanize->new( 24 $args->{mech_opt} && ref $args->{mech_opt} ? %{$args->{mech_opt}} : () 25 ), 20 login => $args->{login} || WWW::HatenaLogin->new({ nologin => 1, %{ $args } }), 26 21 verbose => $args->{verbose}, 27 22 }, $class; … … 31 26 process '//td[@class="username"]/a', 'username' => 'TEXT'; 32 27 result 'username'; 33 }->scrape($self->{ mech}->content, URI->new($login_uri));34 $self->{ username} = $username if !$self->{username};35 $self->{diary} = "$self->{base}$self->{username}/";28 }->scrape($self->{login}->mech->content, $self->{login}->login_uri); 29 $self->{login}->username($username) if !$self->{login}->username; 30 $self->{diary} = $self->{base}.$self->{login}->username.'/'; 36 31 } 37 32 … … 41 36 sub is_loggedin { 42 37 my $self = shift; 43 my $link; 44 45 $self->{mech}->get($login_uri); 46 ($link) = map { $_->url } $self->{mech}->find_link(tag => 'meta'); 47 48 !!$link; 38 $self->{login}->is_loggedin; 49 39 } 50 40 … … 52 42 my ($self, $args) = @_; 53 43 54 if ($args) { 55 if ($args->{username}) { 56 $self->{username} = $args->{username}; 57 } 58 if ($args->{password}) { 59 $self->{password} = $args->{password}; 60 } 61 } 62 63 $self->{diary} = "$self->{base}$self->{username}/"; 64 $self->{mech}->get($login_uri); 65 $self->{mech}->submit_form( 66 fields => { 67 name => $self->{username}, 68 password => $self->{password}, 69 } 70 ); 44 $self->{login}->login($args); 45 $self->{diary} = $self->{base}.$self->{login}->username.'/'; 71 46 72 47 !!($self->{rkm} = $self->get_rkm) || … … 78 53 my $rkm; 79 54 80 $self->{ mech}->get("$self->{diary}?mode=json");55 $self->{login}->mech->get("$self->{diary}?mode=json"); 81 56 eval { 82 $rkm = Load($self->{ mech}->content)->{rkm};57 $rkm = Load($self->{login}->mech->content)->{rkm}; 83 58 }; 84 59 … … 101 76 if !$args->{uri}; 102 77 103 $self->{ mech}->get("$args->{uri}?mode=json");104 Load($self->{ mech}->content);78 $self->{login}->mech->get("$args->{uri}?mode=json"); 79 Load($self->{login}->mech->content); 105 80 } 106 81 … … 115 90 116 91 my $uri = "$self->{diary}edit?date=$y$m$d"; 117 $self->{ mech}->get($uri);118 my $form = $self->{ mech}->form_name('edit');92 $self->{login}->mech->get($uri); 93 my $form = $self->{login}->mech->form_name('edit'); 119 94 120 95 { … … 147 122 148 123 my $uri = "$self->{diary}edit?date=$y$m$d"; 149 $self->{ mech}->get($uri);150 $self->{ mech}->submit_form(124 $self->{login}->mech->get($uri); 125 $self->{login}->mech->submit_form( 151 126 form_name => 'edit', 152 127 fields => { … … 163 138 } 164 139 165 $self->{ mech}->success;140 $self->{login}->mech->success; 166 141 } 167 142 … … 206 181 my $uri = "$self->{diary}edit?date=$y$m$d"; 207 182 208 $self->{ mech}->get($uri);183 $self->{login}->mech->get($uri); 209 184 210 185 if ($self->{group}) { 211 for my $form ($self->{ mech}->forms) {186 for my $form ($self->{login}->mech->forms) { 212 187 if ($form->action =~ /deletediary$/) { 213 $self->{ mech}->request($form->click);188 $self->{login}->mech->request($form->click); 214 189 } 215 190 } 216 191 } 217 192 else { 218 $self->{ mech}->submit_form(form_number => 2);193 $self->{login}->mech->submit_form(form_number => 2); 219 194 } 220 195 } … … 223 198 } 224 199 225 $self->{ mech}->success;200 $self->{login}->mech->success; 226 201 } 227 202 … … 230 205 my $uri = $args->{uri} || $self->{diary}; 231 206 232 $self->{ mech}->post($uri, {207 $self->{login}->mech->post($uri, { 233 208 rkm => $self->{rkm}, 234 209 %$args, -
lang/perl/WWW-HatenaDiary/trunk/t/97_podspell.t
r4595 r5817 15 15 cpan 16 16 gmail 17 AtomPub
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)