11use crate :: {
22 parsed_url:: ParsedUrl ,
33 request:: endpoint:: { ApiUrlResolver , AsNamespace , WpNamespace } ,
4+ wp_com:: WpComBaseUrl ,
45} ;
56use std:: sync:: Arc ;
67use strum:: IntoEnumIterator ;
7- use url:: Url ;
88
99pub mod jetpack_connection_endpoint;
1010pub mod oauth2;
@@ -14,16 +14,16 @@ pub mod support_bots_endpoint;
1414#[ derive( uniffi:: Object ) ]
1515pub struct WpComDotOrgApiUrlResolver {
1616 pub base_url : ParsedUrl ,
17- pub site_url : String ,
17+ pub site_id : String ,
1818}
1919
2020#[ uniffi:: export]
2121impl WpComDotOrgApiUrlResolver {
2222 #[ uniffi:: constructor]
23- pub fn new ( site_url : String ) -> Self {
23+ pub fn new ( site_id : String , base_url : WpComBaseUrl ) -> Self {
2424 Self {
25- base_url : wp_com_base_url ( ) ,
26- site_url ,
25+ base_url : base_url . parsed_url ( ) ,
26+ site_id ,
2727 }
2828 }
2929}
@@ -43,7 +43,7 @@ impl ApiUrlResolver for WpComDotOrgApiUrlResolver {
4343 Arc :: new (
4444 self . base_url
4545 . 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( ) ]
4747 . into_iter ( )
4848 . chain ( endpoint_segments) ,
4949 )
@@ -60,7 +60,7 @@ pub(crate) struct WpComApiClientInternalUrlResolver {
6060impl WpComApiClientInternalUrlResolver {
6161 fn new ( ) -> Self {
6262 Self {
63- base_url : wp_com_base_url ( ) ,
63+ base_url : WpComBaseUrl :: Production . parsed_url ( ) ,
6464 }
6565 }
6666}
@@ -91,12 +91,6 @@ impl ApiUrlResolver for WpComApiClientInternalUrlResolver {
9191 }
9292}
9393
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-
10094#[ cfg( test) ]
10195mod tests {
10296 use super :: * ;
@@ -109,7 +103,10 @@ mod tests {
109103 #[ case] endpoint_segments : Vec < String > ,
110104 #[ case] expected_url : & str ,
111105 ) {
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+ ) ;
113110 assert_eq ! (
114111 resolver
115112 . resolve( namespace. to_string( ) , endpoint_segments)
0 commit comments