Skip to content

Commit

Permalink
Update api spec (#291)
Browse files Browse the repository at this point in the history
* YOYO NEW API SPEC!

* I have generated the library!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 3db52db commit 4114625
Show file tree
Hide file tree
Showing 8 changed files with 1,109 additions and 23 deletions.
30 changes: 27 additions & 3 deletions kittycad.rs.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/meta/struct.Meta.html#method.get_metadata"
}
},
{
"op": "add",
"path": "/paths/~1_meta~1ipinfo/get/x-rust",
"value": {
"example": "/// Get ip address information.\nasync fn example_meta_get_ipinfo() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::IpAddrInfo = client.meta().get_ipinfo().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/meta/struct.Meta.html#method.get_ipinfo"
}
},
{
"op": "add",
"path": "/paths/~1ai-prompts/get/x-rust",
Expand Down Expand Up @@ -235,15 +243,23 @@
"op": "add",
"path": "/paths/~1oauth2~1provider~1{provider}~1callback/get/x-rust",
"value": {
"example": "/// Listen for callbacks for the OAuth 2.0 provider.\n/// \n/// **Parameters:**\n/// \n/// - `code: Option<String>`: The authorization code.\n/// - `provider: crate::types::AccountProvider`: The provider. (required)\n/// - `state: Option<String>`: The state that we had passed in through the user consent URL.\nasync fn example_oauth2_oauth_2_provider_callback() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_provider_callback(\n Some(\"some-string\".to_string()),\n kittycad::types::AccountProvider::Github,\n Some(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n",
"example": "/// Listen for callbacks for the OAuth 2.0 provider.\n/// \n/// **Parameters:**\n/// \n/// - `code: Option<String>`: The authorization code.\n/// - `id_token: Option<String>`: For Apple only, a JSON web token containing the user’s identity information.\n/// - `provider: crate::types::AccountProvider`: The provider. (required)\n/// - `state: Option<String>`: The state that we had passed in through the user consent URL.\n/// - `user: Option<String>`: For Apple only, a JSON string containing the data requested in the scope property. The returned data is in the following format: `{ \"name\": { \"firstName\": string, \"lastName\": string }, \"email\": string }`\nasync fn example_oauth2_oauth_2_provider_callback() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_provider_callback(\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n kittycad::types::AccountProvider::Tencent,\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/oauth2/struct.Oauth2.html#method.oauth_2_provider_callback"
}
},
{
"op": "add",
"path": "/paths/~1oauth2~1provider~1{provider}~1callback/post/x-rust",
"value": {
"example": "/// Listen for callbacks for the OAuth 2.0 provider.\n/// \n/// This specific endpoint listens for posts of form data.\n/// \n/// **Parameters:**\n/// \n/// - `provider: crate::types::AccountProvider`: The provider. (required)\nasync fn example_oauth2_oauth_2_provider_callback_post() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_provider_callback_post(\n kittycad::types::AccountProvider::Tencent,\n &kittycad::types::AuthCallback {\n code: Some(\"some-string\".to_string()),\n id_token: Some(\"some-string\".to_string()),\n state: Some(\"some-string\".to_string()),\n user: Some(\"some-string\".to_string()),\n },\n )\n .await?;\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/oauth2/struct.Oauth2.html#method.oauth_2_provider_callback_post"
}
},
{
"op": "add",
"path": "/paths/~1oauth2~1provider~1{provider}~1consent/get/x-rust",
"value": {
"example": "/// Get the consent URL and other information for the OAuth 2.0 provider.\n/// \n/// **Parameters:**\n/// \n/// - `callback_url: Option<String>`: The URL to redirect back to after we have authenticated.\n/// - `provider: crate::types::AccountProvider`: The provider. (required)\nasync fn example_oauth2_oauth_2_provider_consent() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2ClientInfo = client\n .oauth2()\n .oauth_2_provider_consent(\n Some(\"some-string\".to_string()),\n kittycad::types::AccountProvider::Github,\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"example": "/// Get the consent URL and other information for the OAuth 2.0 provider.\n/// \n/// **Parameters:**\n/// \n/// - `callback_url: Option<String>`: The URL to redirect back to after we have authenticated.\n/// - `provider: crate::types::AccountProvider`: The provider. (required)\nasync fn example_oauth2_oauth_2_provider_consent() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2ClientInfo = client\n .oauth2()\n .oauth_2_provider_consent(\n Some(\"some-string\".to_string()),\n kittycad::types::AccountProvider::Tencent,\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/oauth2/struct.Oauth2.html#method.oauth_2_provider_consent"
}
},
Expand Down Expand Up @@ -307,7 +323,7 @@
"op": "add",
"path": "/paths/~1org~1members/post/x-rust",
"value": {
"example": "/// Add a member to your org.\n/// \n/// This endpoint requires authentication by an org admin. It adds the specified member to the authenticated user's org.\nasync fn example_orgs_create_member() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::OrgMember = client\n .orgs()\n .create_member(&kittycad::types::AddOrgMember {\n email: \"email@example.com\".to_string(),\n role: kittycad::types::OrgRole::Member,\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"example": "/// Add a member to your org.\n/// \n/// If the user exists, this will add them to your org. If they do not exist, this will create a new user and add them to your org.\n/// In both cases the user gets an email that they have been added to the org.\n/// If the user is already in your org, this will return a 400 and a message.\n/// If the user is already in a different org, this will return a 400 and a message.\n/// This endpoint requires authentication by an org admin. It adds the specified member to the authenticated user's org.\nasync fn example_orgs_create_member() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::OrgMember = client\n .orgs()\n .create_member(&kittycad::types::AddOrgMember {\n email: \"email@example.com\".to_string(),\n role: kittycad::types::OrgRole::Member,\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/orgs/struct.Orgs.html#method.create_member"
}
},
Expand Down Expand Up @@ -607,6 +623,14 @@
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/users/struct.Users.html#method.get_self_extended"
}
},
{
"op": "add",
"path": "/paths/~1user~1oauth2~1providers/get/x-rust",
"value": {
"example": "/// Get the OAuth2 providers for your user.\n/// \n/// If this returns an empty array, then the user has not connected any OAuth2 providers and uses raw email authentication.\n/// This endpoint requires authentication by any Zoo user. It gets the providers for the authenticated user.\nasync fn example_users_get_oauth_2_providers_for() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: Vec<kittycad::types::AccountProvider> =\n client.users().get_oauth_2_providers_for().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/users/struct.Users.html#method.get_oauth_2_providers_for"
}
},
{
"op": "add",
"path": "/paths/~1user~1onboarding/get/x-rust",
Expand Down
32 changes: 32 additions & 0 deletions kittycad/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,38 @@ impl Meta {
}
}

