use crate::endpoint::EndpointUrl; use reqwest::Client; pub struct ApiClient { endpoint_url: &'static str, } impl ApiClient { pub fn new() -> Self { ApiClient { endpoint_url: EP::endpoint_url(), } } 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, category: Option, in_repo_filter: Option, not_in_repo_filter: Option, repos_filter: Option, families_filter: Option, repos_newest: Option, families_newest: Option, newest: Option, outdated: Option, problematic: Option, } impl<'a> ProjectRequestFilteredBuilder<'a> { pub fn with_search(mut self, opt: Option) -> Self { self.search = opt; self } pub fn with_category(mut self, opt: Option) -> Self { self.category = opt; self } pub fn with_in_repo_filter(mut self, opt: Option) -> Self { self.in_repo_filter = opt; self } pub fn with_not_in_repo_filter(mut self, opt: Option) -> Self { self.not_in_repo_filter = opt; self } pub fn with_repos_filter(mut self, opt: Option) -> Self { self.repos_filter = opt; self } pub fn with_families_filter(mut self, opt: Option) -> Self { self.families_filter = opt; self } pub fn with_repos_newest(mut self, opt: Option) -> Self { self.repos_newest = opt; self } pub fn with_families_newest(mut self, opt: Option) -> Self { self.families_newest = opt; self } pub fn with_newest(mut self, opt: Option) -> Self { self.newest = opt; self } pub fn with_outdated(mut self, opt: Option) -> Self { self.outdated = opt; self } pub fn with_problematic(mut self, opt: Option) -> Self { self.problematic = opt; self } } pub enum NumberOrRange { Number(usize), Range(Option, Option), }