Introduction

Description

Toornament - is the eSports platform for tournaments organizers, their participants and their fans.

toornament-rs - is a library which implements the REST-API of toornament.com. This library fully implements the endpoints stack so you can be sure that you can do any kind of things with it. The library is MIT-licensed and very-well documented. It has no unsafe-blocks of code, uses cutting-edge crates as dependencies and provides the interface as simple as possible.

The library provides additionally provides iter-like inteface rather than REST-one. It abstracts code writers from rest-inteface at all, lets them work with Toornament entities directly without calling API methods, increases code readability and writability, and eventually boosts developing.

The library is thread-safe, the Toornament structure implements Send and Sync traits and has no mutable methods.

Quick start

Compiling

To compile the crate simply get the sources and perform use cargo to build it:

git clone https://github.com/vityafx/toornament-rs.git
cd toornament-rs/
cargo update;
cargo build --release;

Adding the crate as dependency

To add as dependency you must add the line into your Cargo.toml:

[dependencies]
toornament = "*"

It will get the latest available toornament crate. However, if you want to publish your crate you must know the exact version and specify it in the [dependencies] section.

Running

Check that you have everything installed correctly by compiling a minimal user-crate:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Listing all the tournaments
    println!("Tournaments: {:?}\n", toornament.tournaments(None, true));
}

Change API_TOKEN, CLIENT_ID, CLIENT_SECRET to yours and run the source with cargo run. If everything is good you will see all the tournaments available in the toornament.com service.

Tournaments

Tournaments is the basic entity of the API. Everything starts here, in tournaments. Each tournament has matches, games, match results, participants, streams, videos, and so on. So the first thing we should start learning is what is a tournament in terms of the service, how to create and edit it.

Create a tournament

Let's split up object creation in the rust language and tournament creation in the toornament service. Ok, I assume, you did that.

Creation of a tournament in the service is fairly simple. All the needed information by the api is already specified in the structure implementation so you may easily create an object of a structure specifically for creating purposes:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Creating a `Tournament` object for adding it to the service
    let mut tournament = Tournament::create(DisciplineId("wwe2k17".to_owned()),
                                            "test tournament by fx",
                                             16,
                                             ParticipantType::Single);

    tournament = toornament.edit_tournament(tournament).unwrap();
    println!("Created tournament: {:?}\n", tournament);

    assert!(tournament.id.is_some());
}

Here we simply created a object of Tournament structure which we may use for sending to the service already: however, it contains very basic information (most of it's parts is simply unspecified), it contains enough information for creation. So, let's create a new tournament in the toornament:

Here is how simple it goes. Let me explain what is going on here:

  1. We created a tournament object through Tournament::create method.
  2. We use it for sending it to the service through Toornament::edit_tournament method.
  3. We then got a created tournament object from the service and re-assigned it to our variable.

So, after that we may check that our tournament object has an id field filled by the toornament.com server.

So, the tournament is created now and you may see it on the organizator's web page.

You may wonder why a method for tournament creation is called "edit_tournament", the reason for this is quite simple: we use same method for editing tournament and creating it. The action depends on does the passed Tournament object have an id: if it does, the method edits the tournament on the server, if not - creates new one.

Here is another way to create a tournament, via iter inteface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let result = toornament.tournaments_iter()
                           .create(|| {
                                 Tournament::create(DisciplineId("wwe2k17".to_owned()),
                                                    "test tournament by fx",
                                                    16,
                                                    ParticipantType::Single)
                           }).update();
}

Looks a bit simplier, right? Also, we don't call Toornament explicitly here, we just use a method of TournamentIter structure.

Edit a tournament

