rippling_api/
custom_object_fields.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct CustomObjectFields {
6    pub client: Client,
7}
8
9impl CustomObjectFields {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List custom object fields\n\nA List of custom object fields\n- Requires: `API Tier 1`\n\n**Parameters:**\n\n- `cursor: Option<String>`\n- `custom_object_api_name: &'astr` (required)\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_custom_object_fields_list_custom_objects_custom_object_api_name_fields_stream(\n) -> anyhow::Result<()> {\n    let client = rippling_api::Client::new_from_env();\n    let mut custom_object_fields = client.custom_object_fields();\n    let mut stream = custom_object_fields\n        .list_custom_objects_custom_object_api_name_fields_stream(\"some-string\");\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_custom_objects_custom_object_api_name_fields<'a>(
18        &'a self,
19        cursor: Option<String>,
20        custom_object_api_name: &'a str,
21    ) -> Result<
22        crate::types::ListCustomObjectsCustomObjectApiNameFieldsResponse,
23        crate::types::error::Error,
24    > {
25        let mut req = self.client.client.request(
26            http::Method::GET,
27            format!(
28                "{}/{}",
29                self.client.base_url,
30                "custom-objects/{custom_object_api_name}/fields"
31                    .replace("{custom_object_api_name}", custom_object_api_name)
32            ),
33        );
34        req = req.bearer_auth(&self.client.token);
35        let mut query_params = vec![];
36        if let Some(p) = cursor {
37            query_params.push(("cursor", p));
38        }
39
40        req = req.query(&query_params);
41        let resp = req.send().await?;
42        let status = resp.status();
43        if status.is_success() {
44            let text = resp.text().await.unwrap_or_default();
45            serde_json::from_str(&text).map_err(|err| {
46                crate::types::error::Error::from_serde_error(
47                    format_serde_error::SerdeError::new(text.to_string(), err),
48                    status,
49                )
50            })
51        } else {
52            let text = resp.text().await.unwrap_or_default();
53            Err(crate::types::error::Error::Server {
54                body: text.to_string(),
55                status,
56            })
57        }
58    }
59
60    #[doc = "List custom object fields\n\nA List of custom object fields\n- Requires: `API Tier 1`\n\n**Parameters:**\n\n- `cursor: Option<String>`\n- `custom_object_api_name: &'astr` (required)\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_custom_object_fields_list_custom_objects_custom_object_api_name_fields_stream(\n) -> anyhow::Result<()> {\n    let client = rippling_api::Client::new_from_env();\n    let mut custom_object_fields = client.custom_object_fields();\n    let mut stream = custom_object_fields\n        .list_custom_objects_custom_object_api_name_fields_stream(\"some-string\");\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```"]
61    #[tracing::instrument]
62    #[cfg(not(feature = "js"))]
63    pub fn list_custom_objects_custom_object_api_name_fields_stream<'a>(
64        &'a self,
65        custom_object_api_name: &'a str,
66    ) -> impl futures::Stream<
67        Item = Result<crate::types::CustomObjectField, crate::types::error::Error>,
68    > + Unpin
69           + '_ {
70        use futures::{StreamExt, TryFutureExt, TryStreamExt};
71
72        use crate::types::paginate::Pagination;
73        self . list_custom_objects_custom_object_api_name_fields (None , custom_object_api_name) . map_ok (move | result | { let items = futures :: stream :: iter (result . items () . into_iter () . map (Ok)) ; let next_pages = futures :: stream :: try_unfold ((None , result) , move | (prev_page_token , new_result) | async move { if new_result . has_more_pages () && ! new_result . items () . is_empty () && prev_page_token != new_result . next_page_token () { async { let mut req = self . client . client . request (http :: Method :: GET , format ! ("{}/{}" , self . client . base_url , "custom-objects/{custom_object_api_name}/fields" . replace ("{custom_object_api_name}" , custom_object_api_name)) ,) ; req = req . bearer_auth (& self . client . token) ; let mut request = req . build () ? ; request = new_result . next_page (request) ? ; let resp = self . client . client . execute (request) . await ? ; let status = resp . status () ; if status . is_success () { let text = resp . text () . await . unwrap_or_default () ; serde_json :: from_str (& text) . map_err (| err | crate :: types :: error :: Error :: from_serde_error (format_serde_error :: SerdeError :: new (text . to_string () , err) , status)) } else { let text = resp . text () . await . unwrap_or_default () ; Err (crate :: types :: error :: Error :: Server { body : text . to_string () , status }) } } . map_ok (| result : crate :: types :: ListCustomObjectsCustomObjectApiNameFieldsResponse | { Some ((futures :: stream :: iter (result . items () . into_iter () . map (Ok) ,) , (new_result . next_page_token () , result) ,)) }) . await } else { Ok (None) } }) . try_flatten () ; items . chain (next_pages) }) . try_flatten_stream () . boxed ()
74    }
75
76    #[doc = "Create a new custom object field\n\nCreate a new custom object field\n\n**Parameters:**\n\n- `custom_object_api_name: &'astr` (required)\n\n```rust,no_run\nasync fn example_custom_object_fields_create_custom_objects_custom_object_api_name_fields(\n) -> anyhow::Result<()> {\n    let client = rippling_api::Client::new_from_env();\n    let result: rippling_api::types::CustomObjectField = client\n        .custom_object_fields()\n        .create_custom_objects_custom_object_api_name_fields(\n            \"some-string\",\n            &rippling_api::types::CreateCustomObjectsCustomObjectApiNameFieldsRequestBody {\n                name: Some(\"some-string\".to_string()),\n                description: Some(\"some-string\".to_string()),\n                required: Some(true),\n                is_unique: Some(true),\n                enable_history: Some(true),\n                derived_field_formula: Some(\"some-string\".to_string()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
77    #[tracing::instrument]
78    pub async fn create_custom_objects_custom_object_api_name_fields<'a>(
79        &'a self,
80        custom_object_api_name: &'a str,
81        body: &crate::types::CreateCustomObjectsCustomObjectApiNameFieldsRequestBody,
82    ) -> Result<crate::types::CustomObjectField, crate::types::error::Error> {
83        let mut req = self.client.client.request(
84            http::Method::POST,
85            format!(
86                "{}/{}",
87                self.client.base_url,
88                "custom-objects/{custom_object_api_name}/fields"
89                    .replace("{custom_object_api_name}", custom_object_api_name)
90            ),
91        );
92        req = req.bearer_auth(&self.client.token);
93        req = req.json(body);
94        let resp = req.send().await?;
95        let status = resp.status();
96        if status.is_success() {
97            let text = resp.text().await.unwrap_or_default();
98            serde_json::from_str(&text).map_err(|err| {
99                crate::types::error::Error::from_serde_error(
100                    format_serde_error::SerdeError::new(text.to_string(), err),
101                    status,
102                )
103            })
104        } else {
105            let text = resp.text().await.unwrap_or_default();
106            Err(crate::types::error::Error::Server {
107                body: text.to_string(),
108                status,
109            })
110        }
111    }
112
113    #[doc = "Retrieve a specific custom object field\n\nRetrieve a specific custom object field\n\n**Parameters:**\n\n- `custom_object_api_name: &'astr` (required)\n- `field_api_name: &'astr` (required)\n\n```rust,no_run\nasync fn example_custom_object_fields_get_custom_objects_custom_object_api_name_fields(\n) -> anyhow::Result<()> {\n    let client = rippling_api::Client::new_from_env();\n    let result: rippling_api::types::CustomObjectField = client\n        .custom_object_fields()\n        .get_custom_objects_custom_object_api_name_fields(\"some-string\", \"some-string\")\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
114    #[tracing::instrument]
115    pub async fn get_custom_objects_custom_object_api_name_fields<'a>(
116        &'a self,
117        custom_object_api_name: &'a str,
118        field_api_name: &'a str,
119    ) -> Result<crate::types::CustomObjectField, crate::types::error::Error> {
120        let mut req = self.client.client.request(
121            http::Method::GET,
122            format!(
123                "{}/{}",
124                self.client.base_url,
125                "custom-objects/{custom_object_api_name}/fields/{field_api_name}"
126                    .replace("{custom_object_api_name}", custom_object_api_name)
127                    .replace("{field_api_name}", field_api_name)
128            ),
129        );
130        req = req.bearer_auth(&self.client.token);
131        let resp = req.send().await?;
132        let status = resp.status();
133        if status.is_success() {
134            let text = resp.text().await.unwrap_or_default();
135            serde_json::from_str(&text).map_err(|err| {
136                crate::types::error::Error::from_serde_error(
137                    format_serde_error::SerdeError::new(text.to_string(), err),
138                    status,
139                )
140            })
141        } else {
142            let text = resp.text().await.unwrap_or_default();
143            Err(crate::types::error::Error::Server {
144                body: text.to_string(),
145                status,
146            })
147        }
148    }
149
150    #[doc = "Delete a custom object field\n\nDelete a custom object field\n\n**Parameters:**\n\n- \
151             `custom_object_api_name: &'astr` (required)\n- `field_api_name: &'astr` \
152             (required)\n\n```rust,no_run\nasync fn \
153             example_custom_object_fields_delete_custom_objects_custom_object_api_name_fields(\n) \
154             -> anyhow::Result<()> {\n    let client = rippling_api::Client::new_from_env();\n    \
155             client\n        .custom_object_fields()\n        \
156             .delete_custom_objects_custom_object_api_name_fields(\"some-string\", \
157             \"some-string\")\n        .await?;\n    Ok(())\n}\n```"]
158    #[tracing::instrument]
159    pub async fn delete_custom_objects_custom_object_api_name_fields<'a>(
160        &'a self,
161        custom_object_api_name: &'a str,
162        field_api_name: &'a str,
163    ) -> Result<(), crate::types::error::Error> {
164        let mut req = self.client.client.request(
165            http::Method::DELETE,
166            format!(
167                "{}/{}",
168                self.client.base_url,
169                "custom-objects/{custom_object_api_name}/fields/{field_api_name}"
170                    .replace("{custom_object_api_name}", custom_object_api_name)
171                    .replace("{field_api_name}", field_api_name)
172            ),
173        );
174        req = req.bearer_auth(&self.client.token);
175        let resp = req.send().await?;
176        let status = resp.status();
177        if status.is_success() {
178            Ok(())
179        } else {
180            let text = resp.text().await.unwrap_or_default();
181            Err(crate::types::error::Error::Server {
182                body: text.to_string(),
183                status,
184            })
185        }
186    }
187
188    #[doc = "Update a custom object field\n\nUpdated a specific custom object field\n\n**Parameters:**\n\n- `custom_object_api_name: &'astr` (required)\n- `field_api_name: &'astr` (required)\n\n```rust,no_run\nasync fn example_custom_object_fields_update_custom_objects_custom_object_api_name_fields(\n) -> anyhow::Result<()> {\n    let client = rippling_api::Client::new_from_env();\n    let result: rippling_api::types::CustomObjectField = client\n        .custom_object_fields()\n        .update_custom_objects_custom_object_api_name_fields(\n            \"some-string\",\n            \"some-string\",\n            &rippling_api::types::UpdateCustomObjectsCustomObjectApiNameFieldsRequestBody {\n                name: Some(\"some-string\".to_string()),\n                description: Some(\"some-string\".to_string()),\n                required: Some(true),\n                is_unique: Some(true),\n                enable_history: Some(true),\n                derived_field_formula: Some(\"some-string\".to_string()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
189    #[tracing::instrument]
190    pub async fn update_custom_objects_custom_object_api_name_fields<'a>(
191        &'a self,
192        custom_object_api_name: &'a str,
193        field_api_name: &'a str,
194        body: &crate::types::UpdateCustomObjectsCustomObjectApiNameFieldsRequestBody,
195    ) -> Result<crate::types::CustomObjectField, crate::types::error::Error> {
196        let mut req = self.client.client.request(
197            http::Method::PATCH,
198            format!(
199                "{}/{}",
200                self.client.base_url,
201                "custom-objects/{custom_object_api_name}/fields/{field_api_name}"
202                    .replace("{custom_object_api_name}", custom_object_api_name)
203                    .replace("{field_api_name}", field_api_name)
204            ),
205        );
206        req = req.bearer_auth(&self.client.token);
207        req = req.json(body);
208        let resp = req.send().await?;
209        let status = resp.status();
210        if status.is_success() {
211            let text = resp.text().await.unwrap_or_default();
212            serde_json::from_str(&text).map_err(|err| {
213                crate::types::error::Error::from_serde_error(
214                    format_serde_error::SerdeError::new(text.to_string(), err),
215                    status,
216                )
217            })
218        } else {
219            let text = resp.text().await.unwrap_or_default();
220            Err(crate::types::error::Error::Server {
221                body: text.to_string(),
222                status,
223            })
224        }
225    }
226}