1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct ShiftInputs {
6 pub client: Client,
7}
8
9impl ShiftInputs {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List shift inputs\n\nA List of shift inputs\n- Requires: `API Tier 2`\n- Filterable fields: `name`\n- Expandable fields: `creator`\n- Sortable fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `cursor: Option<String>`\n- `expand: Option<String>`\n- `filter: Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_shift_inputs_list_stream() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let mut shift_inputs = client.shift_inputs();\n let mut stream = shift_inputs.list_stream(\n Some(\"some-string\".to_string()),\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 filter: Option<String>,
22 order_by: Option<String>,
23 ) -> Result<crate::types::ListShiftInputsResponse, crate::types::error::Error> {
24 let mut req = self.client.client.request(
25 http::Method::GET,
26 format!("{}/{}", self.client.base_url, "shift-inputs"),
27 );
28 req = req.bearer_auth(&self.client.token);
29 let mut query_params = vec![];
30 if let Some(p) = cursor {
31 query_params.push(("cursor", p));
32 }
33
34 if let Some(p) = expand {
35 query_params.push(("expand", p));
36 }
37
38 if let Some(p) = filter {
39 query_params.push(("filter", p));
40 }
41
42 if let Some(p) = order_by {
43 query_params.push(("order_by", p));
44 }
45
46 req = req.query(&query_params);
47 let resp = req.send().await?;
48 let status = resp.status();
49 if status.is_success() {
50 let text = resp.text().await.unwrap_or_default();
51 serde_json::from_str(&text).map_err(|err| {
52 crate::types::error::Error::from_serde_error(
53 format_serde_error::SerdeError::new(text.to_string(), err),
54 status,
55 )
56 })
57 } else {
58 let text = resp.text().await.unwrap_or_default();
59 Err(crate::types::error::Error::Server {
60 body: text.to_string(),
61 status,
62 })
63 }
64 }
65
66 #[doc = "List shift inputs\n\nA List of shift inputs\n- Requires: `API Tier 2`\n- Filterable fields: `name`\n- Expandable fields: `creator`\n- Sortable fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `cursor: Option<String>`\n- `expand: Option<String>`\n- `filter: Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_shift_inputs_list_stream() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let mut shift_inputs = client.shift_inputs();\n let mut stream = shift_inputs.list_stream(\n Some(\"some-string\".to_string()),\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```"]
67 #[tracing::instrument]
68 #[cfg(not(feature = "js"))]
69 pub fn list_stream<'a>(
70 &'a self,
71 expand: Option<String>,
72 filter: Option<String>,
73 order_by: Option<String>,
74 ) -> impl futures::Stream<Item = Result<crate::types::ShiftInput, crate::types::error::Error>>
75 + Unpin
76 + '_ {
77 use futures::{StreamExt, TryFutureExt, TryStreamExt};
78
79 use crate::types::paginate::Pagination;
80 self.list(None, expand, filter, order_by)
81 .map_ok(move |result| {
82 let items = futures::stream::iter(result.items().into_iter().map(Ok));
83 let next_pages = futures::stream::try_unfold(
84 (None, result),
85 move |(prev_page_token, new_result)| async move {
86 if new_result.has_more_pages()
87 && !new_result.items().is_empty()
88 && prev_page_token != new_result.next_page_token()
89 {
90 async {
91 let mut req = self.client.client.request(
92 http::Method::GET,
93 format!("{}/{}", self.client.base_url, "shift-inputs"),
94 );
95 req = req.bearer_auth(&self.client.token);
96 let mut request = req.build()?;
97 request = new_result.next_page(request)?;
98 let resp = self.client.client.execute(request).await?;
99 let status = resp.status();
100 if status.is_success() {
101 let text = resp.text().await.unwrap_or_default();
102 serde_json::from_str(&text).map_err(|err| {
103 crate::types::error::Error::from_serde_error(
104 format_serde_error::SerdeError::new(
105 text.to_string(),
106 err,
107 ),
108 status,
109 )
110 })
111 } else {
112 let text = resp.text().await.unwrap_or_default();
113 Err(crate::types::error::Error::Server {
114 body: text.to_string(),
115 status,
116 })
117 }
118 }
119 .map_ok(|result: crate::types::ListShiftInputsResponse| {
120 Some((
121 futures::stream::iter(result.items().into_iter().map(Ok)),
122 (new_result.next_page_token(), result),
123 ))
124 })
125 .await
126 } else {
127 Ok(None)
128 }
129 },
130 )
131 .try_flatten();
132 items.chain(next_pages)
133 })
134 .try_flatten_stream()
135 .boxed()
136 }
137
138 #[doc = "Create a new shift input\n\nCreate a new shift input\n\n```rust,no_run\nasync fn example_shift_inputs_create() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let result: rippling_api::types::ShiftInput = client\n .shift_inputs()\n .create(&rippling_api::types::ShiftInputRequest {\n creator_id: Some(\"some-string\".to_string()),\n name: \"some-string\".to_string(),\n prompt: \"some-string\".to_string(),\n type_: \"some-string\".to_string(),\n country_code: \"some-string\".to_string(),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
139 #[tracing::instrument]
140 pub async fn create<'a>(
141 &'a self,
142 body: &crate::types::ShiftInputRequest,
143 ) -> Result<crate::types::ShiftInput, crate::types::error::Error> {
144 let mut req = self.client.client.request(
145 http::Method::POST,
146 format!("{}/{}", self.client.base_url, "shift-inputs"),
147 );
148 req = req.bearer_auth(&self.client.token);
149 req = req.json(body);
150 let resp = req.send().await?;
151 let status = resp.status();
152 if status.is_success() {
153 let text = resp.text().await.unwrap_or_default();
154 serde_json::from_str(&text).map_err(|err| {
155 crate::types::error::Error::from_serde_error(
156 format_serde_error::SerdeError::new(text.to_string(), err),
157 status,
158 )
159 })
160 } else {
161 let text = resp.text().await.unwrap_or_default();
162 Err(crate::types::error::Error::Server {
163 body: text.to_string(),
164 status,
165 })
166 }
167 }
168
169 #[doc = "Retrieve a specific shift input\n\nRetrieve a specific shift input\n\n**Parameters:**\n\n- `expand: Option<String>`\n- `id: &'astr`: ID of the resource to return (required)\n\n```rust,no_run\nasync fn example_shift_inputs_get() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let result: rippling_api::types::GetShiftInputsResponse = client\n .shift_inputs()\n .get(\n Some(\"some-string\".to_string()),\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
170 #[tracing::instrument]
171 pub async fn get<'a>(
172 &'a self,
173 expand: Option<String>,
174 id: &'a str,
175 ) -> Result<crate::types::GetShiftInputsResponse, crate::types::error::Error> {
176 let mut req = self.client.client.request(
177 http::Method::GET,
178 format!(
179 "{}/{}",
180 self.client.base_url,
181 "shift-inputs/{id}".replace("{id}", id)
182 ),
183 );
184 req = req.bearer_auth(&self.client.token);
185 let mut query_params = vec![];
186 if let Some(p) = expand {
187 query_params.push(("expand", p));
188 }
189
190 req = req.query(&query_params);
191 let resp = req.send().await?;
192 let status = resp.status();
193 if status.is_success() {
194 let text = resp.text().await.unwrap_or_default();
195 serde_json::from_str(&text).map_err(|err| {
196 crate::types::error::Error::from_serde_error(
197 format_serde_error::SerdeError::new(text.to_string(), err),
198 status,
199 )
200 })
201 } else {
202 let text = resp.text().await.unwrap_or_default();
203 Err(crate::types::error::Error::Server {
204 body: text.to_string(),
205 status,
206 })
207 }
208 }
209
210 #[doc = "Delete a shift input\n\n**Parameters:**\n\n- `id: &'astr`: ID of the resource to \
211 delete (required)\n\n```rust,no_run\nasync fn example_shift_inputs_delete() -> \
212 anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n \
213 client\n .shift_inputs()\n \
214 .delete(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")\n .await?;\n \
215 Ok(())\n}\n```"]
216 #[tracing::instrument]
217 pub async fn delete<'a>(&'a self, id: &'a str) -> Result<(), crate::types::error::Error> {
218 let mut req = self.client.client.request(
219 http::Method::DELETE,
220 format!(
221 "{}/{}",
222 self.client.base_url,
223 "shift-inputs/{id}".replace("{id}", id)
224 ),
225 );
226 req = req.bearer_auth(&self.client.token);
227 let resp = req.send().await?;
228 let status = resp.status();
229 if status.is_success() {
230 Ok(())
231 } else {
232 let text = resp.text().await.unwrap_or_default();
233 Err(crate::types::error::Error::Server {
234 body: text.to_string(),
235 status,
236 })
237 }
238 }
239
240 #[doc = "Update a shift input\n\nUpdated a specific shift input\n\n**Parameters:**\n\n- `id: &'astr`: ID of the resource to patch (required)\n\n```rust,no_run\nasync fn example_shift_inputs_update() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let result: rippling_api::types::ShiftInput = client\n .shift_inputs()\n .update(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n &rippling_api::types::ShiftInputRequest {\n creator_id: Some(\"some-string\".to_string()),\n name: \"some-string\".to_string(),\n prompt: \"some-string\".to_string(),\n type_: \"some-string\".to_string(),\n country_code: \"some-string\".to_string(),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
241 #[tracing::instrument]
242 pub async fn update<'a>(
243 &'a self,
244 id: &'a str,
245 body: &crate::types::ShiftInputRequest,
246 ) -> Result<crate::types::ShiftInput, crate::types::error::Error> {
247 let mut req = self.client.client.request(
248 http::Method::PATCH,
249 format!(
250 "{}/{}",
251 self.client.base_url,
252 "shift-inputs/{id}".replace("{id}", id)
253 ),
254 );
255 req = req.bearer_auth(&self.client.token);
256 req = req.json(body);
257 let resp = req.send().await?;
258 let status = resp.status();
259 if status.is_success() {
260 let text = resp.text().await.unwrap_or_default();
261 serde_json::from_str(&text).map_err(|err| {
262 crate::types::error::Error::from_serde_error(
263 format_serde_error::SerdeError::new(text.to_string(), err),
264 status,
265 )
266 })
267 } else {
268 let text = resp.text().await.unwrap_or_default();
269 Err(crate::types::error::Error::Server {
270 body: text.to_string(),
271 status,
272 })
273 }
274 }
275}