#[doc = "Get ip address information.\n\n```rust,no_run\nasync fn example_meta_get_ipinfo() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: kittycad::types::IpAddrInfo = client.meta().get_ipinfo().await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get_ipinfo<'a>(
&'a self,
) -> Result<crate::types::IpAddrInfo, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "_meta/ipinfo"),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().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();
return Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
});
}
}

#[doc = "Get an API token for a user by their discord id.\n\nThis endpoint allows us to run \
API calls from our discord bot on behalf of a user. The user must have a discord \
account linked to their Zoo Account via oauth2 for this to work.\nYou must be a Zoo \
Expand Down
66 changes: 55 additions & 11 deletions kittycad/src/oauth2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,15 @@ impl Oauth2 {
}
}

#[doc = "Listen for callbacks for the OAuth 2.0 provider.\n\n**Parameters:**\n\n- `code: \
Option<String>`: The authorization code.\n- `provider: \
crate::types::AccountProvider`: The provider. (required)\n- `state: Option<String>`: \
The state that we had passed in through the user consent \
URL.\n\n```rust,no_run\nasync fn example_oauth2_oauth_2_provider_callback() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n \
client\n .oauth2()\n .oauth_2_provider_callback(\n \
Some(\"some-string\".to_string()),\n \
kittycad::types::AccountProvider::Github,\n \
Some(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n```"]
#[doc = "Listen for callbacks for the OAuth 2.0 provider.\n\n**Parameters:**\n\n- `code: Option<String>`: The authorization code.\n- `id_token: Option<String>`: For Apple only, a JSON web token containing the user’s identity information.\n- `provider: crate::types::AccountProvider`: The provider. (required)\n- `state: Option<String>`: The state that we had passed in through the user consent URL.\n- `user: Option<String>`: For Apple only, a JSON string containing the data requested in the scope property. The returned data is in the following format: `{ \"name\": { \"firstName\": string, \"lastName\": string }, \"email\": string }`\n\n```rust,no_run\nasync fn example_oauth2_oauth_2_provider_callback() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_provider_callback(\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n kittycad::types::AccountProvider::Tencent,\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_provider_callback<'a>(
&'a self,
code: Option<String>,
id_token: Option<String>,
provider: crate::types::AccountProvider,
state: Option<String>,
user: Option<String>,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
Expand All @@ -168,10 +161,18 @@ impl Oauth2 {
query_params.push(("code", p));
}

if let Some(p) = id_token {
query_params.push(("id_token", p));
}

if let Some(p) = state {
query_params.push(("state", p));
}

if let Some(p) = user {
query_params.push(("user", p));
}

req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
Expand All @@ -186,6 +187,49 @@ impl Oauth2 {
}
}

