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]
fn with_application<S: Into<String>>(
api_token: S,
client_id: S,
client_secret: S
) -> Result<Toornament>
api_token: S,
client_id: S,
client_secret: S
) -> Result<Toornament>
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());
fn refresh(&self) -> bool
Refreshes the oauth token. Automatically used when it is expired.
fn timeout(self, seconds: u64) -> Toornament
Consumes Toornament
object and sets timeout to it
fn tournaments_iter(&self) -> TournamentsIter
Returns Iterator-like objects to work with tournaments and it's subobjects.
fn disciplines_iter(&self) -> DisciplinesIter
Returns Iterator-like objects to work with disciplines and it's subobjects.
fn disciplines(&self, id: Option<DisciplineId>) -> Result<Disciplines>
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()));
fn tournaments(
&self,
id: Option<TournamentId>,
with_streams: bool
) -> Result<Tournaments>
&self,
id: Option<TournamentId>,
with_streams: bool
) -> Result<Tournaments>
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())));
fn edit_tournament(&self, tournament: Tournament) -> Result<Tournament>
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()));
fn delete_tournament(&self, id: TournamentId) -> Result<()>
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());
fn my_tournaments(&self) -> Result<Tournaments>
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();
fn matches(
&self,
id: TournamentId,
match_id: Option<MatchId>,
with_games: bool
) -> Result<Matches>
&self,
id: TournamentId,
match_id: Option<MatchId>,
with_games: bool
) -> Result<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();
fn matches_by_discipline(
&self,
id: DisciplineId,
filter: MatchFilter
) -> Result<Matches>
&self,
id: DisciplineId,
filter: MatchFilter
) -> Result<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();
fn update_match(
&self,
id: TournamentId,
match_id: MatchId,
updated_match: Match
) -> Result<Match>
&self,
id: TournamentId,
match_id: MatchId,
updated_match: Match
) -> Result<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);
fn match_result(
&self,
id: TournamentId,
match_id: MatchId
) -> Result<MatchResult>
&self,
id: TournamentId,
match_id: MatchId
) -> Result<MatchResult>
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();
fn set_match_result(
&self,
id: TournamentId,
match_id: MatchId,
result: MatchResult
) -> Result<MatchResult>
&self,
id: TournamentId,
match_id: MatchId,
result: MatchResult
) -> Result<MatchResult>
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());
fn match_games(
&self,
id: TournamentId,
match_id: MatchId,
with_stats: bool
) -> Result<Games>
&self,
id: TournamentId,
match_id: MatchId,
with_stats: bool
) -> Result<Games>
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();
fn match_game(
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber,
with_stats: bool
) -> Result<Game>
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber,
with_stats: bool
) -> Result<Game>
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();
fn update_match_game(
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber,
game: Game
) -> Result<Game>
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber,
game: Game
) -> Result<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());
fn match_game_result(
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber
) -> Result<MatchResult>
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber
) -> Result<MatchResult>
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());
fn update_match_game_result(
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber,
result: MatchResult,
update_match: bool
) -> Result<MatchResult>
&self,
id: TournamentId,
match_id: MatchId,
game_number: GameNumber,
result: MatchResult,
update_match: bool
) -> Result<MatchResult>
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());
fn tournament_participants(
&self,
id: TournamentId,
filter: TournamentParticipantsFilter
) -> Result<Participants>
&self,
id: TournamentId,
filter: TournamentParticipantsFilter
) -> Result<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();
fn create_tournament_participant(
&self,
id: TournamentId,
participant: Participant
) -> Result<Participant>
&self,
id: TournamentId,
participant: Participant
) -> Result<Participant>
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());
fn update_tournament_participants(
&self,
id: TournamentId,
participants: Participants
) -> Result<Participants>
&self,
id: TournamentId,
participants: Participants
) -> Result<Participants>
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);
fn tournament_participant(
&self,
id: TournamentId,
participant_id: ParticipantId
) -> Result<Participant>
&self,
id: TournamentId,
participant_id: ParticipantId
) -> Result<Participant>
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())));
fn update_tournament_participant(
&self,
id: TournamentId,
participant_id: ParticipantId,
participant: Participant
) -> Result<Participant>
&self,
id: TournamentId,
participant_id: ParticipantId,
participant: Participant
) -> Result<Participant>
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");
fn delete_tournament_participant(
&self,
id: TournamentId,
participant_id: ParticipantId
) -> Result<()>
&self,
id: TournamentId,
participant_id: ParticipantId
) -> Result<()>
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());
fn tournament_permissions(&self, id: TournamentId) -> Result<Permissions>
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();
fn create_tournament_permission(
&self,
id: TournamentId,
permission: Permission
) -> Result<Permission>
&self,
id: TournamentId,
permission: Permission
) -> Result<Permission>
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);
fn tournament_permission(
&self,
id: TournamentId,
permission_id: PermissionId
) -> Result<Permission>
&self,
id: TournamentId,
permission_id: PermissionId
) -> Result<Permission>
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())));
fn update_tournament_permission_attributes(
&self,
id: TournamentId,
permission_id: PermissionId,
attributes: PermissionAttributes
) -> Result<Permission>
&self,
id: TournamentId,
permission_id: PermissionId,
attributes: PermissionAttributes
) -> Result<Permission>
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());
fn delete_tournament_permission(
&self,
id: TournamentId,
permission_id: PermissionId
) -> Result<()>
&self,
id: TournamentId,
permission_id: PermissionId
) -> Result<()>
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());
fn tournament_stages(&self, id: TournamentId) -> Result<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();
fn tournament_videos(
&self,
id: TournamentId,
filter: TournamentVideosFilter
) -> Result<Videos>
&self,
id: TournamentId,
filter: TournamentVideosFilter
) -> Result<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();