Trait twitch_api::helix::request::RequestPost
source · [−]pub trait RequestPost: Request {
type Body: HelixRequestBody;
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>, HelixRequestPostError>
where
Self: Sized,
{ ... }
fn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPostError>
where
Self: Sized,
{ ... }
}
Available on crate feature
helix
only.Expand description
Helix endpoint POSTs information
Required Associated Types
sourcetype Body: HelixRequestBody
type Body: HelixRequestBody
Body parameters
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 152)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
pub async fn req_post<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 + RequestPost<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 113)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
pub async fn req_post_custom<'d, R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T,
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as crate::HttpClient<'a>>::Error>>
where
R: Request + RequestPost + RequestPost<Body = B>,
B: HelixRequestBody,
D: serde::de::Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
{
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 request = Some(request);
let uri = &uri;
let text = std::str::from_utf8(response.body()).map_err(|e| {
HelixRequestPostError::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(HelixRequestPostError::Error {
error,
status: status.try_into().unwrap_or(http::StatusCode::BAD_REQUEST),
message,
uri: uri.clone(),
body: response.body().clone(),
}
.into());
}
let response: CustomInnerResponse<'_> = crate::parse_json(text, true).map_err(|e| {
HelixRequestPostError::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>, HelixRequestPostError>where
Self: Sized,
fn parse_response<B: Into<Bytes>>(
request: Option<Self>,
uri: &Uri,
response: Response<B>
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPostError>where
Self: Sized,
Examples found in repository?
src/helix/client.rs (line 161)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
pub async fn req_post<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 + RequestPost<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)
}
sourcefn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPostError>where
Self: Sized,
fn parse_inner_response(
request: Option<Self>,
uri: &Uri,
response: &str,
status: StatusCode
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPostError>where
Self: Sized,
Parse a response string into the response.
Examples found in repository?
src/helix/request.rs (line 106)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn parse_response<B: Into<hyper::body::Bytes>>(
// FIXME: Is this really needed? Its currently only used for error reporting.
request: Option<Self>,
uri: &http::Uri,
response: http::Response<B>,
) -> Result<Response<Self, <Self as Request>::Response>, HelixRequestPostError>
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| {
HelixRequestPostError::Utf8Error(response.body().clone(), e, uri.clone())
})?;
if let Ok(HelixRequestError {
error,
status,
message,
}) = parse_json::<HelixRequestError>(text, false)
{
return Err(HelixRequestPostError::Error {
error,
status: status.try_into().unwrap_or(http::StatusCode::BAD_REQUEST),
message,
uri: uri.clone(),
body: response.body().clone(),
});
}
<Self as RequestPost>::parse_inner_response(request, uri, text, response.status())
}
Implementors
sourceimpl RequestPost for AddChannelVipRequest<'_>
impl RequestPost for AddChannelVipRequest<'_>
sourceimpl RequestPost for AddChannelModeratorRequest<'_>
impl RequestPost for AddChannelModeratorRequest<'_>
sourceimpl RequestPost for StartARaidRequest<'_>
impl RequestPost for StartARaidRequest<'_>
sourceimpl<'a> RequestPost for StartCommercialRequest<'a>
impl<'a> RequestPost for StartCommercialRequest<'a>
type Body = StartCommercialBody<'a>
sourceimpl<'a> RequestPost for SendChatAnnouncementRequest<'a>
impl<'a> RequestPost for SendChatAnnouncementRequest<'a>
type Body = SendChatAnnouncementBody<'a>
sourceimpl<'a> RequestPost for AddBlockedTermRequest<'a>
impl<'a> RequestPost for AddBlockedTermRequest<'a>
type Body = AddBlockedTermBody<'a>
sourceimpl<'a> RequestPost for BanUserRequest<'a>
impl<'a> RequestPost for BanUserRequest<'a>
type Body = BanUserBody<'a>
sourceimpl<'a> RequestPost for CheckAutoModStatusRequest<'a>
impl<'a> RequestPost for CheckAutoModStatusRequest<'a>
type Body = &'a [&'a CheckAutoModStatusBody<'a>]
sourceimpl<'a> RequestPost for ManageHeldAutoModMessagesRequest<'a>
impl<'a> RequestPost for ManageHeldAutoModMessagesRequest<'a>
type Body = ManageHeldAutoModMessagesBody<'a>
sourceimpl<'a> RequestPost for CreateCustomRewardRequest<'a>
impl<'a> RequestPost for CreateCustomRewardRequest<'a>
type Body = CreateCustomRewardBody<'a>
sourceimpl<'a> RequestPost for CreatePollRequest<'a>
impl<'a> RequestPost for CreatePollRequest<'a>
type Body = CreatePollBody<'a>
sourceimpl<'a> RequestPost for CreatePredictionRequest<'a>
impl<'a> RequestPost for CreatePredictionRequest<'a>
type Body = CreatePredictionBody<'a>
sourceimpl<'a> RequestPost for CreateChannelStreamScheduleSegmentRequest<'a>
impl<'a> RequestPost for CreateChannelStreamScheduleSegmentRequest<'a>
type Body = CreateChannelStreamScheduleSegmentBody<'a>
sourceimpl<'a> RequestPost for SendWhisperRequest<'a>
impl<'a> RequestPost for SendWhisperRequest<'a>
type Body = SendWhisperBody<'a>
sourceimpl<E: EventSubscription> RequestPost for CreateEventSubSubscriptionRequest<E>
Available on crate feature eventsub
only.
impl<E: EventSubscription> RequestPost for CreateEventSubSubscriptionRequest<E>
Available on crate feature
eventsub
only.