This repository was archived by the owner on Jul 6, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " proton-api-rs"
3
3
authors = [" Leander Beernaert <lbb-dev@pm.me>" ]
4
- version = " 0.3 .0"
4
+ version = " 0.4 .0"
5
5
edition = " 2021"
6
6
license = " AGPL-3.0-only"
7
7
description = " Unofficial implemention of proton REST API in rust"
Original file line number Diff line number Diff line change @@ -7,12 +7,11 @@ async fn main() {
7
7
let user_password = std:: env:: var ( "PAPI_USER_PASSWORD" ) . unwrap ( ) ;
8
8
let app_version = std:: env:: var ( "PAPI_APP_VERSION" ) . unwrap ( ) ;
9
9
10
- let client = match ClientBuilder :: new ( )
11
- . app_version ( & app_version)
12
- . login ( & user_email, & user_password)
13
- . await
14
- . unwrap ( )
15
- {
10
+ let builder = ClientBuilder :: new ( ) . app_version ( & app_version) ;
11
+
12
+ builder. ping ( ) . await . unwrap ( ) ;
13
+
14
+ let client = match builder. login ( & user_email, & user_password) . await . unwrap ( ) {
16
15
ClientLoginState :: Authenticated ( c) => c,
17
16
18
17
ClientLoginState :: AwaitingTotp ( mut t) => {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use crate::client::types::{
5
5
use crate :: client:: { HttpClientBuilder , X_PM_UID_HEADER } ;
6
6
use crate :: domain:: { SecretString , UserUid } ;
7
7
use crate :: { impl_error_conversion, Client , RequestError } ;
8
+ use anyhow:: anyhow;
8
9
use go_srp:: SRPAuth ;
9
10
use secrecy:: ExposeSecret ;
10
11
use std:: time:: Duration ;
@@ -214,6 +215,17 @@ impl ClientBuilder {
214
215
215
216
Ok ( Client { http_client, user } )
216
217
}
218
+
219
+ /// Check connectivity
220
+ pub async fn ping ( & self ) -> Result < ( ) , RequestError > {
221
+ let http_client = self . 0 . clone ( ) . build ( ) ?;
222
+ let r = http_client. get ( "tests/ping" ) . execute ( ) . await ?;
223
+ if r. status_code ( ) != 200 {
224
+ return Err ( RequestError :: Other ( anyhow ! ( "Service not pingable" ) ) ) ;
225
+ }
226
+
227
+ Ok ( ( ) )
228
+ }
217
229
}
218
230
219
231
#[ derive( Debug ) ]
You can’t perform that action at this time.
0 commit comments