fr3ddy/laratoor

Laravel Toornament API 包

0.0.5 2018-03-18 23:10 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:01:54 UTC


README

此包将支持您进行任何与官方 Toornament API 相关的开发。在API V2发布后,许多东西都发生了变化。您可以在Toornament页面上找到完整的文档。

安装

可以使用composer轻松安装

    composer require fr3ddy/laratoor

将Fr3ddy\Laratoor\LaratoorServiceProvider::class 添加到您的config/app.php文件中的providers数组

    Fr3ddy\Laratoor\LaratoorServiceProvider::class

Toornament 为您的应用程序添加API令牌。

    TOORNAMENT_KEY=
    TOORNAMENT_CLIENT_ID=
    TOORNAMENT_CLIENT_SECRET=

使用方法

自第二个版本以来,Toornament API已经具有四个不同的层。Viewer API为您提供公开可用的信息。Account API将为您提供访问用户数据的功能。Participant API允许您注册比赛,而organizer API可以帮助您管理比赛。

实现状态

Viewer API: Beta 工作版本,可能需要更多的优化

Account API: Alpha 用户授权已实现,返回的用户数据工作正常。

Participant API: TBD 尚未实现。

Organizer API: TBD Toornament本身尚未实现。

Viewer API

Viewer API 帮助访问数据,如学科、特色比赛、比赛信息等。

过滤器

某些方法允许指定过滤器。这可以通过指定一个包含相应内容的数组来完成。

例如

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    
    $discipline = $viewer->getDiscipline($id);
    $filter = array(
        'is_featured' => 1, //returns matches of featured tournaments
        'statuses' => [ //pass an array of status you want to have in your list
            'pending',
            'running'
        ]
    );
    $matches = $discipline->getAllMatches($filter);

您可以在Toornament API页面上找到过滤可能性,其中相应的API调用作为查询参数。

学科

学科是Toornament支持的不同游戏。这里列出了所有主要游戏及其发行商和一些其他信息。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    
    //Collection of all disciplines
    $disciplines = $viewer->getAllDisciplines();
    //Collection of disciplines with pagination
    $disciplines = $viewer->getDisciplines($from,$to);
    //Discipline without platforms_available & team_size
    $first_discipline = $disciplines->first();
    //Discipline with platforms_available & team_size
    $first_discipline->loadDetails();
    //Discipline with platforms_available & team_size
    $discipline = $viewer->getDiscipline($id);
    //All Matches of this discipline
    $matches = $discipline->getAllMatches($filter);
    //Matches of this discipline with Pagination
    $matches = $discipline->getMatches($filter,$from,$to);

比赛

比赛是一组给定竞争者的竞赛。这些竞争者按照预定义的路径相互比赛。一些竞争者会在途中被淘汰,最终宣布一个竞争者获胜。在Toornament中,竞争者被定义为参与者。预定义的比赛路径被定义为比赛的架构,由阶段、小组、轮次、淘汰赛、排名和比赛组成。比赛可以进一步细化,通常称为游戏或比赛游戏。

来源: Toornament

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    
    //Collection of all featured tournaments with filter
    $tournaments = $viewer->getAllFeaturedTournaments($filter);
    //Collection of featured tournaments with filter and pagination
    $tournaments = $viewer->getFeaturedTournaments($filter,$from,$to);
    //Tournament by Tournamnet ID
    $tournament = $viewer->getTournament($tournament_id);


    //Custom Fields of Teams for this tournament
    $custom_fields_team = $tournament->getCustomFieldsTeam();
    //Custom Fields of Team Players for this tournament
    $custom_fields_teamplayer = $tournament->getCustomFieldsTeamPlayer();
    //Custom Fields of Players for this tournament
    $custom_fields_player = $tournament->getCustomFieldsPlayer(); 

参与者

