Skip to content

Commit

Permalink
Change UrlDiscovery attempts type from Vec to HashMap (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer authored Aug 8, 2024
1 parent b2c6a80 commit 855484c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions wp_api/src/login/login_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl WpLoginClient {
let attempts = attempts
.into_iter()
.map(|a| match a {
Ok(s) => UrlDiscoveryState::Success(s),
Err(e) => UrlDiscoveryState::Failure(e),
Ok(s) => (s.site_url.url(), UrlDiscoveryState::Success(s)),
Err(e) => (e.site_url(), UrlDiscoveryState::Failure(e)),
})
.collect();
if let Some(s) = successful_attempt {
Expand Down
18 changes: 15 additions & 3 deletions wp_api/src/login/url_discovery.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{collections::HashMap, sync::Arc};

use crate::{
request::{WpNetworkHeaderMap, WpNetworkResponse},
Expand Down Expand Up @@ -55,18 +55,30 @@ pub enum UrlDiscoveryAttemptError {
},
}

impl UrlDiscoveryAttemptError {
pub fn site_url(&self) -> String {
match self {
UrlDiscoveryAttemptError::FailedToParseSiteUrl { site_url, .. } => site_url.clone(),
UrlDiscoveryAttemptError::FetchApiRootUrlFailed { site_url, .. } => site_url.url(),
UrlDiscoveryAttemptError::FetchApiDetailsFailed { site_url, .. } => site_url.url(),
}
}
}

#[derive(Debug, uniffi::Record)]
pub struct UrlDiscoverySuccess {
pub site_url: Arc<ParsedUrl>,
pub api_details: Arc<WpApiDetails>,
pub api_root_url: Arc<ParsedUrl>,
pub attempts: Vec<UrlDiscoveryState>,
pub attempts: HashMap<String, UrlDiscoveryState>,
}

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum UrlDiscoveryError {
#[error("Url discovery failed: {:?}", attempts)]
UrlDiscoveryFailed { attempts: Vec<UrlDiscoveryState> },
UrlDiscoveryFailed {
attempts: HashMap<String, UrlDiscoveryState>,
},
}

#[derive(Debug)]
Expand Down
6 changes: 5 additions & 1 deletion wp_api_integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ impl<T: std::fmt::Debug, E: std::error::Error> AssertResponse for Result<T, E> {
type Item = T;

fn assert_response(self) -> T {
assert!(self.is_ok(), "Request failed with: {}", self.unwrap_err());
assert!(
self.is_ok(),
"Request failed with: {:#?}",
self.unwrap_err()
);
self.unwrap()
}
}

0 comments on commit 855484c

Please sign in to comment.