Changeset 336

Show
Ignore:
Timestamp:
08/18/06 11:24:05 (2 years ago)
Author:
ogawa
Message:

- Now can check properly whether ClientLogin? is succeeded or not.
- Drop "auth_token" if users change the service name, because auth_tokens are not compatible between different services.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • XML-Atom-GDataClient/trunk/lib/XML/Atom/GDataClient.pm

    r334 r336  
    1212sub service { 
    1313    my $client = shift; 
    14     $client->{service} = shift if @_; 
     14    if (@_) { 
     15        $client->{service} = shift; 
     16        delete $client->{auth_token}; # drop auth_token if changing "service" 
     17    } 
    1518    $client->{service}; 
     19} 
     20 
     21sub login { 
     22    my $client = shift; 
     23    return $client->{auth_token} if $client->{auth_token}; 
     24    my $r = $client->{ua}->post($GOOGLE_AUTH_URL, { 
     25        Email => $client->username, 
     26        Passwd => $client->password, 
     27        source => __PACKAGE__ . '-' . $VERSION, 
     28        service => $client->service, 
     29    }); 
     30    return $client->error("Error on GData ClientLogin: " . $r->status_line) 
     31        unless $r->code == 200; 
     32    my($token) = $r->content =~ m/Auth=(.+)/; 
     33    $client->{auth_token} = $token; 
     34} 
     35 
     36sub make_request { 
     37    my $client = shift; 
     38    my($req) = @_; 
     39    $client->login or return; # do Google ClientLogin 
     40    $client->munge_request($req); 
     41    my $res = $client->{ua}->request($req); 
     42    $client->munge_response($res); 
     43    $client->{response} = $res; 
     44    $res; 
    1645} 
    1746 
     
    1948    my $client = shift; 
    2049    my($req) = @_; 
    21     unless ($client->{gdata_auth_token}) { 
    22         my $r = $client->{ua}->post($GOOGLE_AUTH_URL, { 
    23             Email => $client->username, 
    24             Passwd => $client->password, 
    25             source => __PACKAGE__ . '-' . $VERSION, 
    26             service => $client->service, 
    27         }); 
    28         return $client->error("Error on GData ClientLogin: " . $r->status_line) 
    29             unless $r->code == 200; 
    30         my($token) = $r->content =~ m/Auth=(.+)/; 
    31         $client->{gdata_auth_token} = $token; 
    32     } 
    33     $req->header('Authorization', 'GoogleLogin auth=' . $client->{gdata_auth_token}); 
     50    $req->header('Authorization', 'GoogleLogin auth=' . $client->{auth_token}); 
    3451    $req->content_type('application/atom+xml'); 
    3552} 
     53 
     54sub munge_responce { } 
    3655 
    37561;