ferric_fred/
sources_request.rs1use crate::{Client, Result, SortOrder, SourcesResults};
2
3#[derive(Debug, Clone)]
15#[must_use = "a SourcesRequest does nothing until you call `.send()`"]
16pub struct SourcesRequest<'a> {
17 client: &'a Client,
18 sort_order: Option<SortOrder>,
19 limit: Option<u32>,
20 offset: Option<u32>,
21}
22
23impl<'a> SourcesRequest<'a> {
24 pub(crate) fn new(client: &'a Client) -> Self {
25 Self {
26 client,
27 sort_order: None,
28 limit: None,
29 offset: None,
30 }
31 }
32
33 pub fn sort_order(mut self, order: SortOrder) -> Self {
35 self.sort_order = Some(order);
36 self
37 }
38
39 pub fn limit(mut self, limit: u32) -> Self {
41 self.limit = Some(limit);
42 self
43 }
44
45 pub fn offset(mut self, offset: u32) -> Self {
47 self.offset = Some(offset);
48 self
49 }
50
51 pub async fn send(self) -> Result<SourcesResults> {
58 self.client.execute_sources(&self).await
59 }
60
61 pub(crate) fn query_params(&self) -> Vec<(&'static str, String)> {
64 let mut params: Vec<(&'static str, String)> = Vec::new();
65 if let Some(order) = self.sort_order {
66 params.push(("sort_order", order.query_code().to_owned()));
67 }
68 if let Some(limit) = self.limit {
69 params.push(("limit", limit.to_string()));
70 }
71 if let Some(offset) = self.offset {
72 params.push(("offset", offset.to_string()));
73 }
74 params
75 }
76}
77
78impl crate::paginate::sealed::Sealed for SourcesRequest<'_> {}
79impl crate::paginate::Paginate for SourcesRequest<'_> {
80 type Page = SourcesResults;
81 const MAX_PAGE: u32 = 1000;
82 fn requested_limit(&self) -> Option<u32> {
83 self.limit
84 }
85 fn requested_offset(&self) -> Option<u32> {
86 self.offset
87 }
88 fn with_paging(self, limit: u32, offset: u32) -> Self {
89 self.limit(limit).offset(offset)
90 }
91 fn send_page(self) -> impl std::future::Future<Output = Result<Self::Page>> + Send {
92 self.send()
93 }
94}