[][src]Struct toornament::Toornament

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]

pub fn with_application<S: Into<String>>(
    api_token: S,
    client_id: S,
    client_secret: S
) -> Result<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] (https://developer.toornament.com/applications/) (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());

pub fn refresh(&self) -> bool[src]

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

pub fn timeout(self, seconds: u64) -> Result<Toornament>[src]

Consumes Toornament object and sets timeout to it

pub fn tournaments_iter(&self) -> TournamentsIter[src]

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

pub fn disciplines_iter(&self) -> DisciplinesIter[src]

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

pub fn disciplines(&self, id: Option<DisciplineId>) -> Result<Disciplines>[src]

[Returns either a collection of disciplines] (https://developer.toornament.com/doc/disciplines#get:disciplines) if id is None or [a disciplines with the detail of his features] (https://developer.toornament.com/doc/disciplines#get:disciplines:id)

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()));

pub fn tournaments(
    &self,
    tournament_id: Option<TournamentId>,
    with_streams: bool
) -> Result<Tournaments>
[src]

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.] (https://developer.toornament.com/doc/tournaments#get:tournaments:id)

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())));

pub fn edit_tournament(&self, tournament: Tournament) -> Result<Tournament>[src]

[Updates some of the editable information on a tournament.] (https://developer.toornament.com/doc/tournaments#patch:tournaments:id) if tournament.id is set otherwise [creates a tournament] (https://developer.toornament.com/doc/tournaments#post:tournaments).

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()));

pub fn delete_tournament(&self, id: TournamentId) -> Result<()>[src]

[Deletes a tournament, its participants and all its matches] (https://developer.toornament.com/doc/tournaments#delete:tournaments:id).

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());

pub fn my_tournaments(&self) -> Result<Tournaments>[src]

