Page 1 of 8 1 2 3 ... LastLast
Results 1 to 10 of 71

Thread: Another way for API processing with PHP

  1. #1
    Basic Member GelioS's Avatar
    Join Date
    Aug 2012
    Posts
    130

    Another way for API processing with PHP

    First of all I want say great thanks to Valve for this API.

    For the last few weeks (and a little bit on September 2012) I have been working on a simple API wrapper. And I think that I am on the right way

    List of supported API-requests:
    • GetMatchHistory
    • GetMatchDetails
    • GetPlayerSummaries
    • GetLeagueListing
    • GetLiveLeagueGames
    • GetTeamInfoByTeamID
    • GetHeroes


    Match view demo (put your match_id in the url)

    All code can be found on github https://github.com/kronusme/dota2-api.

    And few examples:

    Load some match-info
    PHP Code:
    <?php
    require_once ('config.php');
    $mm = new match_mapper_web(121995119);
    $match $mm->load();
    Work with match-object
    PHP Code:
    <?php
    require_once ('config.php');
    $mm = new match_mapper_web(121995119);
    $match $mm->load();
    echo 
    $match->get('match_id');
    echo 
    $match->get('start_time');
    echo 
    $match->get('game_mode');
    $slots $match->get_all_slots();
    foreach(
    $slots as $slot) {
        echo 
    $slot->get('last_hits');
    }
    print_r($match->get_data_array());
    print_r($match->get_slot(0)->get_data_array());
    Save match-info in the database
    PHP Code:
    <?php
    require_once ('config.php');
    $mm = new match_mapper_web(121995119);
    $match $mm->load();
    $saver = new match_mapper_db();
    $saver->save($match);
    I want get all matches with some player
    PHP Code:
    <?php
    require_once ('config.php');
    $matches_mapper_web = new matches_mapper_web();
    $matches_mapper_web->set_account_id(93712171);
    $matches_short_info $matches_mapper_web->load();
    foreach (
    $matches_short_info AS $key=>$match_short_info) {
        
    $match_mapper = new match_mapper_web($key);
        
    $match $match_mapper->load();
        
    $mm = new match_mapper_db();
        
    $mm->save($match);
    }
    Get player info
    PHP Code:
    <?php
    require_once ('config.php');
    $players_mapper_web = new players_mapper_web();
    $players_info $players_mapper_web->add_id('76561198067833250')->add_id('76561198058587506')->load();
    foreach(
    $players_info as $player_info) {
        echo 
    $player_info->get('realname');
        echo 
    '<img src="'.$player_info->get('avatarfull').'" alt="'.$player_info->get('personaname').'" />';
        echo 
    '<a href="'.$player_info->get('profileurl').'">'.$player_info->get('personaname').'\'s steam profile</a>';
    }
    print_r($players_info);
    Get team info
    PHP Code:
    <?php
    $teams_mapper_web 
    = new teams_mapper_web();
    $teams $teams_mapper_web->set_team_id(2)->set_teams_requested(2)->load();
    foreach(
    $teams as $team) {
        echo 
    $team->get('name');
        echo 
    $team->get('rating');
        echo 
    $team->get('country_code');
        
    print_r($team->get_all_leagues_ids());
    }
    Get current heroes list
    PHP Code:
    <?php
    require_once ('config.php');
    $heroes_mapper = new heroes_mapper();
    $heroes $heroes_mapper->load();
    print_r($heroes);
    Get leagues list
    PHP Code:
    <?php
    require_once ('config.php');
    $leagues_mapper = new leagues_mapper();
    $leagues $leagues_mapper->load();
    foreach(
    $leagues as $league) {
        echo 
    $league['description'];
        if (
    $league['tournament_url']) {
            echo 
    $league['tournament_url'];
        }
     }
    Get live leagues matches
    PHP Code:
    <?php
    require_once ('config.php');
    $league_mapper = new league_mapper(22); // set league id (can be get via leagues_mapper)
    $games $league_mapper->load();
    print_r($games);
    Last edited by GelioS; 03-10-2013 at 11:35 AM. Reason: New examples added

  2. #2
    Basic Member GelioS's Avatar
    Join Date
    Aug 2012
    Posts
    130
    Added teams and players parsers.

    Teams:
    PHP Code:
    <?php
    require_once ('config.php');
    $teams_mapper_web = new teams_mapper_web();
    $teams $teams_mapper_web->set_team_id(2)->set_teams_requested(2)->load();
    print_r($teams);
    Players:
    PHP Code:
    <?php
    require_once ('config.php');
    $players_mapper_web = new players_mapper_web();
    $info $players_mapper_web->add_id('76561198067833250')->add_id('76561198058587506')->load();
    print_r($info);

  3. #3
    Basic Member GelioS's Avatar
    Join Date
    Aug 2012
    Posts
    130
    More API features supported.
    Look at readme examples on the GitHub - https://github.com/kronusme/dota2-api.

    DotA 2 Web API Processing with PHP
    DotA2 Statistic - Professional leagues statistic
    follow @dota2statistic

  4. #4
    Basic Member GelioS's Avatar
    Join Date
    Aug 2012
    Posts
    130
    Huge update - more examples, comments, code review etc.

    List of supported API-requests:
    • GetMatchHistory
    • GetMatchDetails
    • GetPlayerSummaries
    • GetLeagueListing
    • GetLiveLeagueGames
    • GetTeamInfoByTeamID
    • GetHeroes

    https://github.com/kronusme/dota2-api

    First post is updated.
    Last edited by GelioS; 02-21-2013 at 03:36 PM.

    DotA 2 Web API Processing with PHP
    DotA2 Statistic - Professional leagues statistic
    follow @dota2statistic

  5. #5
    Basic Member SAK_ATAK's Avatar
    Join Date
    Nov 2011
    Posts
    540
    Just wanted to say this looks really cool and I will probably look into it sometime. I myself have done a few API libraries and I know how much of a pain they can be to make (at least in java and C# they are). kudos!

  6. #6

  7. #7
    Basic Member GelioS's Avatar
    Join Date
    Aug 2012
    Posts
    130
    Additional units support added (testing now) - click.

    DotA 2 Web API Processing with PHP
    DotA2 Statistic - Professional leagues statistic
    follow @dota2statistic

  8. #8
    Basic Member GelioS's Avatar
    Join Date
    Aug 2012
    Posts
    130
    Update:
    • JSON data about heroes, abilities, items, lobbies, mods and new processing for it
    • New method for picks and bans - get divided by team and state
    • New method for match model - get set of the slots divided to Dire and Radiant
    • XML error handling support for mappers


    Match view demo (put your match_id in the url)

    DotA 2 Web API Processing with PHP
    DotA2 Statistic - Professional leagues statistic
    follow @dota2statistic

  9. #9
    Basic Member
    Join Date
    Nov 2011
    Posts
    111
    Nice design! Glad to see dotareport.net isn't the only one who is inspired by us

  10. #10
    Basic Member
    Join Date
    Mar 2013
    Posts
    20
    Just wanted to say that you have done an awesome job! To anyone using the api just a quick tip that i somehow missed -> since you have been limited to getting up to 25 matches per request when requesting the next 25 get the oldest match id from database and search from it. Example would be ($oldest = oldest id)
    $matches_mapper_web->set_start_at_match_id($oldest);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •