From 0e8c28c948ec7240ba02162501bc9d687927eb4d Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 31 Mar 2022 20:26:54 +0200 Subject: [PATCH] Move endpoints to sub module in api_core Signed-off-by: trivernis --- src/api_core/client.rs | 26 +++++++++++-------- .../{ => endpoints}/access_management.rs | 2 +- src/api_core/{ => endpoints}/adding_files.rs | 2 +- src/api_core/{ => endpoints}/adding_notes.rs | 2 +- src/api_core/{ => endpoints}/adding_tags.rs | 2 +- src/api_core/{ => endpoints}/adding_urls.rs | 4 +-- .../{ => endpoints}/client_builder.rs | 0 .../managing_cookies_and_http_headers.rs | 2 +- .../{ => endpoints}/managing_pages.rs | 2 +- src/api_core/endpoints/mod.rs | 20 ++++++++++++++ .../searching_and_fetching_files.rs | 2 +- src/api_core/mod.rs | 23 +--------------- src/lib.rs | 2 +- src/wrapper/address.rs | 2 +- src/wrapper/builders/delete_files_builder.rs | 2 +- src/wrapper/builders/import_builder.rs | 4 +-- src/wrapper/builders/search_builder.rs | 4 ++- src/wrapper/builders/tagging_builder.rs | 2 +- src/wrapper/hydrus_file.rs | 2 +- src/wrapper/service.rs | 4 +-- src/wrapper/url.rs | 2 +- tests/client/test_adding_files.rs | 2 +- tests/client/test_adding_tags.rs | 2 +- tests/client/test_adding_urls.rs | 2 +- .../test_managing_cookies_and_http_headers.rs | 2 +- .../test_searching_and_fetching_files.rs | 6 +++-- tests/common/mod.rs | 2 +- tests/wrapper/test_files.rs | 2 +- tests/wrapper/test_hydrus.rs | 2 +- 29 files changed, 69 insertions(+), 62 deletions(-) rename src/api_core/{ => endpoints}/access_management.rs (97%) rename src/api_core/{ => endpoints}/adding_files.rs (98%) rename src/api_core/{ => endpoints}/adding_notes.rs (97%) rename src/api_core/{ => endpoints}/adding_tags.rs (99%) rename src/api_core/{ => endpoints}/adding_urls.rs (97%) rename src/api_core/{ => endpoints}/client_builder.rs (100%) rename src/api_core/{ => endpoints}/managing_cookies_and_http_headers.rs (98%) rename src/api_core/{ => endpoints}/managing_pages.rs (97%) create mode 100644 src/api_core/endpoints/mod.rs rename src/api_core/{ => endpoints}/searching_and_fetching_files.rs (99%) diff --git a/src/api_core/client.rs b/src/api_core/client.rs index 4234213..c3b05de 100644 --- a/src/api_core/client.rs +++ b/src/api_core/client.rs @@ -1,32 +1,36 @@ -use crate::api_core::access_management::{ +use crate::api_core::common::{FileIdentifier, FileMetadataInfo, FileRecord, OptionalStringNumber}; +use crate::api_core::endpoints::access_management::{ ApiVersion, ApiVersionResponse, GetServices, GetServicesResponse, SessionKey, SessionKeyResponse, VerifyAccessKey, VerifyAccessKeyResponse, }; -use crate::api_core::adding_files::{ +use crate::api_core::endpoints::adding_files::{ AddFile, AddFileRequest, AddFileResponse, ArchiveFiles, ArchiveFilesRequest, DeleteFiles, DeleteFilesRequest, UnarchiveFiles, UnarchiveFilesRequest, UndeleteFiles, UndeleteFilesRequest, }; -use crate::api_core::adding_notes::{DeleteNotes, DeleteNotesRequest, SetNotes, SetNotesRequest}; -use crate::api_core::adding_tags::{AddTags, AddTagsRequest, CleanTags, CleanTagsResponse}; -use crate::api_core::adding_urls::{ +use crate::api_core::endpoints::adding_notes::{ + DeleteNotes, DeleteNotesRequest, SetNotes, SetNotesRequest, +}; +use crate::api_core::endpoints::adding_tags::{ + AddTags, AddTagsRequest, CleanTags, CleanTagsResponse, +}; +use crate::api_core::endpoints::adding_urls::{ AddUrl, AddUrlRequest, AddUrlResponse, AssociateUrl, AssociateUrlRequest, GetUrlFiles, GetUrlFilesResponse, GetUrlInfo, GetUrlInfoResponse, }; -use crate::api_core::client_builder::ClientBuilder; -use crate::api_core::common::{FileIdentifier, FileMetadataInfo, FileRecord, OptionalStringNumber}; -use crate::api_core::managing_cookies_and_http_headers::{ +use crate::api_core::endpoints::client_builder::ClientBuilder; +use crate::api_core::endpoints::managing_cookies_and_http_headers::{ GetCookies, GetCookiesResponse, SetCookies, SetCookiesRequest, SetUserAgent, SetUserAgentRequest, }; -use crate::api_core::managing_pages::{ +use crate::api_core::endpoints::managing_pages::{ AddFiles, AddFilesRequest, FocusPage, FocusPageRequest, GetPageInfo, GetPageInfoResponse, GetPages, GetPagesResponse, }; -use crate::api_core::searching_and_fetching_files::{ +use crate::api_core::endpoints::searching_and_fetching_files::{ FileMetadata, FileMetadataResponse, FileSearchOptions, GetFile, SearchFileHashes, SearchFileHashesResponse, SearchFiles, SearchFilesResponse, SearchQueryEntry, }; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; use crate::error::{Error, Result}; use bytes::Buf; use reqwest::Response; diff --git a/src/api_core/access_management.rs b/src/api_core/endpoints/access_management.rs similarity index 97% rename from src/api_core/access_management.rs rename to src/api_core/endpoints/access_management.rs index 8c5ff11..1e2f275 100644 --- a/src/api_core/access_management.rs +++ b/src/api_core/endpoints/access_management.rs @@ -1,5 +1,5 @@ use crate::api_core::common::BasicServiceInfo; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; use std::collections::HashMap; pub static SERVICE_TYPE_LOCAL_TAGS: &str = "local_tags"; diff --git a/src/api_core/adding_files.rs b/src/api_core/endpoints/adding_files.rs similarity index 98% rename from src/api_core/adding_files.rs rename to src/api_core/endpoints/adding_files.rs index 52bf489..e9028e0 100644 --- a/src/api_core/adding_files.rs +++ b/src/api_core/endpoints/adding_files.rs @@ -1,5 +1,5 @@ use crate::api_core::common::{BasicHashList, ServiceIdentifier}; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; use serde::Serialize; pub static STATUS_IMPORT_SUCCESS: u8 = 1; diff --git a/src/api_core/adding_notes.rs b/src/api_core/endpoints/adding_notes.rs similarity index 97% rename from src/api_core/adding_notes.rs rename to src/api_core/endpoints/adding_notes.rs index 794d958..d7c875a 100644 --- a/src/api_core/adding_notes.rs +++ b/src/api_core/endpoints/adding_notes.rs @@ -1,5 +1,5 @@ use crate::api_core::common::FileIdentifier; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; use std::collections::HashMap; pub struct SetNotes; diff --git a/src/api_core/adding_tags.rs b/src/api_core/endpoints/adding_tags.rs similarity index 99% rename from src/api_core/adding_tags.rs rename to src/api_core/endpoints/adding_tags.rs index 1c9aafe..8ac4363 100644 --- a/src/api_core/adding_tags.rs +++ b/src/api_core/endpoints/adding_tags.rs @@ -1,5 +1,5 @@ use crate::api_core::common::ServiceIdentifier; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; use std::collections::HashMap; #[derive(Debug, Clone, Deserialize)] diff --git a/src/api_core/adding_urls.rs b/src/api_core/endpoints/adding_urls.rs similarity index 97% rename from src/api_core/adding_urls.rs rename to src/api_core/endpoints/adding_urls.rs index 33aae0b..c083e37 100644 --- a/src/api_core/adding_urls.rs +++ b/src/api_core/endpoints/adding_urls.rs @@ -1,5 +1,5 @@ use crate::api_core::common::ServiceIdentifier; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; use serde::Serialize; use std::collections::HashMap; @@ -74,7 +74,7 @@ pub struct AddUrlRequest { /// /// Example: /// ``` -/// use hydrus_api::api_core::adding_urls::AddUrlRequestBuilder; +/// use hydrus_api::api_core::endpoints::adding_urls::AddUrlRequestBuilder; /// use hydrus_api::api_core::common::ServiceIdentifier; /// /// let request = AddUrlRequestBuilder::default() diff --git a/src/api_core/client_builder.rs b/src/api_core/endpoints/client_builder.rs similarity index 100% rename from src/api_core/client_builder.rs rename to src/api_core/endpoints/client_builder.rs diff --git a/src/api_core/managing_cookies_and_http_headers.rs b/src/api_core/endpoints/managing_cookies_and_http_headers.rs similarity index 98% rename from src/api_core/managing_cookies_and_http_headers.rs rename to src/api_core/endpoints/managing_cookies_and_http_headers.rs index 1587657..c8fc4ea 100644 --- a/src/api_core/managing_cookies_and_http_headers.rs +++ b/src/api_core/endpoints/managing_cookies_and_http_headers.rs @@ -1,5 +1,5 @@ use crate::api_core::common::OptionalStringNumber; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; #[derive(Clone, Debug, Deserialize)] pub struct GetCookiesResponse { diff --git a/src/api_core/managing_pages.rs b/src/api_core/endpoints/managing_pages.rs similarity index 97% rename from src/api_core/managing_pages.rs rename to src/api_core/endpoints/managing_pages.rs index f42556d..119047c 100644 --- a/src/api_core/managing_pages.rs +++ b/src/api_core/endpoints/managing_pages.rs @@ -1,5 +1,5 @@ use crate::api_core::common::PageInformation; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; #[derive(Clone, Debug, Deserialize)] pub struct GetPagesResponse { diff --git a/src/api_core/endpoints/mod.rs b/src/api_core/endpoints/mod.rs new file mode 100644 index 0000000..a1130ed --- /dev/null +++ b/src/api_core/endpoints/mod.rs @@ -0,0 +1,20 @@ +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::fmt::Debug; + +pub mod access_management; +pub mod adding_files; +pub mod adding_notes; +pub mod adding_tags; +pub mod adding_urls; +pub mod client_builder; +pub mod managing_cookies_and_http_headers; +pub mod managing_pages; +pub mod searching_and_fetching_files; + +pub(crate) trait Endpoint { + type Request: Serialize + Debug; + type Response: DeserializeOwned + Debug; + + fn path() -> String; +} diff --git a/src/api_core/searching_and_fetching_files.rs b/src/api_core/endpoints/searching_and_fetching_files.rs similarity index 99% rename from src/api_core/searching_and_fetching_files.rs rename to src/api_core/endpoints/searching_and_fetching_files.rs index 42ca9f8..fe9cdbe 100644 --- a/src/api_core/searching_and_fetching_files.rs +++ b/src/api_core/endpoints/searching_and_fetching_files.rs @@ -1,5 +1,5 @@ use crate::api_core::common::FileMetadataInfo; -use crate::api_core::Endpoint; +use crate::api_core::endpoints::Endpoint; pub mod file_sort_type { pub const SORT_FILE_SIZE: u8 = 0; diff --git a/src/api_core/mod.rs b/src/api_core/mod.rs index b07f339..8891c59 100644 --- a/src/api_core/mod.rs +++ b/src/api_core/mod.rs @@ -1,24 +1,3 @@ -use serde::de::DeserializeOwned; -use serde::Serialize; -use std::fmt::Debug; - -pub mod access_management; -pub mod adding_files; -pub mod adding_tags; -pub mod adding_urls; pub mod client; -pub mod client_builder; pub mod common; -pub mod managing_cookies_and_http_headers; -pub mod managing_pages; -pub mod searching_and_fetching_files; -pub mod adding_notes; - -pub use searching_and_fetching_files::file_sort_type; - -pub(crate) trait Endpoint { - type Request: Serialize + Debug; - type Response: DeserializeOwned + Debug; - - fn path() -> String; -} +pub mod endpoints; diff --git a/src/lib.rs b/src/lib.rs index d7b6884..5f3f53c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,7 +56,7 @@ //! ## Client Usage Example //! ``` //! use hydrus_api::Client; -//! use hydrus_api::api_core::adding_tags::{AddTagsRequestBuilder, TagAction}; +//! use hydrus_api::api_core::endpoints::adding_tags::{AddTagsRequestBuilder, TagAction}; //! use std::env; //! use hydrus_api::api_core::common::ServiceIdentifier; //! # #[tokio::test] diff --git a/src/wrapper/address.rs b/src/wrapper/address.rs index b3f13c7..85830a2 100644 --- a/src/wrapper/address.rs +++ b/src/wrapper/address.rs @@ -1,5 +1,5 @@ use crate::api_core::common::OptionalStringNumber; -use crate::api_core::managing_cookies_and_http_headers::CookieBuilder; +use crate::api_core::endpoints::managing_cookies_and_http_headers::CookieBuilder; use crate::error::Result; use crate::Client; use std::time::{Duration, SystemTime, UNIX_EPOCH}; diff --git a/src/wrapper/builders/delete_files_builder.rs b/src/wrapper/builders/delete_files_builder.rs index b9abd61..2f57ec3 100644 --- a/src/wrapper/builders/delete_files_builder.rs +++ b/src/wrapper/builders/delete_files_builder.rs @@ -1,5 +1,5 @@ -use crate::api_core::adding_files::DeleteFilesRequest; use crate::api_core::common::{FileIdentifier, ServiceIdentifier}; +use crate::api_core::endpoints::adding_files::DeleteFilesRequest; use crate::error::Result; use crate::Client; diff --git a/src/wrapper/builders/import_builder.rs b/src/wrapper/builders/import_builder.rs index c8969e8..ec9aae0 100644 --- a/src/wrapper/builders/import_builder.rs +++ b/src/wrapper/builders/import_builder.rs @@ -1,6 +1,6 @@ -use crate::api_core::adding_files::{STATUS_IMPORT_FAILED, STATUS_IMPORT_VETOED}; -use crate::api_core::adding_urls::AddUrlRequestBuilder; use crate::api_core::common::ServiceIdentifier; +use crate::api_core::endpoints::adding_files::{STATUS_IMPORT_FAILED, STATUS_IMPORT_VETOED}; +use crate::api_core::endpoints::adding_urls::AddUrlRequestBuilder; use crate::error::{Error, Result}; use crate::utils::tag_list_to_string_list; use crate::wrapper::hydrus_file::HydrusFile; diff --git a/src/wrapper/builders/search_builder.rs b/src/wrapper/builders/search_builder.rs index 86a5d06..4443138 100644 --- a/src/wrapper/builders/search_builder.rs +++ b/src/wrapper/builders/search_builder.rs @@ -1,4 +1,6 @@ -use crate::api_core::searching_and_fetching_files::{FileSearchOptions, SearchQueryEntry}; +use crate::api_core::endpoints::searching_and_fetching_files::{ + FileSearchOptions, SearchQueryEntry, +}; use crate::error::Result; use crate::wrapper::hydrus_file::HydrusFile; use crate::wrapper::or_chain::OrChain; diff --git a/src/wrapper/builders/tagging_builder.rs b/src/wrapper/builders/tagging_builder.rs index 07f85b0..ad0c748 100644 --- a/src/wrapper/builders/tagging_builder.rs +++ b/src/wrapper/builders/tagging_builder.rs @@ -1,5 +1,5 @@ -use crate::api_core::adding_tags::{AddTagsRequestBuilder, TagAction}; use crate::api_core::common::ServiceIdentifier; +use crate::api_core::endpoints::adding_tags::{AddTagsRequestBuilder, TagAction}; use crate::error::Result; use crate::wrapper::tag::Tag; use crate::Client; diff --git a/src/wrapper/hydrus_file.rs b/src/wrapper/hydrus_file.rs index 4b3e368..3e2d60b 100644 --- a/src/wrapper/hydrus_file.rs +++ b/src/wrapper/hydrus_file.rs @@ -1,5 +1,5 @@ -use crate::api_core::adding_tags::{AddTagsRequestBuilder, TagAction}; use crate::api_core::common::{FileIdentifier, FileMetadataInfo, FileRecord, ServiceIdentifier}; +use crate::api_core::endpoints::adding_tags::{AddTagsRequestBuilder, TagAction}; use crate::error::{Error, Result}; use crate::utils::tag_list_to_string_list; use crate::wrapper::builders::delete_files_builder::DeleteFilesBuilder; diff --git a/src/wrapper/service.rs b/src/wrapper/service.rs index c8b9ab1..87664f7 100644 --- a/src/wrapper/service.rs +++ b/src/wrapper/service.rs @@ -1,5 +1,5 @@ -use crate::api_core::access_management::GetServicesResponse; -use crate::api_core::access_management::{ +use crate::api_core::endpoints::access_management::GetServicesResponse; +use crate::api_core::endpoints::access_management::{ SERVICE_TYPE_ALL_KNOWN_FILES, SERVICE_TYPE_ALL_KNOWN_TAGS, SERVICE_TYPE_ALL_LOCAL_FILES, SERVICE_TYPE_FILE_REPOSITORIES, SERVICE_TYPE_LOCAL_FILES, SERVICE_TYPE_LOCAL_TAGS, SERVICE_TYPE_TAG_REPOSITORIES, SERVICE_TYPE_TRASH, diff --git a/src/wrapper/url.rs b/src/wrapper/url.rs index dc7060f..e1582fd 100644 --- a/src/wrapper/url.rs +++ b/src/wrapper/url.rs @@ -1,4 +1,4 @@ -use crate::api_core::adding_urls::{ +use crate::api_core::endpoints::adding_urls::{ URL_TYPE_FILE, URL_TYPE_GALLERY, URL_TYPE_POST, URL_TYPE_WATCHABLE, }; use crate::error::Result; diff --git a/tests/client/test_adding_files.rs b/tests/client/test_adding_files.rs index 0424fa8..dc47a42 100644 --- a/tests/client/test_adding_files.rs +++ b/tests/client/test_adding_files.rs @@ -1,7 +1,7 @@ use crate::common; use crate::common::create_testdata; use crate::common::test_data::get_test_hashes; -use hydrus_api::api_core::adding_files::DeleteFilesRequest; +use hydrus_api::api_core::endpoints::adding_files::DeleteFilesRequest; use hydrus_api::wrapper::service::ServiceName; #[tokio::test] diff --git a/tests/client/test_adding_tags.rs b/tests/client/test_adding_tags.rs index 3b34952..5c43792 100644 --- a/tests/client/test_adding_tags.rs +++ b/tests/client/test_adding_tags.rs @@ -1,7 +1,7 @@ use super::super::common; use crate::common::test_data::EMPTY_HASH; -use hydrus_api::api_core::adding_tags::{AddTagsRequestBuilder, TagAction}; use hydrus_api::api_core::common::ServiceIdentifier; +use hydrus_api::api_core::endpoints::adding_tags::{AddTagsRequestBuilder, TagAction}; #[tokio::test] async fn it_cleans_tags() { diff --git a/tests/client/test_adding_urls.rs b/tests/client/test_adding_urls.rs index 4e7a629..03f0b24 100644 --- a/tests/client/test_adding_urls.rs +++ b/tests/client/test_adding_urls.rs @@ -1,7 +1,7 @@ use super::super::common; use crate::common::test_data::{get_test_hashes, get_test_urls, TEST_URL_1}; -use hydrus_api::api_core::adding_urls::{AddUrlRequestBuilder, URL_TYPE_POST}; use hydrus_api::api_core::common::ServiceIdentifier; +use hydrus_api::api_core::endpoints::adding_urls::{AddUrlRequestBuilder, URL_TYPE_POST}; #[tokio::test] async fn it_returns_files_for_an_url() { diff --git a/tests/client/test_managing_cookies_and_http_headers.rs b/tests/client/test_managing_cookies_and_http_headers.rs index 31e7b1e..a308850 100644 --- a/tests/client/test_managing_cookies_and_http_headers.rs +++ b/tests/client/test_managing_cookies_and_http_headers.rs @@ -1,5 +1,5 @@ use super::super::common; -use hydrus_api::api_core::managing_cookies_and_http_headers::CookieBuilder; +use hydrus_api::api_core::endpoints::managing_cookies_and_http_headers::CookieBuilder; #[tokio::test] async fn it_returns_cookies_for_a_domain() { diff --git a/tests/client/test_searching_and_fetching_files.rs b/tests/client/test_searching_and_fetching_files.rs index dde77ad..9021967 100644 --- a/tests/client/test_searching_and_fetching_files.rs +++ b/tests/client/test_searching_and_fetching_files.rs @@ -1,7 +1,9 @@ use super::super::common; use hydrus_api::api_core::common::FileIdentifier; -use hydrus_api::api_core::file_sort_type::SORT_FILE_PIXEL_COUNT; -use hydrus_api::api_core::searching_and_fetching_files::{FileSearchOptions, SearchQueryEntry}; +use hydrus_api::api_core::endpoints::searching_and_fetching_files::file_sort_type::SORT_FILE_PIXEL_COUNT; +use hydrus_api::api_core::endpoints::searching_and_fetching_files::{ + FileSearchOptions, SearchQueryEntry, +}; #[tokio::test] async fn is_searches_files() { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index cac4110..575d449 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,5 +1,5 @@ -use hydrus_api::api_core::adding_urls::AddUrlRequestBuilder; use hydrus_api::api_core::client::Client; +use hydrus_api::api_core::endpoints::adding_urls::AddUrlRequestBuilder; use hydrus_api::Hydrus; use std::env; use std::sync::{Arc, Mutex, MutexGuard}; diff --git a/tests/wrapper/test_files.rs b/tests/wrapper/test_files.rs index ce64a76..4f6cd29 100644 --- a/tests/wrapper/test_files.rs +++ b/tests/wrapper/test_files.rs @@ -1,8 +1,8 @@ use super::super::common; use crate::common::test_data::TEST_HASH_2; use crate::common::{create_testdata, get_client}; -use hydrus_api::api_core::adding_tags::TagAction; use hydrus_api::api_core::common::FileIdentifier; +use hydrus_api::api_core::endpoints::adding_tags::TagAction; use hydrus_api::wrapper::hydrus_file::HydrusFile; use hydrus_api::wrapper::service::ServiceName; diff --git a/tests/wrapper/test_hydrus.rs b/tests/wrapper/test_hydrus.rs index 777d1d3..4abd3b8 100644 --- a/tests/wrapper/test_hydrus.rs +++ b/tests/wrapper/test_hydrus.rs @@ -1,5 +1,5 @@ use super::super::common; -use hydrus_api::api_core::adding_tags::TagAction; +use hydrus_api::api_core::endpoints::adding_tags::TagAction; use hydrus_api::wrapper::builders::or_chain_builder::OrChainBuilder; use hydrus_api::wrapper::builders::search_builder::SortType; use hydrus_api::wrapper::builders::tag_builder::TagBuilder;