Skip to content

Commit 0987e5d

Browse files
committed
feat(refs): part 2 - docs and examples
1 parent d18a73d commit 0987e5d

Some content is hidden

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

45 files changed

+301
-222
lines changed

examples/automod_check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
3535

3636
let req =
3737
twitch_api::helix::moderation::CheckAutoModStatusRequest::broadcaster_id(broadcaster_id);
38-
let data =
39-
twitch_api::helix::moderation::CheckAutoModStatusBody::new("123", args.collect::<String>());
38+
let text = args.collect::<String>();
39+
let data = twitch_api::helix::moderation::CheckAutoModStatusBody::new("123", &text);
4040
println!("data: {:?}", data);
41-
let response = client.req_post(req, vec![data], &token).await?;
42-
println!("{:?}", response.data);
41+
let response = client.req_post(req, &[&data], &token).await?.data;
42+
println!("{response:?}");
4343

4444
Ok(())
4545
}

examples/channel_information.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
2626
let token = UserToken::from_existing(&client, token, None, None).await?;
2727

2828
let user = client
29-
.get_user_from_login(args.next().unwrap(), &token)
29+
.get_user_from_login(&*args.next().unwrap(), &token)
3030
.await?
3131
.expect("no user found");
3232

3333
let channel = client
34-
.get_channel_from_id(user.id.clone(), &token)
34+
.get_channel_from_id(&*user.id, &token)
3535
.await?
3636
.expect("no channel found");
3737

examples/channel_information_custom.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
2424
.map(AccessToken::new)
2525
.expect("Please set env: TWITCH_TOKEN or pass token as first argument");
2626
let token = UserToken::from_existing(&client, token, None, None).await?;
27-
let id = token.user_id.clone();
2827

2928
let resp = client
3029
.req_get_custom(
31-
helix::channels::GetChannelInformationRequest::broadcaster_id(id),
30+
helix::channels::GetChannelInformationRequest::broadcaster_id(&*token.user_id),
3231
&token,
3332
)
3433
.await

examples/client.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use twitch_api::{helix::streams::GetStreamsRequest, TwitchClient};
1+
use twitch_api::{helix::streams::GetStreamsRequest, types, TwitchClient};
22
use twitch_oauth2::{AccessToken, UserToken};
33
fn main() {
44
use std::error::Error;
@@ -36,9 +36,20 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
3636
)
3737
.await?;
3838

39-
let req = GetStreamsRequest::user_login(args.next().expect("please provide an username"));
4039
foo_client.client.helix.clone_client();
41-
let response = foo_client.client.helix.req_get(req, &token).await?;
42-
println!("{:?}", response);
40+
let response = foo_client
41+
.client
42+
.helix
43+
.req_get(
44+
GetStreamsRequest::user_logins(
45+
&[types::UserNameRef::from_str(
46+
&args.next().expect("please provide an username"),
47+
)][..],
48+
),
49+
&token,
50+
)
51+
.await?
52+
.data;
53+
println!("{response:?}");
4354
Ok(())
4455
}

examples/eventsub/src/twitch.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ pub async fn is_live<'a>(
264264
tracing::info!("checking if live");
265265
if let Some(stream) = client
266266
.req_get(
267-
helix::streams::get_streams::GetStreamsRequest::user_id(config.broadcaster.id.clone()),
267+
helix::streams::get_streams::GetStreamsRequest::user_ids(
268+
&[config.broadcaster.id.as_ref()][..],
269+
),
268270
token,
269271
)
270272
.await

examples/followed_streams.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
3737
.try_collect::<Vec<_>>()
3838
.await?;
3939
let games = client
40-
.get_games_by_id(streams.iter().map(|s| s.game_id.clone()), &token)
40+
.get_games_by_id(
41+
&streams
42+
.iter()
43+
.map(|s| s.game_id.as_ref())
44+
.collect::<Vec<_>>(),
45+
&token,
46+
)
4147
.await?;
4248

4349
println!(

examples/get_channel_status.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use twitch_api::{helix::streams::GetStreamsRequest, HelixClient};
1+
use twitch_api::{helix::streams::GetStreamsRequest, types, HelixClient};
22
use twitch_oauth2::{AccessToken, UserToken};
33

44
fn main() {
@@ -31,10 +31,17 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
3131
.await
3232
.unwrap();
3333

34-
let req = GetStreamsRequest::user_login(args.next().unwrap());
34+
let response = client
35+
.req_get(
36+
GetStreamsRequest::user_logins(
37+
&[types::UserNameRef::from_str(&args.next().unwrap())][..],
38+
),
39+
&token,
40+
)
41+
.await
42+
.unwrap()
43+
.data;
3544

36-
let response = client.req_get(req, &token).await.unwrap();
37-
38-
println!("Stream information:\n\t{:?}", response.data);
45+
println!("Stream information:\n\t{response:?}");
3946
Ok(())
4047
}

examples/mock_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
6868
.await?
6969
.expect("no channel found");
7070
let _channel = client
71-
.get_channel_from_id(user.id.clone(), &token)
71+
.get_channel_from_id(&*user.id, &token)
7272
.await?
7373
.expect("no channel found");
7474

@@ -86,7 +86,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
8686
.await?;
8787
dbg!(search.get(0));
8888
let _total = client
89-
.get_total_followers_from_id(search.get(0).unwrap().id.clone(), &token)
89+
.get_total_followers_from_id(&*search.get(0).unwrap().id, &token)
9090
.await?;
9191
dbg!(_total);
9292
let streams: Vec<_> = client.get_followed_streams(&token).try_collect().await?;

examples/modify_channel.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
3333
let broadcaster_id = token.validate_token(&client).await?.user_id.unwrap();
3434

3535
let req = twitch_api::helix::channels::ModifyChannelInformationRequest::broadcaster_id(
36-
broadcaster_id,
36+
&*broadcaster_id,
3737
);
3838

39-
let mut data = twitch_api::helix::channels::ModifyChannelInformationBody::new();
40-
data.title("Hello World!");
41-
4239
println!("scopes: {:?}", token.scopes());
43-
let response = client.req_patch(req, data, &token).await?;
40+
let response = client
41+
.req_patch(
42+
req,
43+
twitch_api::helix::channels::ModifyChannelInformationBody::builder()
44+
.title("Hello World!")
45+
.build(),
46+
&token,
47+
)
48+
.await?;
4449
println!("{:?}", response);
4550

4651
Ok(())

0 commit comments

Comments
 (0)