Skip to content

Commit 2cb4c3b

Browse files
authored
Merge pull request #498 from jacobtread/main
fix: create clip api method and change response type
2 parents 7e676ec + 376e100 commit 2cb4c3b

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/helix/endpoints/clips/create_clip.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! ## Response: [CreatedClip]
1616
//!
17-
//! Send the request to receive the response with [`HelixClient::req_get()`](helix::HelixClient::req_get).
17+
//! Send the request to receive the response with [`HelixClient::req_post()`](helix::HelixClient::req_post).
1818
//!
1919
//! ```rust, no_run
2020
//! use twitch_api::helix::{self, clips::create_clip};
@@ -25,16 +25,17 @@
2525
//! # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
2626
//! # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
2727
//! let request = create_clip::CreateClipRequest::broadcaster_id("1234");
28-
//! let response: Vec<create_clip::CreatedClip> = client.req_get(request, &token).await?.data;
28+
//! let body = helix::EmptyBody;
29+
//! let response: create_clip::CreatedClip = client.req_post(request, body, &token).await?.data;
2930
//! # Ok(())
3031
//! # }
3132
//! ```
3233
//!
33-
//! You can also get the [`http::Request`] with [`request.create_request(&token, &client_id)`](helix::RequestGet::create_request)
34+
//! You can also get the [`http::Request`] with [`request.create_request(&token, &client_id)`](helix::RequestPost::create_request)
3435
//! and parse the [`http::Response`] with [`CreateClipRequest::parse_response(None, &request.get_uri(), response)`](CreateClipRequest::parse_response)
3536
3637
use super::*;
37-
use helix::RequestGet;
38+
use helix::RequestPost;
3839

3940
/// Query Parameters for [Create Clip](super::create_clip)
4041
///
@@ -48,7 +49,7 @@ pub struct CreateClipRequest<'a> {
4849
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
4950
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
5051
pub broadcaster_id: Cow<'a, types::UserIdRef>,
51-
/// A Boolean value that determines whether the API captures the clip at the moment the viewer requests it or after a delay. If false (default), Twitch captures the clip at the moment the viewer requests it (this is the same clip experience as the Twitch UX). If true, Twitch adds a delay before capturing the clip
52+
/// A Boolean value that determines whether the API captures the clip at the moment the viewer requests it or after a delay. If false (default), Twitch captures the clip at the moment the viewer requests it (this is the same clip experience as the Twitch UX). If true, Twitch adds a delay before capturing the clip (this basically shifts the capture window to the right slightly).
5253
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
5354
pub has_delay: Option<bool>,
5455
}
@@ -76,22 +77,38 @@ impl<'a> CreateClipRequest<'a> {
7677
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
7778
#[non_exhaustive]
7879
pub struct CreatedClip {
79-
/// ID of the created clip.
80+
/// An ID that uniquely identifies the clip.
8081
pub id: types::ClipId,
8182
/// A URL that you can use to edit the clip’s title, identify the part of the clip to publish, and publish the clip.
83+
///
84+
/// The URL is valid for up to 24 hours or until the clip is published, whichever comes first.
8285
pub edit_url: String,
8386
}
8487

8588
impl Request for CreateClipRequest<'_> {
86-
type Response = Vec<CreatedClip>;
89+
type Response = CreatedClip;
8790

8891
const PATH: &'static str = "clips";
8992
#[cfg(feature = "twitch_oauth2")]
9093
const SCOPE: twitch_oauth2::Validator =
9194
twitch_oauth2::validator![twitch_oauth2::Scope::ClipsEdit];
9295
}
9396

94-
impl RequestGet for CreateClipRequest<'_> {}
97+
impl RequestPost for CreateClipRequest<'_> {
98+
type Body = helix::EmptyBody;
99+
100+
fn parse_inner_response(
101+
request: Option<Self>,
102+
uri: &http::Uri,
103+
response: &str,
104+
status: http::StatusCode,
105+
) -> Result<helix::Response<Self, <Self as Request>::Response>, helix::HelixRequestPostError>
106+
where
107+
Self: Sized,
108+
{
109+
helix::parse_single_return(request, uri, response, status)
110+
}
111+
}
95112

96113
#[cfg(test)]
97114
#[test]

0 commit comments

Comments
 (0)