参与者指的是竞争者在单个比赛中的出席情况。参与者与其比赛相关联。如果一个竞争者参加多个比赛,他将为每个比赛代表一个独特的参与者。参与者在需要明确识别比赛中的竞争者时被引用。例如,为了识别谁在比赛或为了识别竞争者在排名中的排名。

来源: Toornament

参与者可以直接从比赛或通过比赛ID选择。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();

    //By Tournament
    $tournament = $viewer->getTournament($tournament_id);
    //All Participants of this tournament with filter
    $participants = $tournament->getAllParticipants($filter);
    //Participants of this tournament with pagination
    $participants = $tournament->getParticipants($filter,$from,$to);
    //Participant of this tournament
    $participant = $tournament->getParticipant($participant_id);

    //By Tournamnet Id
    //All Participants of this tournament with filter
    $participants = $viewer->getAllParticipantsOfTournament($tournament_id,$filter);
    //Participants of this tournament with pagination
    $participants = $viewer->getParticipantsOfTournament($tournament_id,$filter,$from,$to);
    //Participant of this tournament
    $participant = $viewer->getParticipantOfTournament($tournament_id,$participant_id);

阶段

阶段是锦标赛中的一个主要步骤。其目的是按照特定的和标准化的方法安排和组织一些参赛者的比赛。阶段类型定义了这种方法。目前,Toornament支持六种不同的阶段类型:单败淘汰赛、双败淘汰赛、循环赛小组、分组赛、联赛和瑞士制。每种类型都有自己的方法来安排参与者之间的比赛。根据类型,阶段可能涉及结构中的子元素:小组、轮次、比赛、括号和排名。

来源:Toornament

可以直接从锦标赛或通过锦标赛ID选择阶段。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    
    //By Tournament
    $tournament = $viewer->getTournament($tournament_id);
    //All Stages of this tournament
    $stages = $tournament->getStages();
    //Details of this Stage of this tournament
    $stage = $tournament->getStage($stage_id);

    //By Tournament ID
    //All Stages of this tournament
    $stages = $viewer->getStagesOfTournament($tournament_id);
    //Details of this Stage of this tournament
    $stage = $viewer->getStageOfTournament($tournament_id,$stage_id);

小组

小组代表阶段的一部分,通常只涉及部分参赛者。大多数情况下,由于涉及不同的参赛者,小组可以同时进行。然而,在某些情况下,一个小组可能必须等待另一个小组的结果,以便接收额外的参赛者并继续。某些阶段类型不需要小组。在这种情况下,仍然创建一个单独的小组作为其他阶段的结构占位符。

来源:Toornament

可以直接从锦标赛或使用特定的锦标赛ID选择小组。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    
    //By Tournament
    $tournament = $viewer->getTournament($tournament_id);
    //All Groups of this tournament with filter
    $groups = $tournament->getAllGroups($filter);
    //Groups of this tournament with filter and pagination
    $groups = $tournament->getGroups($filter,$from,$to);
    //Group details of this group of the specific tournament
    $group = $tournament->getGroup($group_id);

    //By Tournament ID
    //All Groups of this tournament with filter
    $groups = $viewer->getAllGroupsOfTournament($tournament_id,$filter);
    //Groups of this tournament with filter and pagination
    $groups = $viewer->getGroupsOfTournament($tournament_id,$filter,$from,$to);
    //Group details of this group of the specific tournament
    $group = $viewer->getGroupOfTournament($tournament_id,$group_id);

轮次

轮次代表小组内部的一个小步骤,其中所有参赛者最多只能进行一场比赛。轮次的目的是在必要时提供一个所有参赛者可以同时进行的步骤。

来源:Toornament

可以直接从锦标赛或使用特定的锦标赛ID选择轮次。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    
    //By Tournament
    $tournament = $viewer->getTournament($tournament_id);
    //Get all Round for this tournament
    $rounds = $tournament->getAllRounds($filter);
    //Get Rounds with pagination for this tournament
    $rounds = $tournament->getRounds($filter,$from,$to);
    //Get Round details
    $round = $tournament->getRound($round_id);

    //By Tournament ID
    //Get all Round for this tournament
    $rounds = $viewer->getAllRoundsOfTournament($tournament_id,$filter);
    //Get Rounds with pagination for this tournament
    $rounds = $viewer->getRoundsOfTournament($tournament_id,$filter,$from,$to);
    //Get Round details
    $round = $viewer->getRoundOfTournament($tournament_id,$round_id);

括号

括号代表一种比赛类型,其中比赛的结果(胜利或失败)决定参赛者下一步的位置。因此,括号中的比赛彼此之间是相连的,通常表示为树状结构。

来源:Toornament

可以直接从锦标赛的阶段或使用特定的锦标赛和阶段ID选择括号。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();

    //By Stage
    $tournament = $viewer->getTournament($tournament_id);
    $stage = $tournament->getStage($stage_id);
    //Get all Brackets of this stage with filter
    $brackets = $stage->getAllBrackets($filter);
    //Get Brackets of this stage with filter and pagination
    $brackets = $stage->getAllBrackets($filter,$from,$to);
    
    //By Tournament and Stage id
    //Get all Brackets of this stage with filter
    $brackets = $viewer->getAllBracketsOfStageInTournament($tournament_id,$stage_id,$filter);
    //Get Brackets of this stage with filter and pagination
    $brackets = $viewer->getBracketsOfStageInTournament($tournament_id,$stage_id,$filter,$from,$to);

排名

排名代表一种比赛类型,其中比赛的结果会给参赛者积分。然后使用这些积分来计算排名。一旦阶段或小组完成,排名就用来确定阶段中参赛者的最终位置。

来源:Toornament

可以直接从锦标赛的阶段或使用特定的锦标赛和阶段ID选择排名。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();

    //By Stage
    $tournament = $viewer->getTournament($tournament_id);
    $stage = $tournament->getStage($stage_id);
    //Get all Brackets of this stage with filter
    $rankings = $stage->getAllRankings($filter);
    //Get Brackets of this stage with filter and pagination
    $rankings = $stage->getRankings($filter,$from,$to);
    
    //By Tournament and Stage id
    //Get all Brackets of this stage with filter
    $rankings = $viewer->getAllRankingsOfStageInTournament($tournament_id,$stage_id,$filter);
    //Get Brackets of this stage with filter and pagination
    $rankings = $viewer->getRankingsOfStageInTournament($tournament_id,$stage_id,$filter,$from,$to);

比赛

比赛是一种小型的结构化游戏形式,涉及一个或多个参赛者。这些参赛者根据比赛格式相互比赛,并可能涉及较小的游戏步骤(如游戏或比赛游戏)。最后,通过比赛格式定义结果。根据比赛中涉及参赛者的数量,结果计算方式不同。当比赛只涉及两个参赛者时,它被标记为对决,结果描述为胜利、平局或失败。当比赛涉及两个以上参赛者时,它被标记为全战,结果描述为排名。比赛包含比赛对手。这些对手像插槽一样,在某个时刻需要收到参赛者。比赛对手包含一个编号和参赛者的比赛相关数据,如他的分数、他的结果和其他游戏信息。

来源:Toornament

可以直接从锦标赛的阶段或使用特定的锦标赛和阶段ID选择排名。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();

    //By Tournament
    $tournament = $viewer->getTournament($tournament_id);
    //All Matches with filter
    $matches = $tournament->getAllMatches($filter);
    //Matches with filter and pagination
    $matches = $tournament->getMatches($filter,$from,$to);
    //Match Details for one match of this tournament
    $match = $tournament->getMatch($match_id);

    //By Tournament ID
    //All Matches with filter
    $matches = $viewer->getAllMatchesOfTournament($tournament_id,$filter);
    //Matches with filter and pagination
    $matches = $viewer->getMatchesOfTournament($tournament_id,$filter,$from,$to);
    //Match Details for one match of this tournament
    $match = $viewer->getMatchOfTournament($tournament_id,$match_id);
