Skip to content

Commit 0882d9e

Browse files
authored
Merge pull request #369 from twitch-rs/response-create
Make it possible to construct a Response
2 parents 35e2f36 + a45cc9b commit 0882d9e

Some content is hidden

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

44 files changed

+290
-277
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- Added `Get Shield Mode Status` and `Update Shield Mode Status`
6969
- Added `channel.shield_mode.begin` and `channel.shield_mode.end` EventSub events
7070
- Added `tower` implementation for `HttpClient`
71+
- Added `helix::Response::new` and `helix::Response::with_data` to make it possible to create your own responses.
7172

7273
### Fixed
7374

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ reorder_impl_items = true
77
edition = "2018"
88
newline_style = "Unix"
99
format_code_in_doc_comments = true
10-
doc_comment_code_block_width = 80
10+
doc_comment_code_block_width = 80

src/helix/endpoints/bits/get_bits_leaderboard.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ impl RequestGet for GetBitsLeaderboardRequest<'_> {
185185
status,
186186
)
187187
})?;
188-
Ok(helix::Response {
189-
data: BitsLeaderboard {
188+
Ok(helix::Response::new(
189+
BitsLeaderboard {
190190
leaderboard: response.data,
191191
date_range: response.date_range,
192192
total: response.total,
193193
},
194-
pagination: None,
194+
None,
195195
request,
196-
total: Some(response.total),
197-
other: None,
198-
})
196+
Some(response.total),
197+
None,
198+
))
199199
}
200200
}
201201

src/helix/endpoints/channels/add_channel_vip.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,10 @@ impl RequestPost for AddChannelVipRequest<'_> {
9999
Self: Sized,
100100
{
101101
match status {
102-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
103-
data: AddChannelVipResponse::Success,
104-
pagination: None,
102+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
103+
AddChannelVipResponse::Success,
105104
request,
106-
total: None,
107-
other: None,
108-
}),
105+
)),
109106
_ => Err(helix::HelixRequestPostError::InvalidResponse {
110107
reason: "unexpected status",
111108
response: response.to_string(),

src/helix/endpoints/channels/modify_channel_information.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,18 @@ impl<'a> RequestPatch for ModifyChannelInformationRequest<'a> {
194194
where
195195
Self: Sized,
196196
{
197-
Ok(helix::Response {
198-
data: match status {
199-
http::StatusCode::NO_CONTENT | http::StatusCode::OK => {
200-
ModifyChannelInformation::Success
201-
}
202-
_ => {
203-
return Err(helix::HelixRequestPatchError::InvalidResponse {
204-
reason: "unexpected status code",
205-
response: response.to_string(),
206-
status,
207-
uri: uri.clone(),
208-
})
209-
}
210-
},
211-
pagination: None,
212-
request,
213-
total: None,
214-
other: None,
215-
})
197+
match status {
198+
http::StatusCode::NO_CONTENT | http::StatusCode::OK => Ok(helix::Response::with_data(
199+
ModifyChannelInformation::Success,
200+
request,
201+
)),
202+
_ => Err(helix::HelixRequestPatchError::InvalidResponse {
203+
reason: "unexpected status code",
204+
response: response.to_string(),
205+
status,
206+
uri: uri.clone(),
207+
}),
208+
}
216209
}
217210
}
218211

src/helix/endpoints/channels/remove_channel_vip.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,10 @@ impl RequestDelete for RemoveChannelVipRequest<'_> {
9999
Self: Sized,
100100
{
101101
match status {
102-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
103-
data: RemoveChannelVipResponse::Success,
104-
pagination: None,
102+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
103+
RemoveChannelVipResponse::Success,
105104
request,
106-
total: None,
107-
other: None,
108-
}),
105+
)),
109106
_ => Err(helix::HelixRequestDeleteError::InvalidResponse {
110107
reason: "unexpected status",
111108
response: response.to_string(),

src/helix/endpoints/charity/get_charity_campaign.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ impl RequestGet for GetCharityCampaignRequest<'_> {
120120
status,
121121
)
122122
})?;
123-
Ok(helix::Response {
124-
data: response.data.into_iter().next(),
125-
pagination: response.pagination.cursor,
123+
Ok(helix::Response::new(
124+
response.data.into_iter().next(),
125+
response.pagination.cursor,
126126
request,
127-
total: response.total,
128-
other: response.other,
129-
})
127+
response.total,
128+
response.other,
129+
))
130130
}
131131
}
132132

