From 0a71247fb61a91c1f6d519762013c1445713a728 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 13 Oct 2021 17:42:41 -0700 Subject: codegen for API schema v0.4.0 --- fatcat-openapi/src/client/mod.rs | 148 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 4 deletions(-) (limited to 'fatcat-openapi/src/client/mod.rs') diff --git a/fatcat-openapi/src/client/mod.rs b/fatcat-openapi/src/client/mod.rs index bb1cee8..774f6ee 100644 --- a/fatcat-openapi/src/client/mod.rs +++ b/fatcat-openapi/src/client/mod.rs @@ -67,10 +67,10 @@ use crate::{ GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, - GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, - LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, - UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, - UpdateWebcaptureResponse, UpdateWorkResponse, + GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupEditorResponse, + LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, + UpdateEditgroupResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, + UpdateReleaseResponse, UpdateWebcaptureResponse, UpdateWorkResponse, }; /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. @@ -13589,6 +13589,9 @@ where async fn lookup_container( &self, param_issnl: Option, + param_issne: Option, + param_issnp: Option, + param_issn: Option, param_wikidata_qid: Option, param_expand: Option, param_hide: Option, @@ -13603,6 +13606,15 @@ where if let Some(param_issnl) = param_issnl { query_string.append_pair("issnl", ¶m_issnl.to_string()); } + if let Some(param_issne) = param_issne { + query_string.append_pair("issne", ¶m_issne.to_string()); + } + if let Some(param_issnp) = param_issnp { + query_string.append_pair("issnp", ¶m_issnp.to_string()); + } + if let Some(param_issn) = param_issn { + query_string.append_pair("issn", ¶m_issn.to_string()); + } if let Some(param_wikidata_qid) = param_wikidata_qid { query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); } @@ -13858,6 +13870,130 @@ where } } + async fn lookup_editor( + &self, + param_username: Option, + context: &C, + ) -> Result { + let mut client_service = self.client_service.clone(); + let mut uri = format!("{}/v0/editor/lookup", self.base_path); + + // Query parameters + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_username) = param_username { + query_string.append_pair("username", ¶m_username.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { + uri += "?"; + uri += &query_string; + } + + let uri = match Uri::from_str(&uri) { + Ok(uri) => uri, + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), + }; + + let mut request = match Request::builder() + .method("GET") + .uri(uri) + .body(Body::empty()) + { + Ok(req) => req, + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), + }; + + let header = HeaderValue::from_str( + Has::::get(context) + .0 + .clone() + .to_string() + .as_str(), + ); + request.headers_mut().insert( + HeaderName::from_static("x-span-id"), + match header { + Ok(h) => h, + Err(e) => { + return Err(ApiError(format!( + "Unable to create X-Span ID header value: {}", + e + ))) + } + }, + ); + + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(body)?; + Ok(LookupEditorResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(body)?; + Ok(LookupEditorResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(body)?; + Ok(LookupEditorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(body)?; + Ok(LookupEditorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("", e), + }, + Err(e) => format!("", e), + } + ))) + } + } + } + async fn lookup_file( &self, param_md5: Option, @@ -14013,6 +14149,7 @@ where param_doaj: Option, param_dblp: Option, param_oai: Option, + param_hdl: Option, param_expand: Option, param_hide: Option, context: &C, @@ -14062,6 +14199,9 @@ where if let Some(param_oai) = param_oai { query_string.append_pair("oai", ¶m_oai.to_string()); } + if let Some(param_hdl) = param_hdl { + query_string.append_pair("hdl", ¶m_hdl.to_string()); + } if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } -- cgit v1.2.3