Module create_poll

Source
Available on crate feature helix only.
Expand description

Create a poll for a specific Twitch channel. create-poll

§Accessing the endpoint

§Request: CreatePollRequest

To use this endpoint, construct a CreatePollRequest with the CreatePollRequest::new() method.

use twitch_api::helix::polls::create_poll;
let request = create_poll::CreatePollRequest::new();

§Body: CreatePollBody

We also need to provide a body to the request containing what we want to change.

use twitch_api::helix::polls::create_poll;
let choices: &[create_poll::NewPollChoice] = &[
    create_poll::NewPollChoice::new("Heads"),
    create_poll::NewPollChoice::new("Tails"),
];
let mut body = create_poll::CreatePollBody::new(
    "141981764",
    "Heads or Tails?",
    1800,
    choices,
);
body.channel_points_voting_enabled = Some(true);
body.channel_points_per_vote = Some(100);

§Response: CreatePollResponse

Send the request to receive the response with HelixClient::req_post().

use twitch_api::helix::{self, polls::create_poll};
let request = create_poll::CreatePollRequest::new();
let choices: &[create_poll::NewPollChoice] = &[
    create_poll::NewPollChoice::new("Heads"),
    create_poll::NewPollChoice::new("Tails"),
];
let mut body = create_poll::CreatePollBody::new("141981764", "Heads or Tails?", 1800, choices);
body.channel_points_voting_enabled = Some(true);
body.channel_points_per_vote = Some(100);
let response: create_poll::CreatePollResponse = client.req_post(request, body, &token).await?.data;

You can also get the http::Request with request.create_request(&token, &client_id) and parse the http::Response with CreatePollRequest::parse_response(None, &request.get_uri(), response)

Structs§

CreatePollBody
Body Parameters for Create Poll
CreatePollRequest
Query Parameters for Create Poll
NewPollChoice
Choice settings for a poll

Type Aliases§

CreatePollResponse
Return Values for Create Poll