src/helix/endpoints/chat/get_chat_settings.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,7 @@ impl RequestGet for GetChatSettingsRequest<'_> {
146146
})
147147
}
148148
};
149-
Ok(helix::Response {
150-
data: resp,
151-
pagination: None,
152-
request,
153-
total: None,
154-
other: None,
155-
})
149+
Ok(helix::Response::with_data(resp, request))
156150
}
157151
}
158152

src/helix/endpoints/chat/send_a_shoutout.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,10 @@ impl RequestPost for SendAShoutoutRequest<'_> {
106106
Self: Sized,
107107
{
108108
match status {
109-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
110-
data: SendAShoutoutResponse::Success,
111-
pagination: None,
109+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
110+
SendAShoutoutResponse::Success,
112111
request,
113-
total: None,
114-
other: None,
115-
}),
112+
)),
116113
_ => Err(helix::HelixRequestPostError::InvalidResponse {
117114
reason: "unexpected status",
118115
response: response.to_string(),

src/helix/endpoints/chat/send_chat_announcement.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,10 @@ impl<'a> RequestPost for SendChatAnnouncementRequest<'a> {
174174
Self: Sized,
175175
{
176176
match status {
177-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
178-
data: SendChatAnnouncementResponse::Success,
179-
pagination: None,
177+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
178+
SendChatAnnouncementResponse::Success,
180179
request,
181-
total: None,
182-
other: None,
183-
}),
180+
)),
184181
_ => Err(helix::HelixRequestPostError::InvalidResponse {
185182
reason: "unexpected status",
186183
response: response.to_string(),

src/helix/endpoints/chat/update_chat_settings.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,7 @@ impl RequestPatch for UpdateChatSettingsRequest<'_> {
223223
})
224224
}
225225
};
226-
Ok(helix::Response {
227-
data: resp,
228-
pagination: None,
229-
request,
230-
total: None,
231-
other: None,
232-
})
226+
Ok(helix::Response::with_data(resp, request))
233227
}
234228
}
235229

src/helix/endpoints/chat/update_user_chat_color.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ impl RequestPut for UpdateUserChatColorRequest<'_> {
108108
Self: Sized,
109109
{
110110
match status {
111-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
112-
data: UpdateUserChatColorResponse::Success,
113-
pagination: None,
111+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
112+
UpdateUserChatColorResponse::Success,
114113
request,
115-
total: None,
116-
other: None,
117-
}),
114+
)),
118115
_ => Err(helix::HelixRequestPutError::InvalidResponse {
119116
reason: "unexpected status",
120117
response: response.to_string(),

src/helix/endpoints/eventsub/create_eventsub_subscription.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ impl<E: EventSubscription> helix::RequestPost for CreateEventSubSubscriptionRequ
168168
uri: uri.clone(),
169169
}
170170
})?;
171-
Ok(helix::Response {
172-
data: CreateEventSubSubscription {
171+
Ok(helix::Response::with_data(
172+
CreateEventSubSubscription {
173+
// helix::Response total is generally the total number of results, not what the total for this endpoint means. Thus, we set it to None.))
173174
total: response.total,
174175
total_cost: response.total_cost,
175176
max_total_cost: response.max_total_cost,
@@ -182,12 +183,8 @@ impl<E: EventSubscription> helix::RequestPost for CreateEventSubSubscriptionRequ
182183
created_at: data.created_at,
183184
transport: data.transport,
184185
},
185-
pagination: None,
186186
request,
187-
// helix::Response total is generally the total number of results, not what the total for this endpoint means. Thus, we set it to None.
188-
total: None,
189-
other: None,
190-
})
187+
))
191188
}
192189
}
193190

src/helix/endpoints/eventsub/delete_eventsub_subscription.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,10 @@ impl RequestDelete for DeleteEventSubSubscriptionRequest<'_> {
5353
Self: Sized,
5454
{
5555
match status {
56-
http::StatusCode::NO_CONTENT | http::StatusCode::OK => Ok(helix::Response {
57-
data: DeleteEventSubSubscription::Success,
58-
pagination: None,
56+
http::StatusCode::NO_CONTENT | http::StatusCode::OK => Ok(helix::Response::with_data(
57+
DeleteEventSubSubscription::Success,
5958
request,
60-
total: None,
61-
other: None,
62-
}),
59+
)),
6360
_ => Err(helix::HelixRequestDeleteError::InvalidResponse {
6461
reason: "unexpected status",
6562
response: response.to_string(),

src/helix/endpoints/eventsub/get_eventsub_subscriptions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ impl RequestGet for GetEventSubSubscriptionsRequest<'_> {
109109
status,
110110
)
111111
})?;
112-
Ok(helix::Response {
113-
data: EventSubSubscriptions {
112+
Ok(helix::Response::new(
113+
EventSubSubscriptions {
114114
// FIXME: This should probably be i64
115115
total: response.total as usize,
116116
total_cost: response.total_cost,
117117
max_total_cost: response.max_total_cost,
118118
subscriptions: response.data,
119119
},
120-
pagination: response.pagination.cursor,
120+
response.pagination.cursor,
121121
request,
122-
total: Some(response.total),
123-
other: None,
124-
})
122+
Some(response.total),
123+
None,
124+
))
125125
}
126126
}
127127

