Struct toornament::Toornament [] [src]

pub struct Toornament { /* fields omitted */ }

Main structure. Should be your point of start using the service. This struct covers all the toornament API.

Methods

impl Toornament
[src]

Creates new Toornament object with client credentials which is your user API_Token, application's client id and secret. You may obtain application's credentials here (You must be logged in to open the page). This method connects to the toornament service and if there is a error it returns the Error object and on success it returns Toornament object.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET");
assert!(t.is_ok());

Refreshes the oauth token. Automatically used when it is expired.

Consumes Toornament object and sets timeout to it

Returns Iterator-like objects to work with tournaments and it's subobjects.

Returns Iterator-like objects to work with disciplines and it's subobjects.

Returns either a collection of disciplines if id is None or a disciplines with the detail of his features

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Getting all disciplines
let all_disciplines: Disciplines = t.disciplines(None).unwrap();
// Get discipline by it's id
let wwe2k17_discipline = t.disciplines(Some(DisciplineId("wwe2k17".to_owned()))).unwrap();
assert_eq!(wwe2k17_discipline.0.len(), 1);
assert_eq!(wwe2k17_discipline.0.first().unwrap().id,
DisciplineId("wwe2k17".to_owned()));

Returns a collection of public tournaments filtered and sorted by the given query parameters. A maximum of 20 tournaments will be returned. Only public tournaments are visible. if id is None or a detailed information about one tournament. The tournament must be public.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Getting all tournaments
let all_tournaments: Tournaments = t.tournaments(None, true).unwrap();
// Get tournament by it's id
let tournament = t.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())));

Updates some of the editable information on a tournament. if tournament.id is set otherwise creates a tournament.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get tournament by it's id
let tournaments = t.tournaments(Some(TournamentId("1".to_owned())), true).unwrap();
assert_eq!(tournaments.0.len(), 1);
let mut tournament = tournaments.0.first().unwrap().clone();
assert_eq!(tournament.id, Some(TournamentId("1".to_owned())));
tournament = tournament.website(Some("https://toornament.com".to_owned()));
// Editing tournament by calling the appropriate method
let tournament = t.edit_tournament(tournament.clone()).unwrap();
assert_eq!(tournament.website,
Some("https://toornament.com".to_owned()));

Deletes a tournament, its participants and all its matches.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Deleting tournament with id = "1"
assert!(t.delete_tournament(TournamentId("1".to_owned())).is_ok());

Returns the private and public tournaments on which the authenticated user has access. The result is filtered, sorted and paginated by the given query parameters. A maximum of 50 tournaments is returned (per page).

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get all my tournaments
let tournaments = t.my_tournaments().unwrap();

Returns a collection of matches from one tournament. The collection may be filtered and sorted by optional query parameters. The tournament must be public to have access to its matches, meaning the tournament organizer has published it.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get all matches of a tournament with id = "1"
let matches = t.matches(TournamentId("1".to_owned()), None, true).unwrap();
// Get match with match id = "2" of a tournament with id = "1"
let matches = t.matches(TournamentId("1".to_owned()), Some(MatchId("2".to_owned())), true).unwrap();

Retrieve a collection of matches from a specific discipline, filtered and sorted by the given query parameters. It might be a list of matches from different tournaments, but only from public tournaments. The matches are returned by 20.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get all matches by a discipline with id = "1" with default filter
let matches = t.matches_by_discipline(DisciplineId("1".to_owned()), MatchFilter::default()).unwrap();

If you need to make changes on your match data, you are able to do so by patching one or several fields of your match.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a match with id = "2" of a tournament with id = "1"
let matches = t.matches(TournamentId("1".to_owned()),
                        Some(MatchId("2".to_owned())),
                        true).unwrap();
let mut match_to_edit = matches.0.first().unwrap().clone()
                               .number(2u64);
match_to_edit = t.update_match(TournamentId("1".to_owned()),
                               MatchId("2".to_owned()),
                               match_to_edit).unwrap();
assert_eq!(match_to_edit.number, 2u64);

Returns detailed result about one match.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a match result of a match with id = "2" of a tournament with id = "1"
let result = t.match_result(TournamentId("1".to_owned()),
                            MatchId("2".to_owned())).unwrap();

Update or create detailed result about one match.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// 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"
assert!(t.set_match_result(TournamentId("1".to_owned()),
                           MatchId("2".to_owned()),
                           result).is_ok());

Returns a collection of games from one match.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get match games of a match with id = "2" of a tournament with id = "1"
let games = t.match_games(TournamentId("1".to_owned()),
                          MatchId("2".to_owned()),
                          true).unwrap();

Returns detailed information about one game.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a match game with number "3" of a match with id = "2" of a tournament with id = "1"
let game = t.match_game(TournamentId("1".to_owned()),
                        MatchId("2".to_owned()),
                        GameNumber(3i64),
                        true).unwrap();

If you need to make changes on your game data, you are able to do so by patching one or several fields of your game.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
let 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"
assert!(t.update_match_game(TournamentId("1".to_owned()),
                            MatchId("2".to_owned()),
                            GameNumber(3i64),
                            game).is_ok());

Returns detailed result about one specific game.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a match game result with number "3" of a match with id = "2" of a tournament with id = "1"
assert!(t.match_game_result(TournamentId("1".to_owned()),
                            MatchId("2".to_owned()),
                            GameNumber(3i64)).is_ok());