So, on the previous page we created a tournament. Let's edit some of it's parts! Imagine, that we want to add a web-site of the tournament so the participants or just toornament users may know more about the tournament. We do this simply: edit needed field of the tournament object and then send it through the same endpoint. So, by the steps:

  1. Editing a tournament object:

    extern crate toornament;
    use toornament::*;
    
    fn main() {
        let toornament = Toornament::with_application("API_TOKEN",
                                                      "CLIENT_ID",
                                                      "CLIENT_SECRET").unwrap()
                                    .timeout(5);
    
        // Defining a website
        let tournament_website = Some("https://toornament.com/".to_owned());
    
        // Creating a `Tournament` object for adding it to the service
        let mut tournament = Tournament::create(DisciplineId("wwe2k17".to_owned()),
                                                "test tournament by fx",
                                                 16,
                                                 ParticipantType::Single);
    
        // Some checks to be sure that our website is not set and our tournament is not public
        assert!(tournament.website.is_none());
        assert_eq!(tournament.public, false);
    
        // Editing fields of the object
        tournament = tournament.website(tournament_website.clone())
                               .public(true);
    
        // Checking everything has been done correctly
        assert_eq!(tournament.website, tournament_website);
        assert_eq!(tournament.public, true);
    }
    
  2. Sending edited tournament object with re-assigning returned tournament from the service to our variable so it is updated with the information from the server.

    // Updating our previously created tournament with new website information
    tournament = toornament.edit_tournament(tournament)?;
    
  3. Making sure that everything has been done correctly:

    assert_eq!(tournament.website, tournament_website);
    assert_eq!(tournament.public, true);
    

So, we have just edited our tournament!

Another way to do that is via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Creating a `Tournament` object for adding it to the service
    let mut tournament = Tournament::create(DisciplineId("wwe2k17".to_owned()),
                                            "test tournament by fx",
                                             16,
                                             ParticipantType::Single);

    // Some checks to be sure that our website is not set and our tournament is not public
    assert!(tournament.website.is_none());
    assert_eq!(tournament.public, false);

    tournament = toornament.tournaments_iter()
                           .with_id(tournament.id.unwrap())
                           .edit(|mut t| t.website(Some("https://toornament.com/".to_owned()))
                                          .public(true))
                           .update().unwrap();

    // Checking everything has been done correctly
    assert_eq!(tournament.website, Some("https://toornament.com/".to_owned()));
    assert_eq!(tournament.public, true);
}

Delete a tournament

Deleting a tournament is very simple: just call an appropriate method with tournament id:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Deleting our tournament
    println!("Deleted tournament: {:?}\n",
             toornament.delete_tournament(TournamentId("1".to_owned())));
}

After that you may no longer see this tournament in your organizator's webpage.

Another way to do that is via iter interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Deleting our tournament
    println!("Deleted tournament: {:?}\n", toornament.tournaments_iter()
                                                     .with_id(TournamentId("1".to_owned()))
                                                     .delete());
}

List tournaments

To list all the tournaments you may use Toornament::tournaments method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Getting all tournaments
    let all_tournaments: Tournaments = toornament.tournaments(None, true).unwrap();
}

You also can fetch a specific tournament by it's id (*):

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get tournament by it's id
    let tournament = toornament.tournaments(Some(TournamentId("1".to_owned())), true).unwrap();
    assert_eq!(tournament.0.len(), 1);
    assert_eq!(tournament.0.first().unwrap().id, Some(TournamentId("1".to_owned())));
}

The second parameter of the method is a boolean which defines should the server include streams or not.

Another way to do that is via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Getting all tournaments
    let all_tournaments = toornament.tournaments_iter()
                                    .all()
                                    .collect::<Tournaments>().unwrap();
    // Get tournament by it's id
    let tournament = toornament.tournaments_iter()
                               .with_id(TournamentId("1".to_owned()))
                               .collect::<Tournament>()
                               .unwrap();
}

(*) Note: you may not get a tournament if there is no tournament with id = 1.

List my tournaments

You may fetch all tournaments that were created by you or associated with your account's credentials:

REST:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get all my tournaments
    let tournaments = toornament.my_tournaments();
}

or via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    /// Get all my tournaments
    let tournaments = toornament.tournaments_iter().my().collect::<Tournaments>();
}

This will return a list of tournaments associated with your account.

Match games

This is a subsection of matches and their games. Continue reading to know how to manage matches, their games and results.

List tournament's matches

To list all the matches of a tournament you may use Toornament::matches method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get all matches of a tournament with id = "1"
    let matches = toornament.matches(TournamentId("1".to_owned()), None, true);
}

You may also get a specific match of a tournament by it's id:

