Skip to content

Commit

Permalink
Use plugin slug type instead of string (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazytonyli authored Jan 23, 2025
1 parent 6f2b564 commit 693b03e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions native/swift/Sources/wordpress-api/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ public typealias WpSiteHealthTestsRequestExecutor = WordPressAPIInternal.WpSiteH
extension WpSiteHealthTestsRequestExecutor: @unchecked Sendable {}
// swiftlint:enable line_length

// MARK: - WordPress.org
public typealias WordPressOrgApiClient = WordPressAPIInternal.WordPressOrgApiClient
extension WordPressOrgApiClient: @unchecked Sendable {}

#endif
6 changes: 6 additions & 0 deletions wp_api/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ impl From<&str> for PluginWpOrgDirectorySlug {
}
}

impl PluginWpOrgDirectorySlug {
pub fn as_str(&self) -> &str {
self.slug.as_str()
}
}

#[derive(
Debug,
Clone,
Expand Down
10 changes: 5 additions & 5 deletions wp_api/src/wordpress_org/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
request::{endpoint::WpEndpointUrl, RequestExecutor, WpNetworkRequest, WpNetworkResponse},
RequestExecutionError,
PluginWpOrgDirectorySlug, RequestExecutionError,
};
use serde::de::DeserializeOwned;
use std::{result::Result, sync::Arc};
Expand All @@ -22,7 +22,7 @@ impl WordPressOrgApiClient {

pub async fn plugin_information(
&self,
slug: &str,
slug: &PluginWpOrgDirectorySlug,
) -> Result<PluginInformation, WordPressOrgApiClientError> {
self.execute(Self::plugin_information_request(slug)).await
}
Expand Down Expand Up @@ -73,12 +73,12 @@ impl WordPressOrgApiClient {
})
}

fn plugin_information_request(slug: &str) -> WpNetworkRequest {
fn plugin_information_request(slug: &PluginWpOrgDirectorySlug) -> WpNetworkRequest {
let mut url = Self::plugin_info_api_url();
url.query_pairs_mut()
.append_pair("action", "plugin_information")
.append_pair("fields", "icons")
.append_pair("slug", slug);
.append_pair("slug", slug.as_str());
WpNetworkRequest::get(WpEndpointUrl(url.to_string()))
}

Expand Down Expand Up @@ -186,7 +186,7 @@ mod tests {

#[test]
fn test_plugin_info_requests_include_icons() {
let request = WordPressOrgApiClient::plugin_information_request("akismet");
let request = WordPressOrgApiClient::plugin_information_request(&("akismet".into()));
assert!(request.url.0.contains("fields=icons"));
}

Expand Down
2 changes: 1 addition & 1 deletion wp_api_integration_tests/tests/test_plugin_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn test_parsing_full_plugin_directory() {

let mut plugin_information_failures = Vec::new();
for slug in all_slugs {
let info = client.plugin_information(&slug).await;
let info = client.plugin_information(&slug.as_str().into()).await;
if let Err(e) = info {
print!("F({})", slug);
plugin_information_failures.push((slug.to_string(), e));
Expand Down

0 comments on commit 693b03e

Please sign in to comment.