Updates or creates detailed result about one game.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Define a result
let result = MatchResult {
    status: MatchStatus::Completed,
    opponents: Opponents::default(),
};
// Update a match game result with number "3" of a match with id = "2" of a tournament with id = "1"
assert!(t.update_match_game_result(TournamentId("1".to_owned()),
                                   MatchId("2".to_owned()),
                                   GameNumber(3i64),
                                   result,
                                   true).is_ok());

Returns a collection of participants from one tournament. The tournament must be public to have access to its participants, meaning the tournament organizer has published it. The participants are returned by 256.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get participants of a tournament with id = "1" with default filter
let participants = t.tournament_participants(
    TournamentId("1".to_owned()),
    TournamentParticipantsFilter::default()).unwrap();

Create a participant in a tournament.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Define a participant
let participant = Participant::create("Test participant");
// Create a participant for a tournament with id = "1"
let participant = t.create_tournament_participant(TournamentId("1".to_owned()),
                                                  participant).unwrap();
assert!(participant.id.is_some());

Create a list of participants in a tournament. If any participant already exists he will be erased.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
let mut participants = vec![Participant::create("First participant"),
                            Participant::create("Second participant")];
// Update a participant for a tournament with id = "1"
let new_participants = t.update_tournament_participants(TournamentId("1".to_owned()),
                                                        Participants(participants)).unwrap();
assert_eq!(new_participants.0.len(), 2);

Returns detailed information about one participant.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a participant with id = "2" of a tournament with id = "1"
let participant = t.tournament_participant(TournamentId("1".to_owned()),
                                           ParticipantId("2".to_owned())).unwrap();
assert_eq!(participant.id, Some(ParticipantId("2".to_owned())));

Update some of the editable information on a participant.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a participant with id = "2" of a tournament with id = "1"
let mut participant = t.tournament_participant(TournamentId("1".to_owned()),
                                               ParticipantId("2".to_owned())).unwrap();
assert_eq!(participant.id, Some(ParticipantId("2".to_owned())));
// Update the participant's name and send it
participant = participant.name("Updated participant name here".to_owned());
let updated_participant = t.update_tournament_participant(
    TournamentId("1".to_owned()),
    ParticipantId("2".to_owned()),
    participant).unwrap();
assert_eq!(updated_participant.id, Some(ParticipantId("2".to_owned())));
assert_eq!(updated_participant.name, "Updated participant name here");

Deletes one participant.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Delete a participant with id = "2" of a tournament with id = "1"
assert!(t.delete_tournament_participant(TournamentId("1".to_owned()),
                                        ParticipantId("2".to_owned())).is_ok());

Returns a collection of permission from one tournament.

Example

use toornament::*;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get permissions of a tournament with id = "1"
let permissions = t.tournament_permissions(TournamentId("1".to_owned())).unwrap();

Create a permission for a user on a tournament.

Example

use toornament::*;
use std::collections::BTreeSet;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// 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 = t.create_tournament_permission(TournamentId("1".to_owned()),
                                                    permission).unwrap();
assert!(new_permission.id.is_some());
assert_eq!(new_permission.email, "test@mail.ru");
assert_eq!(new_permission.attributes.0.len(), 2);

Retrieves a permission of a tournament.

Example

use toornament::*;
use std::collections::BTreeSet;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get a permission with id = "2" of a tournament with id = "1"
let permission = t.tournament_permission(TournamentId("1".to_owned()),
                                         PermissionId("2".to_owned())).unwrap();
assert_eq!(permission.id, Some(PermissionId("2".to_owned())));

Update rights of a permission.

Example

use toornament::*;
use std::collections::BTreeSet;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// 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 = t.update_tournament_permission_attributes(
    TournamentId("1".to_owned()),
    PermissionId("2".to_owned()),
    PermissionAttributes(attributes)).unwrap();
assert_eq!(permission.id, Some(PermissionId("2".to_owned())));
assert_eq!(permission.attributes.0.len(), 2);
assert!(permission.attributes.0.iter().find(|p| *p == &PermissionAttribute::Edit).is_some());
assert!(permission.attributes.0.iter().find(|p| *p == &PermissionAttribute::Register).is_some());

Delete a user permission of a tournament.

Example

use toornament::*;
use std::collections::BTreeSet;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Delete a permission with id = "2" of a tournament with id = "1"
assert!(t.delete_tournament_permission(
    TournamentId("1".to_owned()),
    PermissionId("2".to_owned())).is_ok());

Returns a collection of stages from one tournament. The tournament must be public to have access to its stages, meaning the tournament organizer must publish it.

Example

use toornament::*;
use std::collections::BTreeSet;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get stages of a tournament with id = "1"
let stages = t.tournament_stages(TournamentId("1".to_owned())).unwrap();

Returns a collection of videos from one tournament. The collection may be filtered and sorted by optional query parameters. The tournament must be public to have access to its videos, meaning the tournament organizer has published it. The videos are returned by 20.

Example

use toornament::*;
use std::collections::BTreeSet;
let t = Toornament::with_application("API_TOKEN",
                                     "CLIENT_ID",
                                     "CLIENT_SECRET").unwrap();
// Get videos of a tournament with id = "1" with default filter
let videos = t.tournament_videos(TournamentId("1".to_owned()),
                                 TournamentVideosFilter::default()).unwrap();

Trait Implementations

impl Debug for Toornament
[src]

Formats the value using the given formatter.