比赛游戏

比赛游戏是比赛的一个子集,描述了比赛的一部分。通常在这里可以找到特定领域的相关信息,如地图或模式。比赛游戏包含比赛游戏对手。他们与比赛中的对手编号相同,因此不需要包含参与者。它们还包含比赛游戏相关的数据,如得分和结果,以及特定领域的相关信息,如角色。

来源:Toornament

比赛游戏只能由锦标赛的比赛接收。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();

    //By Tournament
    $tournament = $viewer->getTournament($tournament_id);
    $match = $tournament->getMatch($match_id);
    //Get all games
    $games = $match->getGames();
    //Get game number 1
    $game = $match->getGame(1);

关系

基于Toornament设计的结构,每个元素都可以接收其父元素。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();
    $match = $viewer->getMatchOfTournament($tournament_id,$match_id);
    $tournament = $match->getTournament();

附加内容

Toornament还提供了有关附加的流和视频的详细信息,这些视频附属于锦标赛或比赛。可以使用元素的ID或直接从元素中选择。

    use Fr3ddy\Laratoor\ViewerApi;

    $viewer = new ViewerApi();

    //By IDs
    //Get all Streams of the tournament with filter
    $streams = $viewer->getAllStreamsOfTournament($tournament_id,$filter);
    //Get Streams with filter and pagination
    $streams = $viewer->getStreamsOfTournament($tournament_id,$filter,$from,$to);
    //Get all Videos of a tournament with filter
    $videos = $viewer->getAllVideosOfTournament($tournament_id,$filter);
    //Get Videos of tournament with filter and pagination
    $videos = $viewer->getVideosOfTournament($tournament_id,$filter,$from,$to);
    //Get all Videos of a match in the tournament with filter
    $videos = $viewer->getAllVideosOfMatchInTournament($tournament_id,$match_id,$filter);

    //By element
    $tournament = $viewer->getTournament($tournament_id);
    $match = $tournament->getMatch($match_id);
    //Get all Streams of the tournament with filter
    $streams = $tournament->getAllStreams($filter);
    //Get Streams with filter and pagination
    $streams = $tournament->getStreams($filter,$from,$to);
    //Get all Videos of a tournament with filter
    $videos = $tournament->getAllVideos($filter);
    //Get Videos of tournament with filter and pagination
    $videos = $tournament->getVideos($filter,$from,$to);
    //Get all Videos of a match in the tournament with filter
    $videos = $match->getAllVideos($filter);

账户API

使用账户API,您可以访问已登录用户的用户数据。您的访客必须通过Toornaments的oAuth2端点进行登录。为此,您需要在.env文件中设置TOORNAMENT_CLIENT_ID和TOORNAMENT_CLIENT_SECRET。此外,您还需要在Toornament中设置您的重定向URL。为此,您必须访问Toornament开发者页面并设置您正在工作的相应应用程序的重定向URL为 https://yourdomain.com/toornament/redirect。不要在意这个重定向URL,您可以在应用程序中设置自己的URL,这个URL只是为了使过程尽可能简单。

    use Fr3ddy\Laratoor\AccountApi;

    Route::get('/', function () {
        $accountApi = new AccountApi();
        echo '<a href="'.$accountApi->getAuthUrl(url('/authorized')).'">Click me</a>';
    });

    Route::get('/authorized',function(){
        $accountApi = new AccountApi();
        $user = $accountApi->getUser();
        echo 'Hello '.$user->name.' from '.$user->country.'.';
    });

这两个步骤就像这样简单,您的用户已经登录,您就可以访问他的个人数据。

参与者API

待定

组织者API

即将推出

免责声明

本软件包与Oxent或任何与Toornament相关的公司没有任何关联。