Skip to content

Commit c379795

Browse files
authored
Merge pull request #503 from twitch-rs/refactor/req-in-response
refactor: Only include pagination data for paginated requests
2 parents e6e675a + fbeefb0 commit c379795

File tree

118 files changed

+275
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+275
-144
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- Removed surf dependency and related feature flags
1010
- Removed http-types dependency
11+
- The pagination state for helix requests was moved into a separate field (`pagination_data`). The type for this depends on the `Request`. Paginatable requests will use `PaginationState<Self>` while others will use `()`.
1112

1213
[Commits](https://github.com/twitch-rs/twitch_api/compare/v0.7.2...Unreleased)
1314

src/helix/client/client_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
782782
)
783783
.await?;
784784

785-
Ok(resp.total.unwrap_or(0))
785+
Ok(resp.pagination_data.total.unwrap_or(0))
786786
}
787787

788788
/// Get users followed channels

src/helix/endpoints/bits/get_bits_leaderboard.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub struct LeaderboardUser {
176176
}
177177

178178
impl Request for GetBitsLeaderboardRequest<'_> {
179+
type PaginationData = ();
179180
type Response = BitsLeaderboard;
180181

181182
const PATH: &'static str = "bits/leaderboard";
@@ -186,7 +187,7 @@ impl Request for GetBitsLeaderboardRequest<'_> {
186187

187188
impl RequestGet for GetBitsLeaderboardRequest<'_> {
188189
fn parse_inner_response(
189-
request: Option<Self>,
190+
_request: Option<Self>,
190191
uri: &http::Uri,
191192
response: &str,
192193
status: http::StatusCode,
@@ -215,9 +216,7 @@ impl RequestGet for GetBitsLeaderboardRequest<'_> {
215216
date_range: response.date_range,
216217
total: response.total,
217218
},
218-
None,
219-
request,
220-
Some(response.total),
219+
(),
221220
None,
222221
))
223222
}

src/helix/endpoints/bits/get_cheermotes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub struct CheermoteImageArray {
186186
pub struct Level(pub String);
187187

188188
impl Request for GetCheermotesRequest<'_> {
189+
type PaginationData = ();
189190
type Response = Vec<Cheermote>;
190191

191192
const PATH: &'static str = "bits/cheermotes";

src/helix/endpoints/ccls/get_content_classification_labels.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub struct ContentClassificationLabel {
8282
}
8383

8484
impl Request for GetContentClassificationLabelsRequest<'_> {
85+
type PaginationData = ();
8586
type Response = Vec<ContentClassificationLabel>;
8687

8788
const PATH: &'static str = "content_classification_labels";

src/helix/endpoints/channels/add_channel_vip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub enum AddChannelVipResponse {
8585
}
8686

8787
impl Request for AddChannelVipRequest<'_> {
88+
type PaginationData = ();
8889
type Response = AddChannelVipResponse;
8990

9091
const PATH: &'static str = "channels/vips";

src/helix/endpoints/channels/get_ad_schedule.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub struct AdSchedule {
9898
}
9999

100100
impl Request for GetAdScheduleRequest<'_> {
101+
type PaginationData = ();
101102
type Response = Option<AdSchedule>;
102103

103104
const PATH: &'static str = "channels/ads";
@@ -110,7 +111,7 @@ impl Request for GetAdScheduleRequest<'_> {
110111

111112
impl RequestGet for GetAdScheduleRequest<'_> {
112113
fn parse_inner_response(
113-
request: Option<Self>,
114+
_request: Option<Self>,
114115
uri: &http::Uri,
115116
str_response: &str,
116117
status: http::StatusCode,
@@ -159,9 +160,7 @@ impl RequestGet for GetAdScheduleRequest<'_> {
159160
};
160161
Ok(helix::Response::new(
161162
response.data.into_iter().next(),
162-
response.pagination.cursor,
163-
request,
164-
response.total,
163+
(),
165164
response.other,
166165
))
167166
}

src/helix/endpoints/channels/get_channel_editors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub struct Editor {
8484
}
8585

8686
impl Request for GetChannelEditorsRequest<'_> {
87+
type PaginationData = ();
8788
type Response = Vec<Editor>;
8889

8990
const PATH: &'static str = "channels/editors";

src/helix/endpoints/channels/get_channel_followers.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
//!
3939
//! You can also get the [`http::Request`] with [`request.create_request(&token, &client_id)`](helix::RequestGet::create_request)
4040
//! and parse the [`http::Response`] with [`GetChannelFollowersRequest::parse_response(None, &request.get_uri(), response)`](GetChannelFollowersRequest::parse_response)
41+
use crate::helix::PaginationState;
42+
4143
use super::*;
4244
use helix::RequestGet;
4345

@@ -119,6 +121,7 @@ pub struct Follower {
119121
}
120122

121123
impl Request for GetChannelFollowersRequest<'_> {
124+
type PaginationData = PaginationState<Self>;
122125
type Response = Vec<Follower>;
123126

124127
const PATH: &'static str = "channels/followers";

src/helix/endpoints/channels/get_channel_information.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub struct ChannelInformation {
119119
}
120120

121121
impl Request for GetChannelInformationRequest<'_> {
122+
type PaginationData = ();
122123
type Response = Vec<ChannelInformation>;
123124

124125
const PATH: &'static str = "channels";

0 commit comments

Comments
 (0)