Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wp_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ name = "wp_api"
[dependencies]
base64 = { workspace = true }
http = { workspace = true }
indoc = "2.0"
url = "2.5"
parse_link_header = "0.3"
serde = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions wp_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod unit_test_common;

const CONTENT_TYPE_JSON: &str = "application/json";

#[derive(uniffi::Object)]
#[derive(Debug, uniffi::Object)]
pub struct WPApiHelper {
api_endpoint: ApiEndpoint,
site_url: Url,
Expand Down Expand Up @@ -361,7 +361,7 @@ impl WPAuthentication {
}
}

#[derive(uniffi::Enum)]
#[derive(Debug, uniffi::Enum)]
pub enum RequestMethod {
GET,
POST,
Expand Down
2 changes: 1 addition & 1 deletion wp_api/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ add_uniffi_exported_parser!(parse_create_plugin_response, PluginWithEditContext)
add_uniffi_exported_parser!(parse_update_plugin_response, PluginWithEditContext);
add_uniffi_exported_parser!(parse_delete_plugin_response, PluginDeleteResponse);

#[derive(Default, Debug, uniffi::Record)]
#[derive(Debug, Default, uniffi::Record)]
pub struct PluginListParams {
/// Limit results to those matching a string.
pub search: Option<String>,
Expand Down
59 changes: 57 additions & 2 deletions wp_api/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Debug};

use url::Url;

use crate::RequestMethod;

pub mod endpoint;

// Has custom `Debug` trait implementation
#[derive(uniffi::Record)]
pub struct WPNetworkRequest {
pub method: RequestMethod,
Expand All @@ -19,6 +20,34 @@ pub struct WPNetworkRequest {
pub body: Option<Vec<u8>>,
}

impl WPNetworkRequest {
pub fn body_as_string(&self) -> Option<String> {
self.body.as_ref().map(|b| body_as_string(b))
}
}

impl Debug for WPNetworkRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut s = format!(
indoc::indoc! {"
WPNetworkRequest {{
method: '{:?}',
url: '{}',
header_map: '{:?}',
body: '{:?}'
}}
"},
self.method,
self.url,
self.header_map,
self.body_as_string()
);
s.pop(); // Remove the new line at the end
write!(f, "{}", s)
}
}

// Has custom `Debug` trait implementation
#[derive(uniffi::Record)]
pub struct WPNetworkResponse {
pub body: Vec<u8>,
Expand All @@ -45,7 +74,33 @@ impl WPNetworkResponse {
}
}
}

None
}

pub fn body_as_string(&self) -> String {
body_as_string(&self.body)
}
}

impl Debug for WPNetworkResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut s = format!(
indoc::indoc! {"
WPNetworkResponse {{
status_code: '{}',
header_map: '{:?}',
body: '{}'
}}
"},
self.status_code,
self.header_map,
self.body_as_string()
);
s.pop(); // Remove the new line at the end
write!(f, "{}", s)
}
}

fn body_as_string(body: &[u8]) -> String {
String::from_utf8_lossy(body).to_string()
}
1 change: 1 addition & 0 deletions wp_api/src/request/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl ApiBaseUrl {
}
}

#[derive(Debug)]
pub struct ApiEndpoint {
pub base_url: ApiBaseUrl,
pub users: UsersEndpoint,
Expand Down
1 change: 1 addition & 0 deletions wp_api/src/request/endpoint/plugins_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{plugins::PluginListParams, PluginSlug, SparsePluginField, WPContext}

use super::{ApiBaseUrl, UrlExtension};

#[derive(Debug)]
pub struct PluginsEndpoint {
api_base_url: ApiBaseUrl,
}
Expand Down
1 change: 1 addition & 0 deletions wp_api/src/request/endpoint/users_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{SparseUserField, UserDeleteParams, UserId, UserListParams, WPContext

use super::{ApiBaseUrl, UrlExtension};

#[derive(Debug)]
pub struct UsersEndpoint {
api_base_url: ApiBaseUrl,
}
Expand Down
6 changes: 3 additions & 3 deletions wp_api/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Default for WPApiParamUsersWho {
}
}

#[derive(Default, Debug, uniffi::Record)]
#[derive(Debug, Default, uniffi::Record)]
pub struct UserListParams {
/// Current page of the collection.
/// Default: `1`
Expand Down Expand Up @@ -184,7 +184,7 @@ impl UserListParams {
}
}

#[derive(Serialize, Debug, uniffi::Record)]
#[derive(Debug, Serialize, uniffi::Record)]
pub struct UserCreateParams {
/// Login name for the user.
pub username: String,
Expand Down Expand Up @@ -254,7 +254,7 @@ impl UserCreateParams {
}
}

#[derive(Default, Serialize, uniffi::Record)]
#[derive(Debug, Default, Serialize, uniffi::Record)]
pub struct UserUpdateParams {
/// Display name for the user.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 2 additions & 0 deletions wp_api/tests/integration_test_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl<T: std::fmt::Debug> AssertWpError<T> for Result<T, WPApiError> {
}
}

#[derive(Debug)]
pub struct TestCredentials {
pub site_url: String,
pub admin_username: String,
Expand Down Expand Up @@ -177,6 +178,7 @@ where
.expect("Failed to restore wp-content/plugins");
}

#[derive(Debug)]
pub struct AsyncWPNetworking {
client: reqwest::Client,
}
Expand Down
1 change: 1 addition & 0 deletions wp_api/tests/wp_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ where
f(WordPressDb { conn }).await
}

#[derive(Debug)]
pub struct WordPressDb {
conn: MySqlConnection,
}
Expand Down