Announcement

Collapse

Forum Rules

  • No flaming or derogatory remarks, directly or through insinuation.
  • No discussion, sharing or referencing illegal software such as hacks, keygen, cracks and pirated software.
  • No offensive contents, including but not limited to, racism, gore or pornography.
  • No excessive spam/meme, i.e. copious one liners in a short period of time, typing with all caps or posting meme responses (text/image).
  • No trolling, including but not limited to, flame incitation, user provocation or false information distribution.
  • No link spamming or signature advertisements for content not specific to Dota 2.
  • No Dota 2 key requests, sell, trade etc.
  • You may not create multiple accounts for any purpose, including ban evasion, unless expressly permitted by a moderator.

  • Please search before posting. One thread per issue. Do not create another thread if there is an existing one already.
  • Before posting anything, make sure you check out all sticky threads (e.g., this). Do not create new threads about closed ones.
  • It is extremely important that you post in correct forum section.

  • Balance discussion only in Misc.
  • All art related (such as hero model) feedbacks go to Art Feedback Forum.
  • All matchmaking feedback should go here: Matchmaking Feedback
  • All report/low priority issues should go here: Commend/Report/Ban Feedback
  • No specific workshop item feedback. These should go to workshop page of that item.
  • When posting in non-bugs section (such as this), use [Bugs], [Discussion] or [Suggestion] prefix in your thread name.



In case you object some action by a moderator, please contact him directly through PM and explain your concerns politely. If you are still unable to resolve the issue, contact an administrator. Do not drag these issues in public.



All rules are meant to augment common sense, please use them when not conflicted with aforementioned policies.
See more
See less

Another way for API processing with PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 11:35 AM. Reason: New examples added

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

  • #2
    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);

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

    Comment


    • #3
      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

      Comment


      • #4
        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, 02:36 PM.

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

        Comment


        • #5
          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!

          Comment


          • #6
            Not big example of usage - Get all leagues matches and calculate win rate for each hero

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

            Comment


            • #7
              Additional units support added (testing now) - click.

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

              Comment


              • #8
                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

                Comment


                • #9
                  Nice design! Glad to see dotareport.net isn't the only one who is inspired by us

                  Comment


                  • #10
                    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);

                    Comment


                    • #11
                      Added methods to delete match(es). See match_mapper_db and matches_mapper_db.
                      Added JSON for regions.
                      Added halloween and greevil items to items.json.

                      See ReadMe for more info.

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

                      Comment


                      • #12
                        Added class for creating map image with barracks and tower (thanks all in this thread).
                        Matches_mapper_web now returns array of match objects (not assoc array of data as it was).
                        Matches_mapper_db now returns data with info about additional units.

                        See ReadMe with examples.

                        For now map may not working sometimes - api returns incorrect values (situations when t3 tower isn't destroyed, but barracks on this line are destroyed etc).

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

                        Comment


                        • #13
                          Some updates. Fixed few bugs and added few improvments.

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

                          Comment


                          • #14
                            I'm not a good programmer, sorry about that.
                            But I can't make it work.
                            And actually I don't get why we use database.

                            I'm making a championship, if you wanna join me, contact me here.
                            Thanks.

                            Comment


                            • #15
                              Jarolim, we use database to store parsed matches, because access to local db is faster then to API-server.

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

                              Comment

                              Working...
                              X