rippling_api/
candidate_applications.rs1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct CandidateApplications {
6 pub client: Client,
7}
8
9impl CandidateApplications {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List candidate applications\n\nA List of candidate applications\n- Requires: `API Tier 2`\n- Expandable fields: `job`\n- Sortable fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `cursor: Option<String>`\n- `expand: Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_candidate_applications_list_stream() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let mut candidate_applications = client.candidate_applications();\n let mut stream = candidate_applications.list_stream(\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
16 #[tracing::instrument]
17 pub async fn list<'a>(
18 &'a self,
19 cursor: Option<String>,
20 expand: Option<String>,
21 order_by: Option<String>,
22 ) -> Result<crate::types::ListCandidateApplicationsResponse, crate::types::error::Error> {
23 let mut req = self.client.client.request(
24 http::Method::GET,
25 format!("{}/{}", self.client.base_url, "candidate-applications"),
26 );
27 req = req.bearer_auth(&self.client.token);
28 let mut query_params = vec![];
29 if let Some(p) = cursor {
30 query_params.push(("cursor", p));
31 }
32
33 if let Some(p) = expand {
34 query_params.push(("expand", p));
35 }
36
37 if let Some(p) = order_by {
38 query_params.push(("order_by", p));
39 }
40
41 req = req.query(&query_params);
42 let resp = req.send().await?;
43 let status = resp.status();
44 if status.is_success() {
45 let text = resp.text().await.unwrap_or_default();
46 serde_json::from_str(&text).map_err(|err| {
47 crate::types::error::Error::from_serde_error(
48 format_serde_error::SerdeError::new(text.to_string(), err),
49 status,
50 )
51 })
52 } else {
53 let text = resp.text().await.unwrap_or_default();
54 Err(crate::types::error::Error::Server {
55 body: text.to_string(),
56 status,
57 })
58 }
59 }
60
61 #[doc = "List candidate applications\n\nA List of candidate applications\n- Requires: `API Tier 2`\n- Expandable fields: `job`\n- Sortable fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `cursor: Option<String>`\n- `expand: Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_candidate_applications_list_stream() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let mut candidate_applications = client.candidate_applications();\n let mut stream = candidate_applications.list_stream(\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
62 #[tracing::instrument]
63 #[cfg(not(feature = "js"))]
64 pub fn list_stream<'a>(
65 &'a self,
66 expand: Option<String>,
67 order_by: Option<String>,
68 ) -> impl futures::Stream<Item = Result<crate::types::Application, crate::types::error::Error>>
69 + Unpin
70 + '_ {
71 use futures::{StreamExt, TryFutureExt, TryStreamExt};
72
73 use crate::types::paginate::Pagination;
74 self.list(None, expand, order_by)
75 .map_ok(move |result| {
76 let items = futures::stream::iter(result.items().into_iter().map(Ok));
77 let next_pages = futures::stream::try_unfold(
78 (None, result),
79 move |(prev_page_token, new_result)| async move {
80 if new_result.has_more_pages()
81 && !new_result.items().is_empty()
82 && prev_page_token != new_result.next_page_token()
83 {
84 async {
85 let mut req = self.client.client.request(
86 http::Method::GET,
87 format!(
88 "{}/{}",
89 self.client.base_url, "candidate-applications"
90 ),
91 );
92 req = req.bearer_auth(&self.client.token);
93 let mut request = req.build()?;
94 request = new_result.next_page(request)?;
95 let resp = self.client.client.execute(request).await?;
96 let status = resp.status();
97 if status.is_success() {
98 let text = resp.text().await.unwrap_or_default();
99 serde_json::from_str(&text).map_err(|err| {
100 crate::types::error::Error::from_serde_error(
101 format_serde_error::SerdeError::new(
102 text.to_string(),
103 err,
104 ),
105 status,
106 )
107 })
108 } else {
109 let text = resp.text().await.unwrap_or_default();
110 Err(crate::types::error::Error::Server {
111 body: text.to_string(),
112 status,
113 })
114 }
115 }
116 .map_ok(|result: crate::types::ListCandidateApplicationsResponse| {
117 Some((
118 futures::stream::iter(result.items().into_iter().map(Ok)),
119 (new_result.next_page_token(), result),
120 ))
121 })
122 .await
123 } else {
124 Ok(None)
125 }
126 },
127 )
128 .try_flatten();
129 items.chain(next_pages)
130 })
131 .try_flatten_stream()
132 .boxed()
133 }
134}