// Get match with match id = "2" of a tournament with id = "1"
let matches = toornament.matches(TournamentId("1".to_owned()), Some(MatchId("2".to_owned())), true);

The third boolean parameter specifies should the server return games field or not.

You also can get all the matches of a tournament via iter interface.

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get all matches of a tournament with id = "1"
    let matches = toornament.tournaments_iter()
                            .with_id(TournamentId("1".to_owned()))
                            .matches()
                            .collect::<Matches>();
}

List matches by a discipline

To get all the matches by a discipline you can use Toornament::matches_by_discipline:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // But let's look all the matches for wwe2k17 discipline
    let matches = toornament.matches_by_discipline(DisciplineId("wwe2k17".to_owned()),
                                                   MatchFilter::default());
}

matches will now contain a result with game matches for a wwe2k17 game discipline. Note, that this method accepts a filter as second parameter which can be used for filtering server's data. In the code above this filter is filled with default values.

If you want to do this via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let matches = toornament.disciplines_iter()
                            .with_id(DisciplineId("wwe2k17".to_owned()))
                            .matches()
                            .collect::<Matches>()
                            .unwrap();
}

Update match

To update a match (change it) you can use Toornament::update_match method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define a match
    let mut match_to_edit = toornament.matches(TournamentId("1".to_owned()),
                                               Some(MatchId("2".to_owned())),
                                               true).unwrap().0.first().unwrap().to_owned();
    // Edit it's number
    match_to_edit = match_to_edit.number(2u64);

    match_to_edit = toornament.update_match(TournamentId("1".to_owned()),
                                            MatchId("2".to_owned()),
                                            match_to_edit).unwrap();
}

This will edit a match with id = 2 and return the updated object.

This can also be done via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define a match
    let mut match_to_edit = toornament.tournaments_iter()
                                      .with_id(TournamentId("1".to_owned()))
                                      .matches()
                                      .with_id(MatchId("2".to_owned()))
                                      .edit(|m| m.number(3u64))
                                      .update();
}

Get match game

To get games of a match you can use Toornament::match_games method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    /// Get match games of a match with id = "2" of a tournament with id = "1"
    let games = toornament.match_games(TournamentId("1".to_owned()),
                                       MatchId("2".to_owned()),
                                       true);
}

The third boolean parameter determines should the server also return game stats in it's answer.

And via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let games = toornament.tournaments_iter()
                          .with_id(TournamentId("1".to_owned()))
                          .matches()
                          .with_id(MatchId("2".to_owned()))
                          .games()
                          .collect::<Games>();
}

Update match game

To update a game data of a match you can use Toornament::update_match_game method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define a game
    let mut game = Game {
        number: GameNumber(3i64),
        status: MatchStatus::Completed,
        opponents: Opponents::default(),
    };
    // Update a match game with number "3" of a match with id = "2" of a tournament with id = "1"
    let game = toornament.update_match_game(TournamentId("1".to_owned()),
                                            MatchId("2".to_owned()),
                                            GameNumber(3i64),
                                            game);
}

The game object will now contain a new Game object.

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let game = toornament.tournaments_iter()
                         .with_id(TournamentId("1".to_owned()))
                         .matches()
                         .with_id(MatchId("2".to_owned()))
                         .games()
                         .with_number(GameNumber(3i64))
                         .edit(|_| Game {
                             number: GameNumber(3i64),
                             status: MatchStatus::Completed,
                             opponents: Opponents::default(),
                         })
                         .update();
}

Set game result

To set result of a match you can use Toornament::set_match_result method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define a result
    let result = MatchResult {
        status: MatchStatus::Completed,
        opponents: Opponents::default(),
    };
    // Set match result for a match with id = "2" of a tournament with id = "1"
    let success = toornament.set_match_result(TournamentId("1".to_owned()),
                                              MatchId("2".to_owned()),
                                              result);
}

This will return a Result which can be used in usual Rust way:

match success {
    Ok(_) => println!("Match result has been set successfully!"),
    Err(e) => println!("Could not set match result: {}", e),
};

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);
    
    let result = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .matches()
                           .with_id(MatchId("2".to_owned()))
                           .games()
                           .with_number(GameNumber(3i64))
                           .result()
                           .edit(|_| MatchResult {
                               status: MatchStatus::Completed,
                               opponents: Opponents::default(),
                           })
                           .update();
}