src/helix/endpoints/moderation/add_channel_moderator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,10 @@ impl RequestPost for AddChannelModeratorRequest<'_> {
102102
Self: Sized,
103103
{
104104
match status {
105-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
106-
data: AddChannelModeratorResponse::Success,
107-
pagination: None,
105+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
106+
AddChannelModeratorResponse::Success,
108107
request,
109-
total: None,
110-
other: None,
111-
}),
108+
)),
112109
_ => Err(helix::HelixRequestPostError::InvalidResponse {
113110
reason: "unexpected status",
114111
response: response.to_string(),

src/helix/endpoints/moderation/ban_user.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,17 @@ impl<'a> RequestPost for BanUserRequest<'a> {
188188
status,
189189
)
190190
})?;
191-
Ok(helix::Response {
192-
data: data.into_iter().next().ok_or_else(|| {
191+
Ok(helix::Response::with_data(
192+
data.into_iter().next().ok_or_else(|| {
193193
helix::HelixRequestPostError::InvalidResponse {
194194
reason: "missing response data",
195195
response: response.to_string(),
196196
status,
197197
uri: uri.clone(),
198198
}
199199
})?,
200-
pagination: None,
201200
request,
202-
total: None,
203-
other: None,
204-
})
201+
))
205202
}
206203
}
207204

src/helix/endpoints/moderation/delete_chat_messages.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,10 @@ impl RequestDelete for DeleteChatMessagesRequest<'_> {
124124
Self: Sized,
125125
{
126126
match status {
127-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
128-
data: DeleteChatMessagesResponse::Success,
129-
pagination: None,
127+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
128+
DeleteChatMessagesResponse::Success,
130129
request,
131-
total: None,
132-
other: None,
133-
}),
130+
)),
134131
_ => Err(helix::HelixRequestDeleteError::InvalidResponse {
135132
reason: "unexpected status",
136133
response: response.to_string(),

src/helix/endpoints/moderation/get_shield_mode_status.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,20 @@ impl RequestGet for GetShieldModeStatusRequest<'_> {
172172
status,
173173
)
174174
})?;
175-
Ok(helix::Response {
176-
data: inner_response.data.into_iter().next().ok_or(
175+
Ok(helix::Response::new(
176+
inner_response.data.into_iter().next().ok_or(
177177
helix::HelixRequestGetError::InvalidResponse {
178178
reason: "expected an entry in `data`",
179179
response: response.to_string(),
180180
status,
181181
uri: uri.clone(),
182182
},
183183
)?,
184-
pagination: inner_response.pagination.cursor,
184+
inner_response.pagination.cursor,
185185
request,
186-
total: inner_response.total,
187-
other: inner_response.other,
188-
})
186+
inner_response.total,
187+
inner_response.other,
188+
))
189189
}
190190
}
191191

src/helix/endpoints/moderation/manage_held_automod_messages.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,10 @@ impl<'a> RequestPost for ManageHeldAutoModMessagesRequest<'a> {
173173
Self: Sized,
174174
{
175175
match status {
176-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
177-
data: ManageHeldAutoModMessages::Success,
178-
pagination: None,
176+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
177+
ManageHeldAutoModMessages::Success,
179178
request,
180-
total: None,
181-
other: None,
182-
}),
179+
)),
183180
_ => Err(helix::HelixRequestPostError::InvalidResponse {
184181
reason: "unexpected status",
185182
response: response.to_string(),

src/helix/endpoints/moderation/remove_blocked_term.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,10 @@ impl RequestDelete for RemoveBlockedTermRequest<'_> {
107107
Self: Sized,
108108
{
109109
match status {
110-
http::StatusCode::NO_CONTENT => Ok(helix::Response {
111-
data: RemoveBlockedTerm::Success,
112-
pagination: None,
110+
http::StatusCode::NO_CONTENT => Ok(helix::Response::with_data(
111+
RemoveBlockedTerm::Success,
113112
request,
114-
total: None,
115-
other: None,
116-
}),
113+
)),
117114
_ => Err(helix::HelixRequestDeleteError::InvalidResponse {
118115
reason: "unexpected status",
119116
response: response.to_string(),

0 commit comments

Comments
 (0)