Skip to content

Commit

Permalink
newer fixed rippling
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Sep 20, 2024
1 parent dad9c7a commit d81a5f0
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 131 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ rippling-base: openapitor
rippling: openapitor
$(openapitor_exe) \
--input specs/rippling-beta.yaml \
--target-version 0.1.3 \
--target-version 0.1.4 \
--output ./rippling \
--name rippling-api \
--description "A fully generated & opinionated API client for the Rippling API." \
Expand Down
2 changes: 1 addition & 1 deletion kittycad.rs
8 changes: 4 additions & 4 deletions rippling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rippling-api"
description = "A fully generated & opinionated API client for the Rippling API."
version = "0.1.3"
version = "0.1.4"
documentation = "https://docs.rs/rippling-api"
readme = "README.md"

Expand All @@ -24,7 +24,7 @@ http = { version = "^0.2.8", optional = true }
itertools = "0.13.0"
log = { version = "^0.4", features = ["serde"], optional = true }
mime_guess = "2.0.4"
parse-display = "0.9.1"
parse-display = "0.10.0"
phonenumber = "0.3.5"
rand = { version = "0.8", optional = true }
reqwest = { version = "0.11.27", default-features = false, features = ["json", "multipart", "rustls-tls"], optional = true }
Expand All @@ -37,7 +37,7 @@ serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11"
serde_json = "1"
serde_urlencoded = { version = "^0.7", optional = true }
tabled = { version = "0.15.0", features = ["ansi"], optional = true }
tabled = { version = "0.16.0", features = ["ansi"], optional = true }
thiserror = "1"
tracing = { version = "^0.1", optional = true }
url = { version = "2", features = ["serde"] }
Expand All @@ -52,7 +52,7 @@ futures-util = "^0.3.26"
pretty_assertions = "1"
rand = "0.8"
tokio = { version = "1.38.0", features = ["rt", "macros"] }
tokio-tungstenite = "0.23"
tokio-tungstenite = "0.24"

[features]
default = ["requests", "retry"]
Expand Down
2 changes: 1 addition & 1 deletion rippling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To install the library, add the following to your `Cargo.toml` file.

```toml
[dependencies]
rippling-api = "0.1.3"
rippling-api = "0.1.4"
```

## Basic example
Expand Down
20 changes: 10 additions & 10 deletions rippling/rippling-api.rs.patch.json

Large diffs are not rendered by default.

80 changes: 79 additions & 1 deletion rippling/src/companies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ impl Companies {
Self { client }
}

#[doc = "List companies\n\nA List of companies\n- Requires: `API Tier 1`\n- Expandable fields: `legal_entities`\n- Sortable fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `expand: Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nasync fn example_companies_list() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let result: rippling_api::types::ListCompaniesResponse = client\n .companies()\n .list(\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[doc = "List companies\n\nA List of companies\n- Requires: `API Tier 1`\n- Expandable fields: `legal_entities`\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_companies_list_stream() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let mut companies = client.companies();\n let mut stream = companies.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```"]
#[tracing::instrument]
pub async fn list<'a>(
&'a self,
cursor: Option<String>,
expand: Option<String>,
order_by: Option<String>,
) -> Result<crate::types::ListCompaniesResponse, crate::types::error::Error> {
Expand All @@ -25,6 +26,10 @@ impl Companies {
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = cursor {
query_params.push(("cursor", p));
}

if let Some(p) = expand {
query_params.push(("expand", p));
}
Expand All @@ -43,6 +48,7 @@ impl Companies {
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
.into()
})
} else {
let text = resp.text().await.unwrap_or_default();
Expand All @@ -52,4 +58,76 @@ impl Companies {
});
}
}

#[doc = "List companies\n\nA List of companies\n- Requires: `API Tier 1`\n- Expandable fields: `legal_entities`\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_companies_list_stream() -> anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let mut companies = client.companies();\n let mut stream = companies.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```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_stream<'a>(
&'a self,
expand: Option<String>,
order_by: Option<String>,
) -> impl futures::Stream<Item = Result<crate::types::Company, crate::types::error::Error>>
+ Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};

use crate::types::paginate::Pagination;
self.list(None, expand, order_by)
.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, "companies"),
);
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,
)
.into()
})
} else {
let text = resp.text().await.unwrap_or_default();
return Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
});
}
}
.map_ok(|result: crate::types::ListCompaniesResponse| {
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()
}
}
101 changes: 96 additions & 5 deletions rippling/src/custom_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ impl CustomFields {
}

#[doc = "List custom fields\n\nA List of custom fields\n- Requires: `API Tier 1`\n- Sortable \
fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `order_by: \
Option<String>`\n\n```rust,no_run\nasync fn example_custom_fields_list() -> \
fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `cursor: \
Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nuse \
futures_util::TryStreamExt;\nasync fn example_custom_fields_list_stream() -> \
anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let \
result: rippling_api::types::ListCustomFieldsResponse = client\n \
.custom_fields()\n .list(Some(\"some-string\".to_string()))\n \
.await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
mut custom_fields = client.custom_fields();\n let mut stream = \
custom_fields.list_stream(Some(\"some-string\".to_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```"]
#[tracing::instrument]
pub async fn list<'a>(
&'a self,
cursor: Option<String>,
order_by: Option<String>,
) -> Result<crate::types::ListCustomFieldsResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
Expand All @@ -30,6 +35,10 @@ impl CustomFields {
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = cursor {
query_params.push(("cursor", p));
}

if let Some(p) = order_by {
query_params.push(("order_by", p));
}
Expand All @@ -44,6 +53,7 @@ impl CustomFields {
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
.into()
})
} else {
let text = resp.text().await.unwrap_or_default();
Expand All @@ -53,4 +63,85 @@ impl CustomFields {
});
}
}

#[doc = "List custom fields\n\nA List of custom fields\n- Requires: `API Tier 1`\n- Sortable \
fields: `id`, `created_at`, `updated_at`\n\n**Parameters:**\n\n- `cursor: \
Option<String>`\n- `order_by: Option<String>`\n\n```rust,no_run\nuse \
futures_util::TryStreamExt;\nasync fn example_custom_fields_list_stream() -> \
anyhow::Result<()> {\n let client = rippling_api::Client::new_from_env();\n let \
mut custom_fields = client.custom_fields();\n let mut stream = \
custom_fields.list_stream(Some(\"some-string\".to_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```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_stream<'a>(
&'a self,
order_by: Option<String>,
) -> impl futures::Stream<Item = Result<crate::types::CustomField, crate::types::error::Error>>
+ Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};

use crate::types::paginate::Pagination;
self.list(None, order_by)
.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-fields"),
);
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,
)
.into()
})
} else {
let text = resp.text().await.unwrap_or_default();
return Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
});
}
}
.map_ok(|result: crate::types::ListCustomFieldsResponse| {
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()
}
}
Loading

0 comments on commit d81a5f0

Please sign in to comment.