Get game result

To get result of a match you can use Toornament::match_result method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get a match result of a match with id = "2" of a tournament with id = "1"
    let result = toornament.match_result(TournamentId("1".to_owned()),
                                         MatchId("2".to_owned()));
}

The result object will now contain a MatchResult object.

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let result = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .matches()
                           .with_id(MatchId("2".to_owned()))
                           .result()
                           .collect::<MatchResult>();
}

Set or update match game result

To set result of a match game you can use Toornament::update_match_game_result method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define a result
    let result = MatchResult {
        status: MatchStatus::Completed,
        opponents: Opponents::default(),
    };
    // Set a match game result with number "3" of a match with id = "2" of a tournament with id = "1"
    let result = toornament.update_match_game_result(TournamentId("1".to_owned()),
                                                     MatchId("2".to_owned()),
                                                     GameNumber(3i64),
                                                     result,
                                                     false);
}

The result object will now contain a new MatchResult object.

The last, 5th parameter (boolean one) is used to specify whether it should set a result or update it. So, if you want to update a result rather than add it to the game, pass true there.

You can do this via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Set a match game result with number "3" of a match with id = "2" of a tournament with id = "1"
    let game = toornament.tournaments_iter()
                         .with_id(TournamentId("1".to_owned()))
                         .matches()
                         .with_id(MatchId("2".to_owned()))
                         .games()
                         .with_number(GameNumber(3i64))
                         .result()
                         .edit(|_| MatchResult {
                             status: MatchStatus::Completed,
                             opponents: Opponents::default(),
                         })
                         .update();
}

Get game result

To get a result of a match game you can use Toornament::match_game_result method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get a match game result with number "3" of a match with id = "2" of a tournament with id = "1"
    let result = toornament.match_game_result(TournamentId("1".to_owned()),
                                              MatchId("2".to_owned()),
                                              GameNumber(3i64));
}

The result object will now contain a new MatchResult object.

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let result = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .matches()
                           .with_id(MatchId("2".to_owned()))
                           .games()
                           .with_number(GameNumber(3i64))
                           .result()
                           .collect::<MatchResult>();
}

Participants

This section is about managing participants of a tournament: fetching, creating, editing and deleting participants. Continue reading to know more.

List tournament's participants

To fetch participants of a tournament you can use Toornament::tournament_participants method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get participants of a tournament with id = "1" with default filter
    let participants = toornament.tournament_participants(TournamentId("1".to_owned()),
                                                          TournamentParticipantsFilter::default());
}

participants will now contain a list of participants of the tournament.

This method accepts a special filter to filter participants by some value. This example uses filter filled with default values.

Listing participants via iter-like interface is simple:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let participants = toornament.tournaments_iter()
                                 .with_id(TournamentId("1".to_owned()))
                                 .participants()
                                 .collect::<Participants>();
}

Get participant

To get a particular participant of a tournament you can use Toornament::tournament_participant method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get a participant with id = "2" of a tournament with id = "1"
    let participant = toornament.tournament_participant(TournamentId("1".to_owned()),
                                                        ParticipantId("2".to_owned()));
}

participant will now contain a participant you requested.

Getting a participant via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let participant = toornament.tournaments_iter()
                                .with_id(TournamentId("1".to_owned()))
                                .participants()
                                .with_id(ParticipantId("2".to_owned()))
                                .collect::<Participant>();
}

Create participant

To create a participant of a tournament you can use Toornament::create_tournament_participant method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define a participant
    let participant = Participant::create("Test participant");
    // Create a participant for a tournament with id = "1"
    let participant = toornament.create_tournament_participant(TournamentId("1".to_owned()),
                                                               participant);
}

This will create a new participant and add it to the tournament with id = 1.

Creating a participant via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let participant = toornament.tournaments_iter()
                                .with_id(TournamentId("1".to_owned()))
                                .participants()
                                .create(|| Participant::create("Test participant"))
                                .update();
}

Update single participant

