summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-07 15:12:57 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-07 16:55:39 +0200
commitaf3da6beefbd28c146f998558be0024e1f1ac1a8 (patch)
treef636488a74536bde49aecf9c9f78a6d3e8c098df
parentc75c23cec594837bfede6341787f80216f42e0ae (diff)
Implement first API interface mockup
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--librepology/src/v1/api.rs132
1 files changed, 132 insertions, 0 deletions
diff --git a/librepology/src/v1/api.rs b/librepology/src/v1/api.rs
index 1f9b076..a090249 100644
--- a/librepology/src/v1/api.rs
+++ b/librepology/src/v1/api.rs
@@ -1,4 +1,5 @@
use crate::endpoint::EndpointUrl;
+use reqwest::Client;
pub struct ApiClient {
endpoint_url: &'static str,
@@ -11,4 +12,135 @@ impl ApiClient {
}
}
+ pub fn projects<'a>(&'a self) -> ProjectRequestBuilder<'a> {
+ ProjectRequestBuilder(self)
+ }
+
+}
+
+pub struct ProjectRequestBuilder<'a>(&'a ApiClient);
+
+impl<'a> ProjectRequestBuilder<'a> {
+ pub fn with_name(self, name: String) -> ProjectRequestBuilderWithName<'a> {
+ ProjectRequestBuilderWithName(self.0, name)
+ }
+
+ pub fn filtered(self) -> ProjectRequestFilteredBuilder<'a> {
+ ProjectRequestFilteredBuilder {
+ client: self.0,
+ search: None,
+ category: None,
+ in_repo_filter: None,
+ not_in_repo_filter: None,
+ repos_filter: None,
+ families_filter: None,
+ repos_newest: None,
+ families_newest: None,
+ newest: None,
+ outdated: None,
+ problematic: None,
+ }
+ }
+}
+
+pub trait ToRequest<'a> {
+ fn to_request(self) -> Request<'a>;
+}
+
+pub struct Request<'a> {
+ client: &'a ApiClient,
+ request_string: String
}
+
+pub struct ProjectRequestBuilderWithName<'a>(&'a ApiClient, String);
+
+impl<'a> ToRequest<'a> for ProjectRequestBuilderWithName<'a> {
+ fn to_request(self) -> Request<'a> {
+ Request {
+ client: self.0,
+ request_string: format!("projects/{}", self.1),
+ }
+ }
+}
+
+pub struct ProjectRequestFilteredBuilder<'a> {
+ client: &'a ApiClient,
+
+ // From the API documentation
+
+ search: Option<String>,
+ category: Option<String>,
+ in_repo_filter: Option<String>,
+ not_in_repo_filter: Option<String>,
+ repos_filter: Option<NumberOrRange>,
+ families_filter: Option<usize>,
+ repos_newest: Option<bool>,
+ families_newest: Option<bool>,
+ newest: Option<bool>,
+ outdated: Option<bool>,
+ problematic: Option<bool>,
+}
+
+impl<'a> ProjectRequestFilteredBuilder<'a> {
+ pub fn with_search(mut self, opt: Option<String>) -> Self {
+ self.search = opt;
+ self
+ }
+
+ pub fn with_category(mut self, opt: Option<String>) -> Self {
+ self.category = opt;
+ self
+ }
+
+ pub fn with_in_repo_filter(mut self, opt: Option<String>) -> Self {
+ self.in_repo_filter = opt;
+ self
+ }
+
+ pub fn with_not_in_repo_filter(mut self, opt: Option<String>) -> Self {
+ self.not_in_repo_filter = opt;
+ self
+ }
+
+ pub fn with_repos_filter(mut self, opt: Option<NumberOrRange>) -> Self {
+ self.repos_filter = opt;
+ self
+ }
+
+ pub fn with_families_filter(mut self, opt: Option<usize>) -> Self {
+ self.families_filter = opt;
+ self
+ }
+
+ pub fn with_repos_newest(mut self, opt: Option<bool>) -> Self {
+ self.repos_newest = opt;
+ self
+ }
+
+ pub fn with_families_newest(mut self, opt: Option<bool>) -> Self {
+ self.families_newest = opt;
+ self
+ }
+
+ pub fn with_newest(mut self, opt: Option<bool>) -> Self {
+ self.newest = opt;
+ self
+ }
+
+ pub fn with_outdated(mut self, opt: Option<bool>) -> Self {
+ self.outdated = opt;
+ self
+ }
+
+ pub fn with_problematic(mut self, opt: Option<bool>) -> Self {
+ self.problematic = opt;
+ self
+ }
+
+}
+
+pub enum NumberOrRange {
+ Number(usize),
+ Range(Option<usize>, Option<usize>),
+}
+