speedrun_api/api/
publishers.rs1use std::{borrow::Cow, fmt::Display};
5
6use serde::{Deserialize, Serialize};
7
8use super::{endpoint::Endpoint, error::BodyError, query_params::QueryParams, Direction, Pageable};
9
10#[derive(Debug, Serialize, Clone, Copy)]
12#[serde(rename_all = "kebab-case")]
13pub enum PublishersSorting {
14 Name,
16}
17
18#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
20pub struct PublisherId<'a>(Cow<'a, str>);
21
22impl<'a> PublisherId<'a> {
23 pub fn new<T>(id: T) -> Self
25 where
26 T: Into<Cow<'a, str>>,
27 {
28 Self(id.into())
29 }
30}
31
32impl<'a, T> From<T> for PublisherId<'a>
33where
34 T: Into<Cow<'a, str>>,
35{
36 fn from(value: T) -> Self {
37 Self::new(value)
38 }
39}
40
41impl Display for PublisherId<'_> {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 write!(f, "{}", &self.0)
44 }
45}
46
47#[derive(Default, Debug, Builder, Serialize, Clone)]
49#[builder(default, setter(into, strip_option))]
50#[serde(rename_all = "kebab-case")]
51pub struct Publishers {
52 #[doc = r"Sorting options for results."]
53 orderby: Option<PublishersSorting>,
54 #[doc = r"Sort direction"]
55 direction: Option<Direction>,
56}
57
58#[derive(Debug, Builder, Clone)]
60#[builder(setter(into, strip_option))]
61pub struct Publisher<'a> {
62 #[doc = r"`ID` for the publisher."]
63 id: PublisherId<'a>,
64}
65
66impl Publishers {
67 pub fn builder() -> PublishersBuilder {
69 PublishersBuilder::default()
70 }
71}
72
73impl Publisher<'_> {
74 pub fn builder<'a>() -> PublisherBuilder<'a> {
76 PublisherBuilder::default()
77 }
78}
79
80impl Default for PublishersSorting {
81 fn default() -> Self {
82 Self::Name
83 }
84}
85
86impl Endpoint for Publishers {
87 fn endpoint(&self) -> Cow<'static, str> {
88 "/publishers".into()
89 }
90
91 fn query_parameters(&self) -> Result<QueryParams<'_>, BodyError> {
92 QueryParams::with(self)
93 }
94}
95
96impl Endpoint for Publisher<'_> {
97 fn endpoint(&self) -> Cow<'static, str> {
98 format!("/publishers/{}", self.id).into()
99 }
100}
101
102impl Pageable for Publishers {}