#[doc = "Listen for callbacks for the OAuth 2.0 provider.\n\nThis specific endpoint listens \
for posts of form data.\n\n**Parameters:**\n\n- `provider: \
crate::types::AccountProvider`: The provider. (required)\n\n```rust,no_run\nasync fn \
example_oauth2_oauth_2_provider_callback_post() -> anyhow::Result<()> {\n let \
client = kittycad::Client::new_from_env();\n client\n .oauth2()\n \
.oauth_2_provider_callback_post(\n \
kittycad::types::AccountProvider::Tencent,\n \
&kittycad::types::AuthCallback {\n code: \
Some(\"some-string\".to_string()),\n id_token: \
Some(\"some-string\".to_string()),\n state: \
Some(\"some-string\".to_string()),\n user: \
Some(\"some-string\".to_string()),\n },\n )\n .await?;\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_provider_callback_post<'a>(
&'a self,
provider: crate::types::AccountProvider,
body: &crate::types::AuthCallback,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"oauth2/provider/{provider}/callback"
.replace("{provider}", &format!("{}", provider))
),
);
req = req.bearer_auth(&self.client.token);
req = req.form(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
return Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
});
}
}

#[doc = "Get the consent URL and other information for the OAuth 2.0 \
provider.\n\n**Parameters:**\n\n- `callback_url: Option<String>`: The URL to redirect \
back to after we have authenticated.\n- `provider: crate::types::AccountProvider`: \
Expand All @@ -194,7 +238,7 @@ impl Oauth2 {
kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2ClientInfo \
= client\n .oauth2()\n .oauth_2_provider_consent(\n \
Some(\"some-string\".to_string()),\n \
kittycad::types::AccountProvider::Github,\n )\n .await?;\n \
kittycad::types::AccountProvider::Tencent,\n )\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_provider_consent<'a>(
Expand Down
14 changes: 9 additions & 5 deletions kittycad/src/orgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ impl Orgs {
.boxed()
}

#[doc = "Add a member to your org.\n\nThis endpoint requires authentication by an org admin. \
It adds the specified member to the authenticated user's \
org.\n\n```rust,no_run\nasync fn example_orgs_create_member() -> anyhow::Result<()> \
{\n let client = kittycad::Client::new_from_env();\n let result: \
kittycad::types::OrgMember = client\n .orgs()\n \
#[doc = "Add a member to your org.\n\nIf the user exists, this will add them to your org. If \
they do not exist, this will create a new user and add them to your org.\nIn both \
cases the user gets an email that they have been added to the org.\nIf the user is \
already in your org, this will return a 400 and a message.\nIf the user is already in \
a different org, this will return a 400 and a message.\nThis endpoint requires \
authentication by an org admin. It adds the specified member to the authenticated \
user's org.\n\n```rust,no_run\nasync fn example_orgs_create_member() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: kittycad::types::OrgMember = client\n .orgs()\n \
.create_member(&kittycad::types::AddOrgMember {\n email: \
\"email@example.com\".to_string(),\n role: \
kittycad::types::OrgRole::Member,\n })\n .await?;\n \
Expand Down
Loading

0 comments on commit 4114625

Please sign in to comment.