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
4 changes: 2 additions & 2 deletions wp_api/src/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use url::Url;

pub use plugins_endpoint::*;
pub use users_endpoint::*;
use plugins_endpoint::*;
use users_endpoint::*;

use crate::SparseField;

Expand Down
3 changes: 1 addition & 2 deletions wp_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

use serde::Deserialize;
use std::collections::HashMap;
use url::Url;

pub use api_error::{WPApiError, WPRestError, WPRestErrorCode, WPRestErrorWrapper};
use endpoint::*;
use login::*;
use plugins::*;
use url::*;
use users::*;

mod api_error; // re-exported relevant types
pub mod endpoint;
pub mod login;
pub mod plugins;
pub mod url;
pub mod users;

#[cfg(test)]
Expand Down
34 changes: 33 additions & 1 deletion wp_api/src/login.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::url::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::str;
use url::Url;

// After a successful login, the system will receive an OAuth callback with the login details
// embedded as query params. This function parses that URL and extracts the login details as an object.
Expand Down Expand Up @@ -60,3 +60,35 @@ pub struct WPAPIApplicationPasswordDetails {
pub user_login: String,
pub password: String,
}

// A type that's guaranteed to represent a valid URL
//
// It is a programmer error to instantiate this object with an invalid URL
#[derive(Debug, uniffi::Record)]
pub struct WPRestAPIURL {
pub string_value: String,
}

impl WPRestAPIURL {
pub fn as_str(&self) -> &str {
self.string_value.as_str()
}

pub fn as_url(&self) -> url::Url {
Url::parse(self.string_value.as_str()).unwrap()
}
}

impl From<Url> for WPRestAPIURL {
fn from(url: url::Url) -> Self {
WPRestAPIURL {
string_value: url.into(),
}
}
}

impl From<WPRestAPIURL> for String {
fn from(url: WPRestAPIURL) -> Self {
url.string_value
}
}
33 changes: 0 additions & 33 deletions wp_api/src/url.rs

This file was deleted.