[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).] (https://developer.toornament.com/doc/tournaments#get:metournaments)

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();

pub fn matches(
    &self,
    tournament_id: TournamentId,
    match_id: Option<MatchId>,
    with_games: bool
) -> Result<Matches>
[src]

[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.] (https://developer.toornament.com/doc/matches#get:tournaments:tournament_id:matches)

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();

pub fn matches_by_discipline(
    &self,
    discipline_id: DisciplineId,
    filter: MatchFilter
) -> Result<Matches>
[src]

[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.] (https://developer.toornament.com/doc/matches#get:tournaments:tournament_id:matches)

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();

pub fn update_match(
    &self,
    tournament_id: TournamentId,
    match_id: MatchId,
    updated_match: Match
) -> Result<Match>
[src]

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);

pub fn match_result(
    &self,
    id: TournamentId,
    match_id: MatchId
) -> Result<MatchResult>
[src]

[Returns detailed result about one match.] (https://developer.toornament.com/doc/matches#get:tournaments:tournament_id:matches:id:result)

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();

pub fn set_match_result(
    &self,
    id: TournamentId,
    match_id: MatchId,
    result: MatchResult
) -> Result<MatchResult>
[src]

[Update or create detailed result about one match.] (https://developer.toornament.com/doc/matches#put:tournaments:tournament_id:matches:id:result)

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());

pub fn match_games(
    &self,
    tournament_id: TournamentId,
    match_id: MatchId,
    with_stats: bool
) -> Result<Games>
[src]

[Returns a collection of games from one match.] (https://developer.toornament.com/doc/games#get:tournaments:tournament_id:matches:match_id:games)

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();

pub fn match_game(
    &self,
    tournament_id: TournamentId,
    match_id: MatchId,
    game_number: GameNumber,
    with_stats: bool
) -> Result<Game>
[src]

[Returns detailed information about one game.] (https://developer.toornament.com/doc/games?#get:tournaments:tournament_id:matches:match_id:games:number)

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();

pub fn update_match_game(
    &self,
    tournament_id: TournamentId,
    match_id: MatchId,
    game_number: GameNumber,
    game: Game
) -> Result<Game>
[src]

[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.] (https://developer.toornament.com/doc/games?#patch:tournaments:tournament_id:matches:match_id:games:number)

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());

pub fn match_game_result(
    &self,
    tournament_id: TournamentId,
    match_id: MatchId,
    game_number: GameNumber
) -> Result<MatchResult>
[src]

[Returns detailed result about one specific game.] (https://developer.toornament.com/doc/games?#get:tournaments:tournament_id:matches:match_id:games:number:result)

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());

pub fn update_match_game_result(
    &self,
    tournament_id: TournamentId,
    match_id: MatchId,
    game_number: GameNumber,
    result: MatchResult,
    update_match: bool
) -> Result<MatchResult>
[src]

[Updates or creates detailed result about one game.] (https://developer.toornament.com/doc/games?#put:tournaments:tournament_id:matches:match_id:games:number:result)

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());

pub fn tournament_participants(
    &self,
    tournament_id: TournamentId,
    filter: TournamentParticipantsFilter
) -> Result<Participants>
[src]

[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.] (https://developer.toornament.com/doc/participant#get:tournaments:tournament_id:participants)

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();

pub fn create_tournament_participant(
    &self,
    id: TournamentId,
    participant: Participant
) -> Result<Participant>
[src]

[Create a participant in a tournament.] (https://developer.toornament.com/doc/participants?#post:tournaments:tournament_id:participants)

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());

pub fn update_tournament_participants(
    &self,
    id: TournamentId,
    participants: Participants
) -> Result<Participants>
[src]

[Create a list of participants in a tournament. If any participant already exists he will be erased.] (https://developer.toornament.com/doc/participants?_locale=en#put:tournaments:tournament_id:participants)

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);

pub fn tournament_participant(
    &self,
    id: TournamentId,
    participant_id: ParticipantId
) -> Result<Participant>
[src]

[Returns detailed information about one participant.] (https://developer.toornament.com/doc/participants?_locale=en#get:tournaments:tournament_id:participants:id)

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())));

pub fn update_tournament_participant(
    &self,
    id: TournamentId,
    participant_id: ParticipantId,
    participant: Participant
) -> Result<Participant>
[src]

[Update some of the editable information on a participant.] (https://developer.toornament.com/doc/participants?_locale=en#patch:tournaments:tournament_id:participants:id)

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");

pub fn delete_tournament_participant(
    &self,
    id: TournamentId,
    participant_id: ParticipantId
) -> Result<()>
[src]

[Deletes one participant.] (https://developer.toornament.com/doc/participants?_locale=en#delete:tournaments:tournament_id:participants:id)

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());

pub fn tournament_permissions(&self, id: TournamentId) -> Result<Permissions>[src]

[Returns a collection of permission from one tournament.] (https://developer.toornament.com/doc/permissions?_locale=en#get:tournaments:tournament_id:permissions)

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();

pub fn create_tournament_permission(
    &self,
    id: TournamentId,
    permission: Permission
) -> Result<Permission>
[src]

[Create a permission for a user on a tournament.] (https://developer.toornament.com/doc/permissions?_locale=en#post:tournaments:tournament_id:permissions)

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);

pub fn tournament_permission(
    &self,
    id: TournamentId,
    permission_id: PermissionId
) -> Result<Permission>
[src]

[Retrieves a permission of a tournament.] (https://developer.toornament.com/doc/permissions?_locale=en#get:tournaments:tournament_id:permissions:permission_id)

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())));

pub fn update_tournament_permission_attributes(
    &self,
    id: TournamentId,
    permission_id: PermissionId,
    attributes: PermissionAttributes
) -> Result<Permission>
[src]

[Update rights of a permission.] (https://developer.toornament.com/doc/permissions?_locale=en#patch:tournaments:tournament_id:permissions:permission_id)

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());

pub fn delete_tournament_permission(
    &self,
    id: TournamentId,
    permission_id: PermissionId
) -> Result<()>
[src]

[Delete a user permission of a tournament.] (https://developer.toornament.com/doc/permissions?_locale=en#delete:tournaments:tournament_id:permissions:permission_id)

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());

pub fn tournament_stages(&self, id: TournamentId) -> Result<Stages>[src]

[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.] (https://developer.toornament.com/doc/stages?_locale=en#get:tournaments:tournament_id:stages)

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();

pub fn tournament_videos(
    &self,
    tournament_id: TournamentId,
    filter: TournamentVideosFilter
) -> Result<Videos>
[src]

[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.] (https://developer.toornament.com/doc/videos?_locale=en#get:tournaments:tournament_id:videos)

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]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.