1
1
use crate :: {
2
2
parsed_url:: ParsedUrl ,
3
3
request:: endpoint:: { ApiUrlResolver , AsNamespace , WpNamespace } ,
4
+ wp_com:: WpComBaseUrl ,
4
5
} ;
5
6
use std:: sync:: Arc ;
6
7
use strum:: IntoEnumIterator ;
7
- use url:: Url ;
8
8
9
9
pub mod jetpack_connection_endpoint;
10
10
pub mod oauth2;
@@ -14,16 +14,16 @@ pub mod support_bots_endpoint;
14
14
#[ derive( uniffi:: Object ) ]
15
15
pub struct WpComDotOrgApiUrlResolver {
16
16
pub base_url : ParsedUrl ,
17
- pub site_url : String ,
17
+ pub site_id : String ,
18
18
}
19
19
20
20
#[ uniffi:: export]
21
21
impl WpComDotOrgApiUrlResolver {
22
22
#[ uniffi:: constructor]
23
- pub fn new ( site_url : String ) -> Self {
23
+ pub fn new ( site_id : String , base_url : WpComBaseUrl ) -> Self {
24
24
Self {
25
- base_url : wp_com_base_url ( ) ,
26
- site_url ,
25
+ base_url : base_url . parsed_url ( ) ,
26
+ site_id ,
27
27
}
28
28
}
29
29
}
@@ -43,7 +43,7 @@ impl ApiUrlResolver for WpComDotOrgApiUrlResolver {
43
43
Arc :: new (
44
44
self . base_url
45
45
. by_extending_and_splitting_by_forward_slash (
46
- vec ! [ namespace, "sites" . to_string( ) , self . site_url . to_string( ) ]
46
+ vec ! [ namespace, "sites" . to_string( ) , self . site_id . to_string( ) ]
47
47
. into_iter ( )
48
48
. chain ( endpoint_segments) ,
49
49
)
@@ -60,7 +60,7 @@ pub(crate) struct WpComApiClientInternalUrlResolver {
60
60
impl WpComApiClientInternalUrlResolver {
61
61
fn new ( ) -> Self {
62
62
Self {
63
- base_url : wp_com_base_url ( ) ,
63
+ base_url : WpComBaseUrl :: Production . parsed_url ( ) ,
64
64
}
65
65
}
66
66
}
@@ -91,12 +91,6 @@ impl ApiUrlResolver for WpComApiClientInternalUrlResolver {
91
91
}
92
92
}
93
93
94
- fn wp_com_base_url ( ) -> ParsedUrl {
95
- Url :: parse ( "https://public-api.wordpress.com" )
96
- . expect ( "This is a valid URL" )
97
- . into ( )
98
- }
99
-
100
94
#[ cfg( test) ]
101
95
mod tests {
102
96
use super :: * ;
@@ -109,7 +103,10 @@ mod tests {
109
103
#[ case] endpoint_segments : Vec < String > ,
110
104
#[ case] expected_url : & str ,
111
105
) {
112
- let resolver = WpComDotOrgApiUrlResolver :: new ( "example.wordpress.com" . to_string ( ) ) ;
106
+ let resolver = WpComDotOrgApiUrlResolver :: new (
107
+ "example.wordpress.com" . to_string ( ) ,
108
+ WpComBaseUrl :: Production ,
109
+ ) ;
113
110
assert_eq ! (
114
111
resolver
115
112
. resolve( namespace. to_string( ) , endpoint_segments)
0 commit comments