To update a participant of a tournament you can use Toornament::update_tournament_participant method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // At first get a participant with id = "2" of a tournament with id = "1"
    let mut participant = toornament.tournament_participant(TournamentId("1".to_owned()),
                                                            ParticipantId("2".to_owned())).unwrap();
    // Update the participant's name and send it
    participant = participant.name("Updated participant name here".to_owned());
    let updated_participant = toornament.update_tournament_participant(
        TournamentId("1".to_owned()),
        ParticipantId("2".to_owned()),
        participant);
}

This will update a participant in the tournament and return updated participant object as a result.

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let participant = toornament.tournaments_iter()
                                .with_id(TournamentId("1".to_owned()))
                                .participants()
                                .with_id(ParticipantId("2".to_owned()))
                                .edit(|p| p.name("Another name"))
                                .update();
}

Update multiple participants

To update multiple participants of a tournament you can use Toornament::update_tournament_participants method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define participants
    let mut participants = vec![Participant::create("First participant"),
                                Participant::create("Second participant")];
    // Update a participant for a tournament with id = "1"
    let new_participants = toornament.update_tournament_participants(TournamentId("1".to_owned()),
                                                                     Participants(participants));
}

This will update a list participants by replacing all old participants with new ones.

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let participants = toornament.tournaments_iter()
                                .with_id(TournamentId("1".to_owned()))
                                .participants()
                                .edit(|_| {
                                    Participants(vec![Participant::create("First participant"),
                                                      Participant::create("Second participant")])
                                })
                                .update();
}

Delete participant

To delete a participant of a tournament you can use Toornament::delete_tournament_participant method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Delete a participant with id = "2" of a tournament with id = "1"
    let result = toornament.delete_tournament_participant(TournamentId("1".to_owned()),
                                                          ParticipantId("2".to_owned()));
}

This will delete a participant with id = 2 from the tournament.

Via iter-like interface:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let result = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .participants()
                           .with_id(ParticipantId("2".to_owned()))
                           .delete();
}

Permissions

This section is about managing user permissions: listing, creating, fetching, editing and deleting. Continue reading to know more.

List tournament's user permissions

To list all the permissions of a tournament you can use Toornament::tournament_permissions method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get permissions of a tournament with id = "1"
    let permissions = toornament.tournament_permissions(TournamentId("1".to_owned())).unwrap();
}

This will return a list of tournament's user permissions.

Via iter-like:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let permissions = toornament.tournaments_iter()
                                .with_id(TournamentId("1".to_owned()))
                                .permissions()
                                .collect::<Permissions>();
}

Create a tournament's user permission

To create a user permission of a tournament you can use Toornament::tournament_permissions method:

extern crate toornament;
use toornament::*;

fn main() {
    use std::collections::BTreeSet;

    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define our permission
    let mut attributes = BTreeSet::new();
    attributes.insert(PermissionAttribute::Register);
    attributes.insert(PermissionAttribute::Edit);

    let permission = Permission::create("test@mail.ru", PermissionAttributes(attributes));
    // Add permission to a tournament with id = "1"
    let new_permission = toornament.create_tournament_permission(TournamentId("1".to_owned()),
                                                                 permission);
}

This will create a user permission and return it as a result.

Via iter-like:

extern crate toornament;
use toornament::*;

fn main() {
    use std::collections::BTreeSet;

    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let permission = toornament.tournaments_iter()
                               .with_id(TournamentId("1".to_owned()))
                               .permissions()
                               .create(|| {
                                    // Define our permission
                                    let mut attributes = BTreeSet::new();
                                    attributes.insert(PermissionAttribute::Register);
                                    attributes.insert(PermissionAttribute::Edit);

                                    Permission::create("test@mail.ru",
                                                       PermissionAttributes(attributes))
                               })
                               .update();
}

Get tournament's user permission

To get a user permission of a tournament you can use Toornament::tournament_permission method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get a permission with id = "2" of a tournament with id = "1"
    let permission = toornament.tournament_permission(TournamentId("1".to_owned()),
                                                      PermissionId("2".to_owned())).unwrap();
}

This will return a user permission as a result.

Via iter-like:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let permission = toornament.tournaments_iter()
                               .with_id(TournamentId("1".to_owned()))
                               .permissions()
                               .with_id(PermissionId("2".to_owned()))
                               .collect::<Permission>();
}

