Traewelling: Use API v1 for login/logout. v1 checkin does not work yet.
This commit is contained in:
parent
fddd5c55be
commit
bde6346401
1 changed files with 14 additions and 14 deletions
|
@ -165,20 +165,20 @@ sub get_user_p {
|
||||||
};
|
};
|
||||||
my $promise = Mojo::Promise->new;
|
my $promise = Mojo::Promise->new;
|
||||||
|
|
||||||
$ua->get_p( "https://traewelling.de/api/v0/getuser" => $header )->then(
|
$ua->get_p( "https://traewelling.de/api/v1/auth/user" => $header )->then(
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
if ( my $err = $tx->error ) {
|
||||||
my $err_msg = "v0/getuser: HTTP $err->{code} $err->{message}";
|
my $err_msg = "v1/auth/user: HTTP $err->{code} $err->{message}";
|
||||||
$promise->reject($err_msg);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $user_data = $tx->result->json;
|
my $user_data = $tx->result->json->{data};
|
||||||
$self->{model}->set_user(
|
$self->{model}->set_user(
|
||||||
uid => $uid,
|
uid => $uid,
|
||||||
trwl_id => $user_data->{id},
|
trwl_id => $user_data->{id},
|
||||||
screen_name => $user_data->{name},
|
screen_name => $user_data->{displayName},
|
||||||
user_name => $user_data->{username},
|
user_name => $user_data->{username},
|
||||||
);
|
);
|
||||||
$promise->resolve;
|
$promise->resolve;
|
||||||
|
@ -188,7 +188,7 @@ sub get_user_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
$promise->reject("v0/getuser: $err");
|
$promise->reject("v1/auth/user: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->wait;
|
)->wait;
|
||||||
|
@ -206,7 +206,7 @@ sub login_p {
|
||||||
my $ua = $self->{user_agent}->request_timeout(20);
|
my $ua = $self->{user_agent}->request_timeout(20);
|
||||||
|
|
||||||
my $request = {
|
my $request = {
|
||||||
email => $email,
|
login => $email,
|
||||||
password => $password,
|
password => $password,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -214,19 +214,19 @@ sub login_p {
|
||||||
my $token;
|
my $token;
|
||||||
|
|
||||||
$ua->post_p(
|
$ua->post_p(
|
||||||
"https://traewelling.de/api/v0/auth/login" => $self->{header},
|
"https://traewelling.de/api/v1/auth/login" => $self->{header},
|
||||||
json => $request
|
json => $request
|
||||||
)->then(
|
)->then(
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
if ( my $err = $tx->error ) {
|
||||||
my $err_msg
|
my $err_msg
|
||||||
= "v0/auth/login: HTTP $err->{code} $err->{message}";
|
= "v1/auth/login: HTTP $err->{code} $err->{message}";
|
||||||
$promise->reject($err_msg);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $res = $tx->result->json;
|
my $res = $tx->result->json->{data};
|
||||||
$token = $res->{token};
|
$token = $res->{token};
|
||||||
my $expiry_dt = $self->parse_datetime( $res->{expires_at} );
|
my $expiry_dt = $self->parse_datetime( $res->{expires_at} );
|
||||||
|
|
||||||
|
@ -259,13 +259,13 @@ sub login_p {
|
||||||
token => $token
|
token => $token
|
||||||
)->finally(
|
)->finally(
|
||||||
sub {
|
sub {
|
||||||
$promise->reject("v0/auth/login: $err");
|
$promise->reject("v1/auth/login: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$promise->reject("v0/auth/login: $err");
|
$promise->reject("v1/auth/login: $err");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -294,13 +294,13 @@ sub logout_p {
|
||||||
my $promise = Mojo::Promise->new;
|
my $promise = Mojo::Promise->new;
|
||||||
|
|
||||||
$ua->post_p(
|
$ua->post_p(
|
||||||
"https://traewelling.de/api/v0/auth/logout" => $header => json =>
|
"https://traewelling.de/api/v1/auth/logout" => $header => json =>
|
||||||
$request )->then(
|
$request )->then(
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( my $err = $tx->error ) {
|
if ( my $err = $tx->error ) {
|
||||||
my $err_msg
|
my $err_msg
|
||||||
= "v0/auth/logout: HTTP $err->{code} $err->{message}";
|
= "v1/auth/logout: HTTP $err->{code} $err->{message}";
|
||||||
$promise->reject($err_msg);
|
$promise->reject($err_msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ sub logout_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
$promise->reject("v0/auth/logout: $err");
|
$promise->reject("v1/auth/logout: $err");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->wait;
|
)->wait;
|
||||||
|
|
Loading…
Reference in a new issue