diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-10-13 17:42:41 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-10-13 17:42:41 -0700 |
commit | 0a71247fb61a91c1f6d519762013c1445713a728 (patch) | |
tree | cbade44d03cd523478a0a821d92504c99376e12b /fatcat-openapi/src/client | |
parent | 052581220de7018d8ccbfe62eb18d8b01a82b83d (diff) | |
download | fatcat-cli-0a71247fb61a91c1f6d519762013c1445713a728.tar.gz fatcat-cli-0a71247fb61a91c1f6d519762013c1445713a728.zip |
codegen for API schema v0.4.0
Diffstat (limited to 'fatcat-openapi/src/client')
-rw-r--r-- | fatcat-openapi/src/client/mod.rs | 148 |
1 files changed, 144 insertions, 4 deletions
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<String>, + param_issne: Option<String>, + param_issnp: Option<String>, + param_issn: Option<String>, param_wikidata_qid: Option<String>, param_expand: Option<String>, param_hide: Option<String>, @@ -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<String>, + context: &C, + ) -> Result<LookupEditorResponse, ApiError> { + 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::<XSpanIdString>::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::<models::Editor>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) + } + } + } + async fn lookup_file( &self, param_md5: Option<String>, @@ -14013,6 +14149,7 @@ where param_doaj: Option<String>, param_dblp: Option<String>, param_oai: Option<String>, + param_hdl: Option<String>, param_expand: Option<String>, param_hide: Option<String>, 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()); } |