summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2024-09-18 15:46:48 -0700
committerGravatar GitHub <noreply@github.com> 2024-09-18 15:46:48 -0700
commit5d5e2fdf0dac9288e21d5793cce76253212dad2c (patch)
treed557a270f6f5724ce40ac61f8adaba58433fe290
parentdc8214d6ca134d6650c272174762a36035b56f02 (diff)
parent7bad3c45442438ebfa65122b83e56c4321db2215 (diff)
downloadpandascore-5d5e2fdf0dac9288e21d5793cce76253212dad2c.tar.gz
pandascore-5d5e2fdf0dac9288e21d5793cce76253212dad2c.tar.zst
pandascore-5d5e2fdf0dac9288e21d5793cce76253212dad2c.zip
Merge pull request #38 from ansg191/player-endpoints
-rw-r--r--src/endpoint/all/players.rs140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/endpoint/all/players.rs b/src/endpoint/all/players.rs
index 9f177fe..8541237 100644
--- a/src/endpoint/all/players.rs
+++ b/src/endpoint/all/players.rs
@@ -1,2 +1,142 @@
+use std::future::Future;
+
+use reqwest::{Request, Response};
+use url::Url;
+
+use crate::{
+ endpoint::{
+ sealed::Sealed, CollectionOptions, EndpointError, ListResponse, PaginatedEndpoint, BASE_URL,
+ },
+ model::{league::League, Identifier},
+};
+
crate::endpoint::list_endpoint!(ListPlayers("/players") => crate::model::player::Player);
crate::endpoint::get_endpoint!(GetPlayer("/players") => crate::model::player::Player);
+
+#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
+pub struct ListPlayerLeagues<'a> {
+ #[builder(into)]
+ id: Identifier<'a>,
+ #[builder(default)]
+ options: CollectionOptions,
+}
+
+impl Sealed for ListPlayerLeagues<'_> {
+ type Response = ListResponse<League>;
+
+ fn to_request(self) -> Result<Request, EndpointError> {
+ let mut url = Url::parse(&format!("{}/players/{}/leagues", BASE_URL, self.id))?;
+ self.options.add_params(&mut url);
+ Ok(Request::new(reqwest::Method::GET, url))
+ }
+
+ fn from_response(
+ response: Response,
+ ) -> impl Future<Output = Result<Self::Response, EndpointError>> + Send {
+ ListResponse::from_response(response)
+ }
+}
+
+impl PaginatedEndpoint for ListPlayerLeagues<'_> {
+ type Item = League;
+
+ fn with_options(self, options: CollectionOptions) -> Self {
+ Self { options, ..self }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
+pub struct ListPlayerSeries<'a> {
+ #[builder(into)]
+ id: Identifier<'a>,
+ #[builder(default)]
+ options: CollectionOptions,
+}
+
+impl Sealed for ListPlayerSeries<'_> {
+ type Response = ListResponse<League>;
+
+ fn to_request(self) -> Result<Request, EndpointError> {
+ let mut url = Url::parse(&format!("{}/players/{}/series", BASE_URL, self.id))?;
+ self.options.add_params(&mut url);
+ Ok(Request::new(reqwest::Method::GET, url))
+ }
+
+ fn from_response(
+ response: Response,
+ ) -> impl Future<Output = Result<Self::Response, EndpointError>> + Send {
+ ListResponse::from_response(response)
+ }
+}
+
+impl PaginatedEndpoint for ListPlayerSeries<'_> {
+ type Item = League;
+
+ fn with_options(self, options: CollectionOptions) -> Self {
+ Self { options, ..self }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
+pub struct ListPlayerTournaments<'a> {
+ #[builder(into)]
+ id: Identifier<'a>,
+ #[builder(default)]
+ options: CollectionOptions,
+}
+
+impl Sealed for ListPlayerTournaments<'_> {
+ type Response = ListResponse<League>;
+
+ fn to_request(self) -> Result<Request, EndpointError> {
+ let mut url = Url::parse(&format!("{}/players/{}/tournaments", BASE_URL, self.id))?;
+ self.options.add_params(&mut url);
+ Ok(Request::new(reqwest::Method::GET, url))
+ }
+
+ fn from_response(
+ response: Response,
+ ) -> impl Future<Output = Result<Self::Response, EndpointError>> + Send {
+ ListResponse::from_response(response)
+ }
+}
+
+impl PaginatedEndpoint for ListPlayerTournaments<'_> {
+ type Item = League;
+
+ fn with_options(self, options: CollectionOptions) -> Self {
+ Self { options, ..self }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
+pub struct ListPlayerMatches<'a> {
+ #[builder(into)]
+ id: Identifier<'a>,
+ #[builder(default)]
+ options: CollectionOptions,
+}
+
+impl Sealed for ListPlayerMatches<'_> {
+ type Response = ListResponse<League>;
+
+ fn to_request(self) -> Result<Request, EndpointError> {
+ let mut url = Url::parse(&format!("{}/players/{}/matches", BASE_URL, self.id))?;
+ self.options.add_params(&mut url);
+ Ok(Request::new(reqwest::Method::GET, url))
+ }
+
+ fn from_response(
+ response: Response,
+ ) -> impl Future<Output = Result<Self::Response, EndpointError>> + Send {
+ ListResponse::from_response(response)
+ }
+}
+
+impl PaginatedEndpoint for ListPlayerMatches<'_> {
+ type Item = League;
+
+ fn with_options(self, options: CollectionOptions) -> Self {
+ Self { options, ..self }
+ }
+}