File tree 2 files changed +13
-7
lines changed
2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ impl MonlibPull {
43
43
url. push_str ( & run) ;
44
44
url. push_str ( "/raw" ) ;
45
45
46
- let response = MonlibRequest . request ( url. as_str ( ) ) . await ?;
46
+ let response = MonlibRequest :: new ( ) . pull ( url. as_str ( ) ) . await ?;
47
47
if response. status ( ) . is_success ( ) {
48
48
let result = String :: new ( ) ;
49
49
let mut is_json = true ;
Original file line number Diff line number Diff line change @@ -2,26 +2,32 @@ extern crate reqwest;
2
2
3
3
use reqwest:: {
4
4
Error ,
5
- Client ,
6
- Response
5
+ Client ,
6
+ Response ,
7
7
} ;
8
8
9
9
use crate :: {
10
10
configs:: env:: Env ,
11
11
consts:: addons:: Addons ,
12
12
} ;
13
13
14
- pub struct MonlibRequest ;
14
+ pub struct MonlibRequest {
15
+ api_key : String
16
+ }
15
17
16
18
impl MonlibRequest {
17
19
18
- pub async fn request ( & self , url : & str ) -> Result < Response , Error > {
19
- let api_key = Env . env_var ( Addons :: MONLIB_API_ENV ) ;
20
+ pub fn new ( ) -> Self {
21
+ let api_key = Env . env_var ( Addons :: MONLIB_API_ENV ) ;
22
+ Self { api_key }
23
+ }
24
+
25
+ pub async fn pull ( & self , url : & str ) -> Result < Response , Error > {
20
26
let client = Client :: builder ( ) . danger_accept_invalid_certs ( true ) . build ( ) . unwrap ( ) ;
21
27
22
28
let response = client
23
29
. get ( url)
24
- . header ( "API-Key" , api_key)
30
+ . header ( "API-Key" , & self . api_key )
25
31
. send ( )
26
32
. await ?;
27
33
You can’t perform that action at this time.
0 commit comments