Trait twitch_api::helix::RequestPatch
source · [−]pub trait RequestPatch: Request {
type Body: HelixRequestBody;
fn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPatchError>
where
Self: Sized;
fn create_request(
&self,
body: Self::Body,
token: &str,
client_id: &str
) -> Result<Request<Bytes>, CreateRequestError> { ... }
fn parse_response<B: Into<Bytes>>(
request: Option<Self>,
uri: &Uri,
response: Response<B>
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPatchError>
where
Self: Sized,
{ ... }
}
Available on crate feature
helix
only.Expand description
Helix endpoint PATCHs information
Required Associated Types
sourcetype Body: HelixRequestBody
type Body: HelixRequestBody
Body parameters
Required Methods
sourcefn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPatchError>where
Self: Sized,
fn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPatchError>where
Self: Sized,
Parse a response string into the response.
Provided Methods
sourcefn create_request(
&self,
body: Self::Body,
token: &str,
client_id: &str
) -> Result<Request<Bytes>, CreateRequestError>
fn create_request(
&self,
body: Self::Body,
token: &str,
client_id: &str
) -> Result<Request<Bytes>, CreateRequestError>
Create a http::Request
from this Request
in your client
Examples found in repository?
src/helix/client.rs (line 178)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
pub async fn req_patch<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T,
) -> Result<Response<R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request<Response = D> + Request + RequestPatch<Body = B>,
B: HelixRequestBody,
D: serde::de::DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
{
let req =
request.create_request(body, token.token().secret(), token.client_id().as_str())?;
let uri = req.uri().clone();
let response = self
.client
.req(req)
.await
.map_err(ClientRequestError::RequestError)?
.into_response_vec()
.await?;
<R>::parse_response(Some(request), &uri, response).map_err(Into::into)
}
More examples
src/helix/client/custom.rs (line 184)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
pub async fn req_patch_custom<'d, R, B, D, T, F>(
&'a self,
request: R,
body: B,
token: &T,
function: F,
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request + RequestPatch + RequestPatch<Body = B>,
B: HelixRequestBody,
D: serde::de::Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &http::Uri, &str, http::StatusCode) -> Result<(), HelixRequestPatchError>,
{
let req =
request.create_request(body, token.token().secret(), token.client_id().as_str())?;
let uri = req.uri().clone();
let response = self
.client
.req(req)
.await
.map_err(ClientRequestError::RequestError)?
.into_response_bytes()
.await?;
{
let uri = &uri;
let text = std::str::from_utf8(response.body()).map_err(|e| {
HelixRequestPatchError::Utf8Error(response.body().clone(), e, uri.clone())
})?;
if let Ok(HelixRequestError {
error,
status,
message,
}) = parse_json::<HelixRequestError>(text, false)
{
return Err(HelixRequestPatchError::Error {
error,
status: status.try_into().unwrap_or(http::StatusCode::BAD_REQUEST),
message,
uri: uri.clone(),
body: response.body().clone(),
}
.into());
}
function(&request, uri, text, response.status())?;
let response: CustomInnerResponse<'_> = crate::parse_json(text, true).map_err(|e| {
HelixRequestPatchError::DeserializeError(
text.to_owned(),
e,
uri.clone(),
response.status(),
)
})?;
Ok(CustomResponse {
pagination: response.pagination.cursor,
request: Some(request),
total: response.total,
other: response.other,
raw_data: response.data.to_owned(),
pd: <_>::default(),
})
}
}
sourcefn parse_response<B: Into<Bytes>>(
request: Option<Self>,
uri: &Uri,
response: Response<B>
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPatchError>where
Self: Sized,
fn parse_response<B: Into<Bytes>>(
request: Option<Self>,
uri: &Uri,
response: Response<B>
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPatchError>where
Self: Sized,
Examples found in repository?
src/helix/client.rs (line 187)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
pub async fn req_patch<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T,
) -> Result<Response<R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request<Response = D> + Request + RequestPatch<Body = B>,
B: HelixRequestBody,
D: serde::de::DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
{
let req =
request.create_request(body, token.token().secret(), token.client_id().as_str())?;
let uri = req.uri().clone();
let response = self
.client
.req(req)
.await
.map_err(ClientRequestError::RequestError)?
.into_response_vec()
.await?;
<R>::parse_response(Some(request), &uri, response).map_err(Into::into)
}