Skip to content

Allow passing WP.com base url #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions wp_api/src/wp_com/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ pub mod support_bots_endpoint;
#[derive(uniffi::Object)]
pub struct WpComDotOrgApiUrlResolver {
pub base_url: ParsedUrl,
pub site_url: String,
pub site_id: String,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both site id and site url are acceptable. I changed this to be site_id to be consistent with the $site_id in most API docs.

}

#[uniffi::export]
impl WpComDotOrgApiUrlResolver {
#[uniffi::constructor]
pub fn new(site_url: String) -> Self {
pub fn new(base_url: Option<String>, site_id: String) -> Self {
Self {
base_url: wp_com_base_url(),
site_url,
base_url: base_url
.and_then(|url| ParsedUrl::parse(&url).ok())
.unwrap_or_else(wp_com_base_url),
site_id,
}
}
}
Expand All @@ -43,7 +45,7 @@ impl ApiUrlResolver for WpComDotOrgApiUrlResolver {
Arc::new(
self.base_url
.by_extending_and_splitting_by_forward_slash(
vec![namespace, "sites".to_string(), self.site_url.to_string()]
vec![namespace, "sites".to_string(), self.site_id.to_string()]
.into_iter()
.chain(endpoint_segments),
)
Expand Down Expand Up @@ -109,7 +111,7 @@ mod tests {
#[case] endpoint_segments: Vec<String>,
#[case] expected_url: &str,
) {
let resolver = WpComDotOrgApiUrlResolver::new("example.wordpress.com".to_string());
let resolver = WpComDotOrgApiUrlResolver::new(None, "example.wordpress.com".to_string());
assert_eq!(
resolver
.resolve(namespace.to_string(), endpoint_segments)
Expand Down