@@ -44,21 +44,38 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
44
44
}
45
45
46
46
/// Get multiple [User](helix::users::User)s from user ids.
47
- pub async fn get_users_from_ids < T > (
47
+ ///
48
+ /// # Examples
49
+ ///
50
+ /// ```rust, no_run
51
+ /// # #[tokio::main]
52
+ /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
53
+ /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
54
+ /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
55
+ /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
56
+ /// use twitch_api::{helix, types};
57
+ /// use futures::TryStreamExt;
58
+ ///
59
+ /// let users: Vec<helix::users::User> = client
60
+ /// .get_users_from_ids(&["1234", "4321"][..].into(), &token).try_collect().await?;
61
+ /// # Ok(()) }
62
+ /// ```
63
+ pub fn get_users_from_ids < T > (
48
64
& ' client self ,
49
- ids : impl AsRef < [ & types:: UserIdRef ] > + Send ,
50
- token : & T ,
51
- ) -> Result < Option < helix:: users:: User > , ClientError < C > >
65
+ ids : & ' client types :: Collection < ' client , types:: UserId > ,
66
+ token : & ' client T ,
67
+ ) -> impl futures :: Stream < Item = Result < helix:: users:: User , ClientError < C > > > + Send + Unpin + ' client
52
68
where
53
69
T : TwitchToken + Send + Sync + ?Sized ,
54
70
{
55
- let ids = ids. as_ref ( ) ;
56
- if ids. len ( ) > 100 {
57
- return Err ( ClientRequestError :: Custom ( "too many IDs, max 100" . into ( ) ) ) ;
58
- }
59
- self . req_get ( helix:: users:: GetUsersRequest :: ids ( ids) , token)
60
- . await
61
- . map ( |response| response. first ( ) )
71
+ futures:: stream:: iter ( ids. chunks ( 100 ) . collect :: < Vec < _ > > ( ) )
72
+ . map ( move |c| {
73
+ let req = helix:: users:: GetUsersRequest :: ids ( c) ;
74
+ futures:: stream:: once ( self . req_get ( req, token) ) . boxed ( )
75
+ } )
76
+ . flatten_unordered ( None )
77
+ . map_ok ( |resp| futures:: stream:: iter ( resp. data . into_iter ( ) . map ( Ok ) ) )
78
+ . try_flatten_unordered ( None )
62
79
}
63
80
64
81
/// Get [ChannelInformation](helix::channels::ChannelInformation) from a broadcasters login
@@ -106,30 +123,31 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
106
123
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
107
124
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
108
125
/// use twitch_api::{helix, types};
126
+ /// use futures::TryStreamExt;
109
127
///
110
- /// let ids: &[&types::UserIdRef] = &["1234".into(), "4321".into()];
111
128
/// let chatters: Vec<helix::channels::ChannelInformation> = client
112
- /// .get_channels_from_ids(ids, &token).await?;
129
+ /// .get_channels_from_ids(&["1234", "4321"][..].into(), &token).try_collect( ).await?;
113
130
/// # Ok(()) }
114
131
/// ```
115
- pub async fn get_channels_from_ids < ' b , T > (
132
+ pub fn get_channels_from_ids < T > (
116
133
& ' client self ,
117
- ids : impl AsRef < [ & types:: UserIdRef ] > + Send ,
118
- token : & T ,
119
- ) -> Result < Vec < helix:: channels:: ChannelInformation > , ClientError < C > >
134
+ ids : & ' client types:: Collection < ' client , types:: UserId > ,
135
+ token : & ' client T ,
136
+ ) -> impl futures:: Stream < Item = Result < helix:: channels:: ChannelInformation , ClientError < C > > >
137
+ + Send
138
+ + Unpin
139
+ + ' client
120
140
where
121
141
T : TwitchToken + Send + Sync + ?Sized ,
122
142
{
123
- let ids = ids. as_ref ( ) ;
124
- if ids. len ( ) > 100 {
125
- return Err ( ClientRequestError :: Custom ( "too many IDs, max 100" . into ( ) ) ) ;
126
- }
127
- self . req_get (
128
- helix:: channels:: GetChannelInformationRequest :: broadcaster_ids ( ids) ,
129
- token,
130
- )
131
- . await
132
- . map ( |response| response. data )
143
+ futures:: stream:: iter ( ids. chunks ( 100 ) . collect :: < Vec < _ > > ( ) )
144
+ . map ( move |c| {
145
+ let req = helix:: channels:: GetChannelInformationRequest :: broadcaster_ids ( c) ;
146
+ futures:: stream:: once ( self . req_get ( req, token) ) . boxed ( )
147
+ } )
148
+ . flatten_unordered ( None )
149
+ . map_ok ( |resp| futures:: stream:: iter ( resp. data . into_iter ( ) . map ( Ok ) ) )
150
+ . try_flatten_unordered ( None )
133
151
}
134
152
135
153
/// Get multiple [Stream](helix::streams::Stream)s from user ids.
@@ -145,12 +163,12 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
145
163
/// use twitch_api::{types, helix};
146
164
/// use futures::TryStreamExt;
147
165
///
148
- /// let live: Vec<helix::streams::Stream> = client.get_streams_from_ids(&["123456", "987654"], &token).try_collect().await?;
166
+ /// let live: Vec<helix::streams::Stream> = client.get_streams_from_ids(&["123456", "987654"][..].into() , &token).try_collect().await?;
149
167
/// # Ok(()) }
150
168
/// ```
151
169
pub fn get_streams_from_ids < T > (
152
170
& ' client self ,
153
- ids : impl Into < types:: Collection < ' client , types:: UserId > > ,
171
+ ids : & ' client types:: Collection < ' client , types:: UserId > ,
154
172
token : & ' client T ,
155
173
) -> impl futures:: Stream < Item = Result < helix:: streams:: Stream , ClientError < C > > >
156
174
+ Send
@@ -159,7 +177,7 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
159
177
where
160
178
T : TwitchToken + Send + Sync + ?Sized ,
161
179
{
162
- let ids = ids. into ( ) . chunks ( 100 ) . collect :: < Vec < _ > > ( ) ;
180
+ let ids = ids. chunks ( 100 ) . collect :: < Vec < _ > > ( ) ;
163
181
futures:: stream:: iter ( ids. into_iter ( ) . map ( move |c| {
164
182
let req = helix:: streams:: GetStreamsRequest :: user_ids ( c) . first ( 100 ) ;
165
183
make_stream ( req, token, self , std:: collections:: VecDeque :: from)
@@ -180,12 +198,12 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
180
198
/// use twitch_api::{types, helix};
181
199
/// use futures::TryStreamExt;
182
200
///
183
- /// let live: Vec<helix::streams::Stream> = client.get_streams_from_logins(&["twitchdev", "justinfan"], &token).try_collect().await?;
201
+ /// let live: Vec<helix::streams::Stream> = client.get_streams_from_logins(&["twitchdev", "justinfan"][..].into() , &token).try_collect().await?;
184
202
/// # Ok(()) }
185
203
/// ```
186
204
pub fn get_streams_from_logins < T > (
187
205
& ' client self ,
188
- logins : impl Into < types:: Collection < ' client , types:: UserName > > ,
206
+ logins : & ' client types:: Collection < ' client , types:: UserName > ,
189
207
token : & ' client T ,
190
208
) -> impl futures:: Stream < Item = Result < helix:: streams:: Stream , ClientError < C > > >
191
209
+ Send
@@ -194,7 +212,7 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
194
212
where
195
213
T : TwitchToken + Send + Sync + ?Sized ,
196
214
{
197
- let logins = logins. into ( ) . chunks ( 100 ) . collect :: < Vec < _ > > ( ) ;
215
+ let logins = logins. chunks ( 100 ) . collect :: < Vec < _ > > ( ) ;
198
216
futures:: stream:: iter ( logins. into_iter ( ) . map ( move |c| {
199
217
let req = helix:: streams:: GetStreamsRequest :: user_logins ( c) . first ( 100 ) ;
200
218
make_stream ( req, token, self , std:: collections:: VecDeque :: from)
@@ -626,18 +644,17 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
626
644
/// use twitch_api::{types, helix};
627
645
/// use futures::TryStreamExt;
628
646
///
629
- /// let games: Vec<helix::games::Game> = client.get_games_by_id(&["509658", "32982", "27471"], &token).try_collect().await?;
647
+ /// let games: Vec<helix::games::Game> = client.get_games_by_id(&["509658", "32982", "27471"][..].into() , &token).try_collect().await?;
630
648
/// # Ok(()) }
631
649
/// ```
632
650
pub fn get_games_by_id < T > (
633
651
& ' client self ,
634
- ids : impl Into < types:: Collection < ' client , types:: CategoryId > > ,
652
+ ids : & ' client types:: Collection < ' client , types:: CategoryId > ,
635
653
token : & ' client T ,
636
654
) -> impl futures:: Stream < Item = Result < helix:: games:: Game , ClientError < C > > > + Send + Unpin + ' client
637
655
where
638
656
T : TwitchToken + Send + Sync + ?Sized ,
639
657
{
640
- let ids = ids. into ( ) ;
641
658
futures:: stream:: iter ( ids. chunks ( 100 ) . collect :: < Vec < _ > > ( ) )
642
659
. map ( move |c| {
643
660
let req = helix:: games:: GetGamesRequest :: ids ( c) ;
@@ -834,16 +851,12 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
834
851
/// use twitch_api::{types, helix};
835
852
/// use futures::TryStreamExt;
836
853
///
837
- /// let games: Vec<helix::chat::get_emote_sets::Emote> = client.get_emote_sets(&["0"], &token).try_collect().await?;
854
+ /// let games: Vec<helix::chat::get_emote_sets::Emote> = client.get_emote_sets(&["0"][..].into() , &token).try_collect().await?;
838
855
/// # Ok(()) }
839
856
/// ```
840
857
pub fn get_emote_sets < T > (
841
858
& ' client self ,
842
- // doesn't work:
843
- emote_sets : impl Into < types:: Collection < ' client , types:: EmoteSetId > > ,
844
- // works:
845
- // emote_sets: &'client [&'client types::EmoteSetIdRef],
846
- //emote_sets: impl AsRef<types::Collection<'client, types::EmoteSetId>> + 'client,
859
+ emote_sets : & ' client types:: Collection < ' client , types:: EmoteSetId > ,
847
860
token : & ' client T ,
848
861
) -> impl futures:: Stream < Item = Result < helix:: chat:: get_emote_sets:: Emote , ClientError < C > > >
849
862
+ Send
@@ -852,7 +865,6 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
852
865
where
853
866
T : TwitchToken + Send + Sync + ?Sized ,
854
867
{
855
- let emote_sets = emote_sets. into ( ) . to_owned ( ) ;
856
868
futures:: stream:: iter ( emote_sets. chunks ( 25 ) . collect :: < Vec < _ > > ( ) )
857
869
. map ( move |c| {
858
870
let req = helix:: chat:: GetEmoteSetsRequest :: emote_set_ids ( c) ;
@@ -1007,12 +1019,12 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
1007
1019
/// use twitch_api::{types, helix};
1008
1020
/// use futures::TryStreamExt;
1009
1021
///
1010
- /// let games: Vec<helix::chat::UserChatColor> = client.get_users_chat_colors(&["1234"], &token).try_collect().await?;
1022
+ /// let games: Vec<helix::chat::UserChatColor> = client.get_users_chat_colors(&["1234"][..].into() , &token).try_collect().await?;
1011
1023
/// # Ok(()) }
1012
1024
/// ```
1013
1025
pub fn get_users_chat_colors < T > (
1014
1026
& ' client self ,
1015
- user_ids : impl Into < types:: Collection < ' client , types:: UserId > > + ' client ,
1027
+ user_ids : & ' client types:: Collection < ' client , types:: UserId > ,
1016
1028
token : & ' client T ,
1017
1029
) -> impl futures:: Stream < Item = Result < helix:: chat:: UserChatColor , ClientError < C > > >
1018
1030
+ Send
@@ -1021,7 +1033,6 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
1021
1033
where
1022
1034
T : TwitchToken + Send + Sync + ?Sized ,
1023
1035
{
1024
- let user_ids = user_ids. into ( ) ;
1025
1036
futures:: stream:: iter ( user_ids. chunks ( 100 ) )
1026
1037
. map ( move |c| {
1027
1038
let req = helix:: chat:: GetUserChatColorRequest :: user_ids ( c) ;
@@ -1165,7 +1176,7 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
1165
1176
where
1166
1177
T : TwitchToken + Send + Sync + ?Sized ,
1167
1178
{
1168
- self . get_custom_rewards ( broadcaster_id, only_managable_rewards, & [ ] , token)
1179
+ self . get_custom_rewards ( broadcaster_id, only_managable_rewards, & types :: Collection :: EMPTY , token)
1169
1180
. await
1170
1181
}
1171
1182
@@ -1186,17 +1197,17 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
1186
1197
/// use twitch_api::helix;
1187
1198
///
1188
1199
/// let rewards: Vec<helix::points::CustomReward> = client
1189
- /// .get_custom_rewards("1234", true, &["8969ec47-55b6-4559-a8fe-3f1fc4e6fe58". into()] , &token)
1200
+ /// .get_custom_rewards("1234", true, &["8969ec47-55b6-4559-a8fe-3f1fc4e6fe58"][..]. into(), &token)
1190
1201
/// .await?;
1191
1202
/// # Ok(()) }
1192
1203
/// ```
1204
+ // XXX: This function is useless as a stream, since you can never have more than 50 rewards on a channel
1193
1205
pub async fn get_custom_rewards < ' b , T > (
1194
1206
& ' client self ,
1195
1207
broadcaster_id : impl types:: IntoCow < ' b , types:: UserIdRef > + Send + ' b ,
1196
1208
only_managable_rewards : bool ,
1197
- // FIXME: This should be `impl AsRef<[&'b T]> + 'b`
1198
- ids : & ' b [ & ' b types:: RewardIdRef ] ,
1199
- token : & T ,
1209
+ ids : & ' b types:: Collection < ' b , types:: RewardId > ,
1210
+ token : & ' client T ,
1200
1211
) -> Result < Vec < helix:: points:: CustomReward > , ClientError < C > >
1201
1212
where
1202
1213
T : TwitchToken + Send + Sync + ?Sized ,
@@ -1208,7 +1219,7 @@ impl<'client, C: crate::HttpClient + Sync + 'client> HelixClient<'client, C> {
1208
1219
. req_get (
1209
1220
helix:: points:: GetCustomRewardRequest :: broadcaster_id ( broadcaster_id)
1210
1221
. only_manageable_rewards ( only_managable_rewards)
1211
- . ids ( ids) ,
1222
+ . ids ( ids. clone ( ) ) ,
1212
1223
token,
1213
1224
)
1214
1225
. await ?
0 commit comments