From eb6993c6cc40e532cb1462e44408ed30db5244c0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 13 Sep 2019 11:27:09 -0700 Subject: rust codegen This re-ordered a lot of code, because several endpoints had their tags changed, but should be no actual change in behavior/spec. --- rust/fatcat-openapi/src/client.rs | 1502 ++++++++++++++++++------------------- 1 file changed, 751 insertions(+), 751 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 378c546f..65bf67a5 100644 --- a/rust/fatcat-openapi/src/client.rs +++ b/rust/fatcat-openapi/src/client.rs @@ -173,42 +173,36 @@ impl Client { } impl Api for Client { - fn create_container(&self, param_editgroup_id: String, param_entity: models::ContainerEntity, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/container", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn auth_check(&self, param_role: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_role = param_role.map_or_else(String::new, |query| format!("role={role}&", role = query.to_string())); - let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); + let url = format!("{}/v0/auth/check?{role}", self.base_path, role = utf8_percent_encode(&query_role, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); + let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER.clone())); 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 { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 201 => { + 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(CreateContainerResponse::CreatedEntity(body)) + Ok(AuthCheckResponse::Success(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(CreateContainerResponse::BadRequest(body)) + Ok(AuthCheckResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -220,7 +214,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(CreateContainerResponse::NotAuthorized { + Ok(AuthCheckResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -230,21 +224,14 @@ impl Api for Client { 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(CreateContainerResponse::Forbidden(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(CreateContainerResponse::NotFound(body)) + Ok(AuthCheckResponse::Forbidden(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(CreateContainerResponse::GenericError(body)) + Ok(AuthCheckResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -264,10 +251,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn create_container_auto_batch(&self, param_auto_batch: models::ContainerAutoBatch, context: &Context) -> Box + Send> { - let url = format!("{}/v0/editgroup/auto/container/batch", self.base_path); + fn auth_oidc(&self, param_oidc_params: models::AuthOidc, context: &Context) -> Box + Send> { + let url = format!("{}/v0/auth/oidc", self.base_path); - let body = serde_json::to_string(¶m_auto_batch).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_oidc_params).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -275,27 +262,34 @@ impl Api for Client { let request = request.body(&body); - custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER_AUTO_BATCH.clone())); + custom_headers.set(ContentType(mimetypes::requests::AUTH_OIDC.clone())); 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 { + 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(AuthOidcResponse::Found(body)) + } 201 => { 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(CreateContainerAutoBatchResponse::CreatedEditgroup(body)) + Ok(AuthOidcResponse::Created(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(CreateContainerAutoBatchResponse::BadRequest(body)) + Ok(AuthOidcResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -307,7 +301,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(CreateContainerAutoBatchResponse::NotAuthorized { + Ok(AuthOidcResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -317,21 +311,21 @@ impl Api for Client { 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(CreateContainerAutoBatchResponse::Forbidden(body)) + Ok(AuthOidcResponse::Forbidden(body)) } - 404 => { + 409 => { 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(CreateContainerAutoBatchResponse::NotFound(body)) + Ok(AuthOidcResponse::Conflict(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(CreateContainerAutoBatchResponse::GenericError(body)) + Ok(AuthOidcResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -351,16 +345,14 @@ impl Api for Client { Box::new(futures::done(result)) } - fn delete_container(&self, param_editgroup_id: String, param_ident: String, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/container/{ident}", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), - ident = utf8_percent_encode(¶m_ident.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn get_changelog(&self, param_limit: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + + let url = format!("{}/v0/changelog?{limit}", self.base_path, limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Delete, &url); + 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()))); @@ -368,57 +360,92 @@ impl Api for Client { 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 { + 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)?; + let body = serde_json::from_str::>(&buf)?; - Ok(DeleteContainerResponse::DeletedEntity(body)) + Ok(GetChangelogResponse::Success(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(DeleteContainerResponse::BadRequest(body)) + Ok(GetChangelogResponse::BadRequest(body)) } - 401 => { + 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)?; - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - let response_www_authenticate = response - .headers - .get::() - .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(DeleteContainerResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) + Ok(GetChangelogResponse::GenericError(body)) } - 403 => { + 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 get_changelog_entry(&self, param_index: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/changelog/{index}", + self.base_path, + index = utf8_percent_encode(¶m_index.to_string(), PATH_SEGMENT_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(GetChangelogEntryResponse::FoundChangelogEntry(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(DeleteContainerResponse::Forbidden(body)) + Ok(GetChangelogEntryResponse::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(DeleteContainerResponse::NotFound(body)) + Ok(GetChangelogEntryResponse::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(DeleteContainerResponse::GenericError(body)) + Ok(GetChangelogEntryResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -438,38 +465,42 @@ impl Api for Client { Box::new(futures::done(result)) } - fn delete_container_edit(&self, param_editgroup_id: String, param_edit_id: String, context: &Context) -> Box + Send> { + fn create_container(&self, param_editgroup_id: String, param_entity: models::ContainerEntity, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}", + "{}/v0/editgroup/{editgroup_id}/container", self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), - edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); + let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Delete, &url); + let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER.clone())); 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 { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 200 => { + 201 => { 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(DeleteContainerEditResponse::DeletedEdit(body)) + Ok(CreateContainerResponse::CreatedEntity(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(DeleteContainerEditResponse::BadRequest(body)) + Ok(CreateContainerResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -481,7 +512,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(DeleteContainerEditResponse::NotAuthorized { + Ok(CreateContainerResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -491,21 +522,21 @@ impl Api for Client { 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(DeleteContainerEditResponse::Forbidden(body)) + Ok(CreateContainerResponse::Forbidden(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(DeleteContainerEditResponse::NotFound(body)) + Ok(CreateContainerResponse::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(DeleteContainerEditResponse::GenericError(body)) + Ok(CreateContainerResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -525,57 +556,74 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_container(&self, param_ident: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { - // Query parameters - 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())); + fn create_container_auto_batch(&self, param_auto_batch: models::ContainerAutoBatch, context: &Context) -> Box + Send> { + let url = format!("{}/v0/editgroup/auto/container/batch", self.base_path); - let url = format!( - "{}/v0/container/{ident}?{expand}{hide}", - self.base_path, - ident = utf8_percent_encode(¶m_ident.to_string(), PATH_SEGMENT_ENCODE_SET), - expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), - hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) - ); + let body = serde_json::to_string(¶m_auto_batch).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER_AUTO_BATCH.clone())); 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 { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 200 => { + 201 => { 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetContainerResponse::FoundEntity(body)) + Ok(CreateContainerAutoBatchResponse::CreatedEditgroup(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(GetContainerResponse::BadRequest(body)) + Ok(CreateContainerAutoBatchResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(CreateContainerAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(CreateContainerAutoBatchResponse::Forbidden(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(GetContainerResponse::NotFound(body)) + Ok(CreateContainerAutoBatchResponse::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(GetContainerResponse::GenericError(body)) + Ok(CreateContainerAutoBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -595,15 +643,16 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_container_edit(&self, param_edit_id: String, context: &Context) -> Box + Send> { + fn delete_container(&self, param_editgroup_id: String, param_ident: String, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/container/edit/{edit_id}", + "{}/v0/editgroup/{editgroup_id}/container/{ident}", self.base_path, - edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + ident = utf8_percent_encode(¶m_ident.to_string(), PATH_SEGMENT_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + let request = hyper_client.request(hyper::method::Method::Delete, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); @@ -611,14 +660,257 @@ impl Api for Client { 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 { + 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(GetContainerEditResponse::FoundEdit(body)) + Ok(DeleteContainerResponse::DeletedEntity(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(DeleteContainerResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(DeleteContainerResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(DeleteContainerResponse::Forbidden(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(DeleteContainerResponse::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(DeleteContainerResponse::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 delete_container_edit(&self, param_editgroup_id: String, param_edit_id: String, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Delete, &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(DeleteContainerEditResponse::DeletedEdit(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(DeleteContainerEditResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(DeleteContainerEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(DeleteContainerEditResponse::Forbidden(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(DeleteContainerEditResponse::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(DeleteContainerEditResponse::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 get_container(&self, param_ident: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { + // Query parameters + 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/{ident}?{expand}{hide}", + self.base_path, + ident = utf8_percent_encode(¶m_ident.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), + hide = utf8_percent_encode(&query_hide, 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(GetContainerResponse::FoundEntity(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(GetContainerResponse::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(GetContainerResponse::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(GetContainerResponse::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 get_container_edit(&self, param_edit_id: String, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/container/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_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(GetContainerEditResponse::FoundEdit(body)) } 400 => { let mut buf = String::new(); @@ -1985,14 +2277,15 @@ impl Api for Client { Box::new(futures::done(result)) } - fn auth_check(&self, param_role: Option, context: &Context) -> Box + Send> { - // Query parameters - let query_role = param_role.map_or_else(String::new, |query| format!("role={role}&", role = query.to_string())); - - let url = format!("{}/v0/auth/check?{role}", self.base_path, role = utf8_percent_encode(&query_role, QUERY_ENCODE_SET)); + fn accept_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/accept", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); @@ -2000,21 +2293,21 @@ impl Api for Client { 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 { + 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(AuthCheckResponse::Success(body)) + Ok(AcceptEditgroupResponse::MergedSuccessfully(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(AuthCheckResponse::BadRequest(body)) + Ok(AcceptEditgroupResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -2026,7 +2319,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(AuthCheckResponse::NotAuthorized { + Ok(AcceptEditgroupResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -2036,14 +2329,28 @@ impl Api for Client { 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(AuthCheckResponse::Forbidden(body)) + Ok(AcceptEditgroupResponse::Forbidden(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(AcceptEditgroupResponse::NotFound(body)) + } + 409 => { + 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(AcceptEditgroupResponse::EditConflict(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(AuthCheckResponse::GenericError(body)) + Ok(AcceptEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2063,10 +2370,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn auth_oidc(&self, param_oidc_params: models::AuthOidc, context: &Context) -> Box + Send> { - let url = format!("{}/v0/auth/oidc", self.base_path); + fn create_editgroup(&self, param_editgroup: models::Editgroup, context: &Context) -> Box + Send> { + let url = format!("{}/v0/editgroup", self.base_path); - let body = serde_json::to_string(¶m_oidc_params).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_editgroup).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -2074,34 +2381,123 @@ impl Api for Client { let request = request.body(&body); - custom_headers.set(ContentType(mimetypes::requests::AUTH_OIDC.clone())); + custom_headers.set(ContentType(mimetypes::requests::CREATE_EDITGROUP.clone())); 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 { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 200 => { + 201 => { 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(AuthOidcResponse::Found(body)) + Ok(CreateEditgroupResponse::SuccessfullyCreated(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(CreateEditgroupResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(CreateEditgroupResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(CreateEditgroupResponse::Forbidden(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(CreateEditgroupResponse::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(CreateEditgroupResponse::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 create_editgroup_annotation( + &self, + param_editgroup_id: String, + param_annotation: models::EditgroupAnnotation, + context: &Context, + ) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/annotation", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let body = serde_json::to_string(¶m_annotation).expect("impossible to fail to serialize"); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Post, &url); + let mut custom_headers = hyper::header::Headers::new(); + + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::CREATE_EDITGROUP_ANNOTATION.clone())); + 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() { 201 => { 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(AuthOidcResponse::Created(body)) + Ok(CreateEditgroupAnnotationResponse::Created(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(AuthOidcResponse::BadRequest(body)) + Ok(CreateEditgroupAnnotationResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -2113,7 +2509,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(AuthOidcResponse::NotAuthorized { + Ok(CreateEditgroupAnnotationResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -2123,21 +2519,21 @@ impl Api for Client { 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(AuthOidcResponse::Forbidden(body)) + Ok(CreateEditgroupAnnotationResponse::Forbidden(body)) } - 409 => { + 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(AuthOidcResponse::Conflict(body)) + Ok(CreateEditgroupAnnotationResponse::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(AuthOidcResponse::GenericError(body)) + Ok(CreateEditgroupAnnotationResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2157,27 +2553,11 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editgroups_reviewable( - &self, - param_expand: Option, - param_limit: Option, - param_before: Option>, - param_since: Option>, - context: &Context, - ) -> Box + Send> { - // Query parameters - let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); - let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); - let query_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); - let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); - + fn get_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/editgroup/reviewable?{expand}{limit}{before}{since}", + "{}/v0/editgroup/{editgroup_id}", self.base_path, - expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), - limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), - before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), - since = utf8_percent_encode(&query_since, QUERY_ENCODE_SET) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); @@ -2189,35 +2569,35 @@ impl Api for Client { 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 { + 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetEditgroupsReviewableResponse::Found(body)) + Ok(GetEditgroupResponse::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(GetEditgroupsReviewableResponse::BadRequest(body)) + Ok(GetEditgroupResponse::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(GetEditgroupsReviewableResponse::NotFound(body)) + Ok(GetEditgroupResponse::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(GetEditgroupsReviewableResponse::GenericError(body)) + Ok(GetEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2237,11 +2617,15 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editor(&self, param_editor_id: String, context: &Context) -> Box + Send> { + fn get_editgroup_annotations(&self, param_editgroup_id: String, param_expand: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); + let url = format!( - "{}/v0/editor/{editor_id}", + "{}/v0/editgroup/{editgroup_id}/annotations?{expand}", self.base_path, - editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); @@ -2253,35 +2637,57 @@ impl Api for Client { 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 { + 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)?; + let body = serde_json::from_str::>(&buf)?; - Ok(GetEditorResponse::Found(body)) + Ok(GetEditgroupAnnotationsResponse::Success(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(GetEditorResponse::BadRequest(body)) + Ok(GetEditgroupAnnotationsResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(GetEditgroupAnnotationsResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(GetEditgroupAnnotationsResponse::Forbidden(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(GetEditorResponse::NotFound(body)) + Ok(GetEditgroupAnnotationsResponse::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(GetEditorResponse::GenericError(body)) + Ok(GetEditgroupAnnotationsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2301,23 +2707,24 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editor_editgroups( + fn get_editgroups_reviewable( &self, - param_editor_id: String, + param_expand: Option, param_limit: Option, param_before: Option>, param_since: Option>, context: &Context, - ) -> Box + Send> { + ) -> Box + Send> { // Query parameters + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); let query_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); let url = format!( - "{}/v0/editor/{editor_id}/editgroups?{limit}{before}{since}", + "{}/v0/editgroup/reviewable?{expand}{limit}{before}{since}", self.base_path, - editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), since = utf8_percent_encode(&query_since, QUERY_ENCODE_SET) @@ -2332,35 +2739,35 @@ impl Api for Client { 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 { + 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(GetEditorEditgroupsResponse::Found(body)) + Ok(GetEditgroupsReviewableResponse::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(GetEditorEditgroupsResponse::BadRequest(body)) + Ok(GetEditgroupsReviewableResponse::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(GetEditorEditgroupsResponse::NotFound(body)) + Ok(GetEditgroupsReviewableResponse::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(GetEditorEditgroupsResponse::GenericError(body)) + Ok(GetEditgroupsReviewableResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2481,78 +2888,51 @@ impl Api for Client { Box::new(futures::done(result)) } - fn update_editor(&self, param_editor_id: String, param_editor: models::Editor, context: &Context) -> Box + Send> { + fn get_editor(&self, param_editor_id: String, context: &Context) -> Box + Send> { let url = format!( "{}/v0/editor/{editor_id}", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let body = serde_json::to_string(¶m_editor).expect("impossible to fail to serialize"); - let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Put, &url); + let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::UPDATE_EDITOR.clone())); 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 { + 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(UpdateEditorResponse::UpdatedEditor(body)) + Ok(GetEditorResponse::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(UpdateEditorResponse::BadRequest(body)) - } - 401 => { - 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)?; - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - let response_www_authenticate = response - .headers - .get::() - .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - - Ok(UpdateEditorResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) - } - 403 => { - 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(UpdateEditorResponse::Forbidden(body)) + Ok(GetEditorResponse::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(UpdateEditorResponse::NotFound(body)) + Ok(GetEditorResponse::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(UpdateEditorResponse::GenericError(body)) + Ok(GetEditorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2572,15 +2952,30 @@ impl Api for Client { Box::new(futures::done(result)) } - fn accept_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { + fn get_editor_annotations( + &self, + param_editor_id: String, + param_limit: Option, + param_before: Option>, + param_since: Option>, + context: &Context, + ) -> Box + Send> { + // Query parameters + let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + let query_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); + let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); + let url = format!( - "{}/v0/editgroup/{editgroup_id}/accept", + "{}/v0/editor/{editor_id}/annotations?{limit}{before}{since}", self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), + before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), + since = utf8_percent_encode(&query_since, QUERY_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); + 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()))); @@ -2588,115 +2983,21 @@ impl Api for Client { 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 { + 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(AcceptEditgroupResponse::MergedSuccessfully(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(AcceptEditgroupResponse::BadRequest(body)) - } - 401 => { - 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)?; - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - let response_www_authenticate = response - .headers - .get::() - .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - - Ok(AcceptEditgroupResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) - } - 403 => { - 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(AcceptEditgroupResponse::Forbidden(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(AcceptEditgroupResponse::NotFound(body)) - } - 409 => { - 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(AcceptEditgroupResponse::EditConflict(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(AcceptEditgroupResponse::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 create_editgroup(&self, param_editgroup: models::Editgroup, context: &Context) -> Box + Send> { - let url = format!("{}/v0/editgroup", self.base_path); - - let body = serde_json::to_string(¶m_editgroup).expect("impossible to fail to serialize"); - - let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); - let mut custom_headers = hyper::header::Headers::new(); - - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::CREATE_EDITGROUP.clone())); - 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() { - 201 => { - 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)?; + let body = serde_json::from_str::>(&buf)?; - Ok(CreateEditgroupResponse::SuccessfullyCreated(body)) + Ok(GetEditorAnnotationsResponse::Success(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(CreateEditgroupResponse::BadRequest(body)) + Ok(GetEditorAnnotationsResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -2708,7 +3009,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(CreateEditgroupResponse::NotAuthorized { + Ok(GetEditorAnnotationsResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -2718,21 +3019,21 @@ impl Api for Client { 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(CreateEditgroupResponse::Forbidden(body)) + Ok(GetEditorAnnotationsResponse::Forbidden(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(CreateEditgroupResponse::NotFound(body)) + Ok(GetEditorAnnotationsResponse::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(CreateEditgroupResponse::GenericError(body)) + Ok(GetEditorAnnotationsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2752,357 +3053,66 @@ impl Api for Client { Box::new(futures::done(result)) } - fn create_editgroup_annotation( + fn get_editor_editgroups( &self, - param_editgroup_id: String, - param_annotation: models::EditgroupAnnotation, + param_editor_id: String, + param_limit: Option, + param_before: Option>, + param_since: Option>, context: &Context, - ) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/annotation", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); - - let body = serde_json::to_string(¶m_annotation).expect("impossible to fail to serialize"); - - let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); - let mut custom_headers = hyper::header::Headers::new(); - - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::CREATE_EDITGROUP_ANNOTATION.clone())); - 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() { - 201 => { - 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(CreateEditgroupAnnotationResponse::Created(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(CreateEditgroupAnnotationResponse::BadRequest(body)) - } - 401 => { - 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)?; - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - let response_www_authenticate = response - .headers - .get::() - .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - - Ok(CreateEditgroupAnnotationResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) - } - 403 => { - 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(CreateEditgroupAnnotationResponse::Forbidden(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(CreateEditgroupAnnotationResponse::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(CreateEditgroupAnnotationResponse::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 get_changelog(&self, param_limit: Option, context: &Context) -> Box + Send> { + ) -> Box + Send> { // Query parameters let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); - - let url = format!("{}/v0/changelog?{limit}", self.base_path, limit = utf8_percent_encode(&query_limit, 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(GetChangelogResponse::Success(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(GetChangelogResponse::BadRequest(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(GetChangelogResponse::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 get_changelog_entry(&self, param_index: i64, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/changelog/{index}", - self.base_path, - index = utf8_percent_encode(¶m_index.to_string(), PATH_SEGMENT_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(GetChangelogEntryResponse::FoundChangelogEntry(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(GetChangelogEntryResponse::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(GetChangelogEntryResponse::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(GetChangelogEntryResponse::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 get_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_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(GetEditgroupResponse::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(GetEditgroupResponse::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(GetEditgroupResponse::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(GetEditgroupResponse::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 get_editgroup_annotations(&self, param_editgroup_id: String, param_expand: Option, context: &Context) -> Box + Send> { - // Query parameters - let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); + let query_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); + let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); let url = format!( - "{}/v0/editgroup/{editgroup_id}/annotations?{expand}", + "{}/v0/editor/{editor_id}/editgroups?{limit}{before}{since}", self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), - expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET) + editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), + before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), + since = utf8_percent_encode(&query_since, 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(GetEditgroupAnnotationsResponse::Success(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)?; + context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - Ok(GetEditgroupAnnotationsResponse::BadRequest(body)) - } - 401 => { + 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)?; - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - let response_www_authenticate = response - .headers - .get::() - .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + let body = serde_json::from_str::>(&buf)?; - Ok(GetEditgroupAnnotationsResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) + Ok(GetEditorEditgroupsResponse::Found(body)) } - 403 => { + 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(GetEditgroupAnnotationsResponse::Forbidden(body)) + Ok(GetEditorEditgroupsResponse::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(GetEditgroupAnnotationsResponse::NotFound(body)) + Ok(GetEditorEditgroupsResponse::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(GetEditgroupAnnotationsResponse::GenericError(body)) + Ok(GetEditorEditgroupsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -3122,52 +3132,42 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editor_annotations( - &self, - param_editor_id: String, - param_limit: Option, - param_before: Option>, - param_since: Option>, - context: &Context, - ) -> Box + Send> { - // Query parameters - let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); - let query_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); - let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); - + fn update_editor(&self, param_editor_id: String, param_editor: models::Editor, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/editor/{editor_id}/annotations?{limit}{before}{since}", + "{}/v0/editor/{editor_id}", self.base_path, - editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), - limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), - before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), - since = utf8_percent_encode(&query_since, QUERY_ENCODE_SET) + editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); + let body = serde_json::to_string(¶m_editor).expect("impossible to fail to serialize"); + let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + let request = hyper_client.request(hyper::method::Method::Put, &url); let mut custom_headers = hyper::header::Headers::new(); + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::UPDATE_EDITOR.clone())); 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 { + 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetEditorAnnotationsResponse::Success(body)) + Ok(UpdateEditorResponse::UpdatedEditor(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(GetEditorAnnotationsResponse::BadRequest(body)) + Ok(UpdateEditorResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -3179,7 +3179,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(GetEditorAnnotationsResponse::NotAuthorized { + Ok(UpdateEditorResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -3189,21 +3189,21 @@ impl Api for Client { 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(GetEditorAnnotationsResponse::Forbidden(body)) + Ok(UpdateEditorResponse::Forbidden(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(GetEditorAnnotationsResponse::NotFound(body)) + Ok(UpdateEditorResponse::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(GetEditorAnnotationsResponse::GenericError(body)) + Ok(UpdateEditorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -5062,97 +5062,6 @@ impl Api for Client { Box::new(futures::done(result)) } - fn create_work(&self, param_editgroup_id: String, param_entity: models::WorkEntity, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/work", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); - - let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); - - let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); - let mut custom_headers = hyper::header::Headers::new(); - - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::CREATE_WORK.clone())); - 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() { - 201 => { - 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(CreateWorkResponse::CreatedEntity(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(CreateWorkResponse::BadRequest(body)) - } - 401 => { - 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)?; - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - let response_www_authenticate = response - .headers - .get::() - .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - - Ok(CreateWorkResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) - } - 403 => { - 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(CreateWorkResponse::Forbidden(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(CreateWorkResponse::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(CreateWorkResponse::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 delete_release(&self, param_editgroup_id: String, param_ident: String, context: &Context) -> Box + Send> { let url = format!( "{}/v0/editgroup/{editgroup_id}/release/{ident}", @@ -6867,6 +6776,97 @@ impl Api for Client { Box::new(futures::done(result)) } + fn create_work(&self, param_editgroup_id: String, param_entity: models::WorkEntity, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/work", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Post, &url); + let mut custom_headers = hyper::header::Headers::new(); + + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::CREATE_WORK.clone())); + 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() { + 201 => { + 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(CreateWorkResponse::CreatedEntity(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(CreateWorkResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(CreateWorkResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(CreateWorkResponse::Forbidden(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(CreateWorkResponse::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(CreateWorkResponse::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 create_work_auto_batch(&self, param_auto_batch: models::WorkAutoBatch, context: &Context) -> Box + Send> { let url = format!("{}/v0/editgroup/auto/work/batch", self.base_path); -- cgit v1.2.3