Skip to content

Commit

Permalink
feat(refs): part 2 - docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Oct 27, 2022
1 parent 8e20056 commit 6c015ca
Show file tree
Hide file tree
Showing 45 changed files with 301 additions and 222 deletions.
8 changes: 4 additions & 4 deletions examples/automod_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>

let req =
twitch_api::helix::moderation::CheckAutoModStatusRequest::broadcaster_id(broadcaster_id);
let data =
twitch_api::helix::moderation::CheckAutoModStatusBody::new("123", args.collect::<String>());
let text = args.collect::<String>();
let data = twitch_api::helix::moderation::CheckAutoModStatusBody::new("123", &text);
println!("data: {:?}", data);
let response = client.req_post(req, vec![data], &token).await?;
println!("{:?}", response.data);
let response = client.req_post(req, &[&data], &token).await?.data;
println!("{response:?}");

Ok(())
}
4 changes: 2 additions & 2 deletions examples/channel_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
let token = UserToken::from_existing(&client, token, None, None).await?;

let user = client
.get_user_from_login(args.next().unwrap(), &token)
.get_user_from_login(&*args.next().unwrap(), &token)
.await?
.expect("no user found");

let channel = client
.get_channel_from_id(user.id.clone(), &token)
.get_channel_from_id(&*user.id, &token)
.await?
.expect("no channel found");

Expand Down
3 changes: 1 addition & 2 deletions examples/channel_information_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
.map(AccessToken::new)
.expect("Please set env: TWITCH_TOKEN or pass token as first argument");
let token = UserToken::from_existing(&client, token, None, None).await?;
let id = token.user_id.clone();

let resp = client
.req_get_custom(
helix::channels::GetChannelInformationRequest::broadcaster_id(id),
helix::channels::GetChannelInformationRequest::broadcaster_id(&*token.user_id),
&token,
)
.await
Expand Down
19 changes: 15 additions & 4 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use twitch_api::{helix::streams::GetStreamsRequest, TwitchClient};
use twitch_api::{helix::streams::GetStreamsRequest, types, TwitchClient};
use twitch_oauth2::{AccessToken, UserToken};
fn main() {
use std::error::Error;
Expand Down Expand Up @@ -36,9 +36,20 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
)
.await?;

let req = GetStreamsRequest::user_login(args.next().expect("please provide an username"));
foo_client.client.helix.clone_client();
let response = foo_client.client.helix.req_get(req, &token).await?;
println!("{:?}", response);
let response = foo_client
.client
.helix
.req_get(
GetStreamsRequest::user_logins(
&[types::UserNameRef::from_str(
&args.next().expect("please provide an username"),
)][..],
),
&token,
)
.await?
.data;
println!("{response:?}");
Ok(())
}
4 changes: 3 additions & 1 deletion examples/eventsub/src/twitch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ pub async fn is_live<'a>(
tracing::info!("checking if live");
if let Some(stream) = client
.req_get(
helix::streams::get_streams::GetStreamsRequest::user_id(config.broadcaster.id.clone()),
helix::streams::get_streams::GetStreamsRequest::user_ids(
&[config.broadcaster.id.as_ref()][..],
),
token,
)
.await
Expand Down
8 changes: 7 additions & 1 deletion examples/followed_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
.try_collect::<Vec<_>>()
.await?;
let games = client
.get_games_by_id(streams.iter().map(|s| s.game_id.clone()), &token)
.get_games_by_id(
&streams
.iter()
.map(|s| s.game_id.as_ref())
.collect::<Vec<_>>(),
&token,
)
.await?;

println!(
Expand Down
17 changes: 12 additions & 5 deletions examples/get_channel_status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use twitch_api::{helix::streams::GetStreamsRequest, HelixClient};
use twitch_api::{helix::streams::GetStreamsRequest, types, HelixClient};
use twitch_oauth2::{AccessToken, UserToken};

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

let req = GetStreamsRequest::user_login(args.next().unwrap());
let response = client
.req_get(
GetStreamsRequest::user_logins(
&[types::UserNameRef::from_str(&args.next().unwrap())][..],
),
&token,
)
.await
.unwrap()
.data;

let response = client.req_get(req, &token).await.unwrap();

println!("Stream information:\n\t{:?}", response.data);
println!("Stream information:\n\t{response:?}");
Ok(())
}
4 changes: 2 additions & 2 deletions examples/mock_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
.await?
.expect("no channel found");
let _channel = client
.get_channel_from_id(user.id.clone(), &token)
.get_channel_from_id(&*user.id, &token)
.await?
.expect("no channel found");

Expand All @@ -86,7 +86,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
.await?;
dbg!(search.get(0));
let _total = client
.get_total_followers_from_id(search.get(0).unwrap().id.clone(), &token)
.get_total_followers_from_id(&*search.get(0).unwrap().id, &token)
.await?;
dbg!(_total);
let streams: Vec<_> = client.get_followed_streams(&token).try_collect().await?;
Expand Down
15 changes: 10 additions & 5 deletions examples/modify_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
let broadcaster_id = token.validate_token(&client).await?.user_id.unwrap();

let req = twitch_api::helix::channels::ModifyChannelInformationRequest::broadcaster_id(
broadcaster_id,
&*broadcaster_id,
);

let mut data = twitch_api::helix::channels::ModifyChannelInformationBody::new();
data.title("Hello World!");

println!("scopes: {:?}", token.scopes());
let response = client.req_patch(req, data, &token).await?;
let response = client
.req_patch(
req,
twitch_api::helix::channels::ModifyChannelInformationBody::builder()
.title("Hello World!")
.build(),
&token,
)
.await?;
println!("{:?}", response);

Ok(())
Expand Down
Loading

0 comments on commit 6c015ca

Please sign in to comment.