Trait twitch_api::helix::RequestGet
source · [−]pub trait RequestGet: Request {
fn create_request(
&self,
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>, HelixRequestGetError>
where
Self: Sized,
{ ... }
fn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestGetError>
where
Self: Sized,
{ ... }
}
Available on crate feature
helix
only.Expand description
Helix endpoint GETs information
Provided Methods
sourcefn create_request(
&self,
token: &str,
client_id: &str
) -> Result<Request<Bytes>, CreateRequestError>
fn create_request(
&self,
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 126)
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
pub async fn req_get<R, D, T>(
&'a self,
request: R,
token: &T,
) -> Result<Response<R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request<Response = D> + Request + RequestGet,
D: serde::de::DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
C: Send,
{
let req = request.create_request(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 49)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
pub async fn req_get_custom<'d, R, D, T>(
&'a self,
request: R,
token: &T,
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request + RequestGet,
D: serde::de::Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
{
let req = request.create_request(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 request = Some(request);
let uri = &uri;
let text = std::str::from_utf8(response.body()).map_err(|e| {
HelixRequestGetError::Utf8Error(response.body().clone(), e, uri.clone())
})?;
//eprintln!("\n\nmessage is ------------ {} ------------", text);
if let Ok(HelixRequestError {
error,
status,
message,
}) = parse_json::<HelixRequestError>(text, false)
{
return Err(HelixRequestGetError::Error {
error,
status: status.try_into().unwrap_or(http::StatusCode::BAD_REQUEST),
message,
uri: uri.clone(),
}
.into());
}
let response: CustomInnerResponse<'_> = crate::parse_json(text, true).map_err(|e| {
HelixRequestGetError::DeserializeError(
text.to_owned(),
e,
uri.clone(),
response.status(),
)
})?;
Ok(CustomResponse {
pagination: response.pagination.cursor,
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>, HelixRequestGetError>where
Self: Sized,
fn parse_response<B: Into<Bytes>>(
request: Option<Self>,
uri: &Uri,
response: Response<B>
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestGetError>where
Self: Sized,
Examples found in repository?
src/helix/client.rs (line 135)
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
pub async fn req_get<R, D, T>(
&'a self,
request: R,
token: &T,
) -> Result<Response<R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request<Response = D> + Request + RequestGet,
D: serde::de::DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
C: Send,
{
let req = request.create_request(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)
}
sourcefn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestGetError>where
Self: Sized,
fn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestGetError>where
Self: Sized,
Parse a response string into the response.
Examples found in repository?
src/helix/request.rs (line 419)
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
fn parse_response<B: Into<hyper::body::Bytes>>(
request: Option<Self>,
uri: &http::Uri,
response: http::Response<B>,
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestGetError>
where
Self: Sized,
{
let response: http::Response<hyper::body::Bytes> = response.map(|b| b.into());
let text = std::str::from_utf8(response.body().as_ref()).map_err(|e| {
HelixRequestGetError::Utf8Error(response.body().clone(), e, uri.clone())
})?;
//eprintln!("\n\nmessage is ------------ {} ------------", text);
if let Ok(HelixRequestError {
error,
status,
message,
}) = parse_json::<HelixRequestError>(text, false)
{
return Err(HelixRequestGetError::Error {
error,
status: status.try_into().unwrap_or(http::StatusCode::BAD_REQUEST),
message,
uri: uri.clone(),
});
}
<Self as RequestGet>::parse_inner_response(request, uri, text, response.status())
}
Implementors
impl RequestGet for GetBitsLeaderboardRequest
impl RequestGet for GetCheermotesRequest
impl RequestGet for GetChannelEditorsRequest
impl RequestGet for GetChannelInformationRequest
impl RequestGet for GetVipsRequest
impl RequestGet for GetChannelChatBadgesRequest
impl RequestGet for GetChannelEmotesRequest
impl RequestGet for GetChatSettingsRequest
impl RequestGet for GetChattersRequest
impl RequestGet for GetEmoteSetsRequest
impl RequestGet for GetGlobalChatBadgesRequest
impl RequestGet for GetGlobalEmotesRequest
impl RequestGet for GetUserChatColorRequest
impl RequestGet for GetClipsRequest
impl RequestGet for GetEventSubSubscriptionsRequest
Available on crate feature
eventsub
only.