From 3a45076685471b969596ef5b58823ce8074224c6 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 12 Oct 2021 16:45:07 -0700 Subject: rust codegen for v0.4 --- rust/fatcat-openapi/src/client.rs | 84 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) (limited to 'rust/fatcat-openapi/src/client.rs') diff --git a/rust/fatcat-openapi/src/client.rs b/rust/fatcat-openapi/src/client.rs index fdb03405..85cec698 100644 --- a/rust/fatcat-openapi/src/client.rs +++ b/rust/fatcat-openapi/src/client.rs @@ -46,8 +46,9 @@ use crate::{ GetFilesetEditResponse, GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, GetWorkRedirectsResponse, - GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, - UpdateCreatorResponse, UpdateEditgroupResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, UpdateWorkResponse, + GetWorkReleasesResponse, GetWorkResponse, 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. @@ -1245,6 +1246,9 @@ impl Api for Client { 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, @@ -1252,14 +1256,20 @@ impl Api for Client { ) -> Box + Send> { // Query parameters let query_issnl = param_issnl.map_or_else(String::new, |query| format!("issnl={issnl}&", issnl = query.to_string())); + let query_issne = param_issne.map_or_else(String::new, |query| format!("issne={issne}&", issne = query.to_string())); + let query_issnp = param_issnp.map_or_else(String::new, |query| format!("issnp={issnp}&", issnp = query.to_string())); + let query_issn = param_issn.map_or_else(String::new, |query| format!("issn={issn}&", issn = query.to_string())); let query_wikidata_qid = param_wikidata_qid.map_or_else(String::new, |query| format!("wikidata_qid={wikidata_qid}&", wikidata_qid = query.to_string())); let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/container/lookup?{issnl}{wikidata_qid}{expand}{hide}", + "{}/v0/container/lookup?{issnl}{issne}{issnp}{issn}{wikidata_qid}{expand}{hide}", self.base_path, issnl = utf8_percent_encode(&query_issnl, QUERY_ENCODE_SET), + issne = utf8_percent_encode(&query_issne, QUERY_ENCODE_SET), + issnp = utf8_percent_encode(&query_issnp, QUERY_ENCODE_SET), + issn = utf8_percent_encode(&query_issn, QUERY_ENCODE_SET), wikidata_qid = utf8_percent_encode(&query_wikidata_qid, QUERY_ENCODE_SET), expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) @@ -3215,6 +3225,69 @@ impl Api for Client { Box::new(futures::done(result)) } + fn lookup_editor(&self, param_username: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_username = param_username.map_or_else(String::new, |query| format!("username={username}&", username = query.to_string())); + + let url = format!("{}/v0/editor/lookup?{username}", self.base_path, username = utf8_percent_encode(&query_username, QUERY_ENCODE_SET)); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Get, &url); + let mut custom_headers = hyper::header::Headers::new(); + + context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); + + let request = request.headers(custom_headers); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn parse_response(mut response: hyper::client::response::Response) -> Result { + match response.status.to_u16() { + 200 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(LookupEditorResponse::Found(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(LookupEditorResponse::BadRequest(body)) + } + 404 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(LookupEditorResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(LookupEditorResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) + } + } + } + + let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + Box::new(futures::done(result)) + } + fn update_editor(&self, param_editor_id: String, param_editor: models::Editor, context: &Context) -> Box + Send> { let url = format!( "{}/v0/editor/{editor_id}", @@ -5880,6 +5953,7 @@ impl Api for Client { param_doaj: Option, param_dblp: Option, param_oai: Option, + param_hdl: Option, param_expand: Option, param_hide: Option, context: &Context, @@ -5898,11 +5972,12 @@ impl Api for Client { let query_doaj = param_doaj.map_or_else(String::new, |query| format!("doaj={doaj}&", doaj = query.to_string())); let query_dblp = param_dblp.map_or_else(String::new, |query| format!("dblp={dblp}&", dblp = query.to_string())); let query_oai = param_oai.map_or_else(String::new, |query| format!("oai={oai}&", oai = query.to_string())); + let query_hdl = param_hdl.map_or_else(String::new, |query| format!("hdl={hdl}&", hdl = query.to_string())); let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/release/lookup?{doi}{wikidata_qid}{isbn13}{pmid}{pmcid}{core}{arxiv}{jstor}{ark}{mag}{doaj}{dblp}{oai}{expand}{hide}", + "{}/v0/release/lookup?{doi}{wikidata_qid}{isbn13}{pmid}{pmcid}{core}{arxiv}{jstor}{ark}{mag}{doaj}{dblp}{oai}{hdl}{expand}{hide}", self.base_path, doi = utf8_percent_encode(&query_doi, QUERY_ENCODE_SET), wikidata_qid = utf8_percent_encode(&query_wikidata_qid, QUERY_ENCODE_SET), @@ -5917,6 +5992,7 @@ impl Api for Client { doaj = utf8_percent_encode(&query_doaj, QUERY_ENCODE_SET), dblp = utf8_percent_encode(&query_dblp, QUERY_ENCODE_SET), oai = utf8_percent_encode(&query_oai, QUERY_ENCODE_SET), + hdl = utf8_percent_encode(&query_hdl, QUERY_ENCODE_SET), expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); -- cgit v1.2.3