Edit tournament's user permission attributes

To edit a user permission attributes of a tournament you can use Toornament::update_tournament_permission_attributes method:

extern crate toornament;
use toornament::*;

fn main() {
    use std::collections::BTreeSet;

    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Define our permission attributes
    let mut attributes = BTreeSet::new();
    attributes.insert(PermissionAttribute::Register);
    attributes.insert(PermissionAttribute::Edit);

    // Update attributes of a permission with id = "2" of a tournament with id = "1"
    let permission = toornament.update_tournament_permission_attributes(
        TournamentId("1".to_owned()),
        PermissionId("2".to_owned()),
        PermissionAttributes(attributes));
}

This will return a new user permission as a result.

Via iter-like:

extern crate toornament;
use toornament::*;

fn main() {
    use std::collections::BTreeSet;

    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let permission = toornament.tournaments_iter()
                               .with_id(TournamentId("1".to_owned()))
                               .permissions()
                               .with_id(PermissionId("2".to_owned()))
                               .attributes()
                               .edit(|_| {
                                   // Define our permission attributes
                                   let mut attributes = BTreeSet::new();
                                   attributes.insert(PermissionAttribute::Register);
                                   attributes.insert(PermissionAttribute::Edit);
                                   PermissionAttributes(attributes)
                               })
                               .update();
}

Delete tournament's user permission

To delete a user permission attributes of a tournament you can use Toornament::delete_tournament_permission method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Delete a permission with id = "2" of a tournament with id = "1"
    let result = toornament.delete_tournament_permission(TournamentId("1".to_owned()),
                                                         PermissionId("2".to_owned()));
}

Via iter-like:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let result = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .permissions()
                           .with_id(PermissionId("2".to_owned()))
                           .delete();
}

Get tournament stages

To fetch stages of a tournament you can use Toornament::tournament_stages method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get stages of a tournament with id = "1"
    let stages = toornament.tournament_stages(TournamentId("1".to_owned()));
}

This will return stages as a result.

Fetching stages via iter-like interface is simple as usual:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let stages = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .stages()
                           .collect::<Stages>();
}

Get tournament stages

To fetch videos of a tournament you can use Toornament::tournament_videos method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Get videos of a tournament with id = "1" with default filter
    let videos = toornament.tournament_videos(TournamentId("1".to_owned()),
                                              TournamentVideosFilter::default());
}

This will return videos as a result.

Fetching videos via iter-like interface is simple as usual:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let videos = toornament.tournaments_iter()
                           .with_id(TournamentId("1".to_owned()))
                           .videos()
                           .collect::<Videos>();
}

Disciplines

This section is about managing game disciplines. Toornament does not have anything but only listing them at this moment. Probably, this will be better in near future.

List disciplines

To fetch all the disciplines you can use Toornament::disciplines method:

extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    // Getting all disciplines
    let all_disciplines = toornament.disciplines(None);
}

This will return all the available disciplines.

To get one particular discipline in details you may use the same endpoint but pass a discipline id there:

// Get discipline by it's id
let wwe2k17_discipline = toornament.disciplines(Some(DisciplineId("wwe2k17".to_owned())));

Via iter-like interface:

let all_disciplines = Disciplines::all();
let wwe2k17_discipline = Discipline::with_id(DisciplineId("wwe2k17".to_owned()));
extern crate toornament;
use toornament::*;

fn main() {
    let toornament = Toornament::with_application("API_TOKEN",
                                                  "CLIENT_ID",
                                                  "CLIENT_SECRET").unwrap()
                                .timeout(5);

    let all = toornament.disciplines_iter()
                        .all()
                        .collect::<Disciplines>();

    let wwe2k17_discipline = toornament.disciplines_iter()
                                       .with_id(DisciplineId("wwe2k17".to_owned()))
                                       .collect::<Discipline>();
}

Contributing

The project awaits for your contributions in:

  1. Developing the library, keeping it up-to-date.
  2. Refactoring the library, improving it's usability in various contexts.
  3. Writing code documentation.
  4. Writing this book.
  5. Writing issues in the repository page.
  6. Library's user feedback.