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

  • #46
    Originally posted by GelioS View Post
    Frode, I tried to run db_latest.sql few minutes ago and didn't get any error.
    Did you modify sql-queries from file?
    Thank you for your response. Okay. I added the WP DB details (db_user/db_pass/db_host/db_name) in config.php and tried to run the query from phpmyadmin after uploading the files to my site. I have PHP 5.3 (Mysql 5.5) supported on server, with PDO_mysql and cURL enabled in php.ini. So I can't see why it wouldn't let me run the queries. (URL: http://www.worldofdota2.com/)

    Comment


    • #47
      So I got the query to work. Though it appears that it wont "find" the included folders (mappers etc). Is the config file broken? The part about it trying to find the required class and folder. It doesn't.

      Also, side question: "pdo_mysql.default_socket=" What should the socket be?

      Comment


      • #48
        Frode, pls show the folders structure (where is api folder, where is config.php and where is file that includes config.php).
        About pdo_mysql.default_socket, I didn't put nothing there.

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

        Comment


        • #49
          Originally posted by GelioS View Post
          Frode, pls show the folders structure (where is api folder, where is config.php and where is file that includes config.php).
          About pdo_mysql.default_socket, I didn't put nothing there.
          well I have a php code snippet plugin for Wordpress, to run the code on my WP pages. The structure is:
          /data
          /images
          /includes
          config.php

          The file that runs the code is in this folder, called insert_php.php.

          Comment


          • #50
            I've finally gotten back into doing my dota site (it only took me a year...)

            two changes I'd like to suggest:
            1)
            in your matches_mapper_db I notice that you load all of the match data and piece together the match objects.
            but you already do this in match_mapper_db. It seems silly to have duplicate code - it'd be smarter to use your match_mapper_db->load method inside matches_mapper_db->load method so that you only have one set of match-loading code.

            2)
            in match_mapper_db when you are loading all of the ability and additional_unit data, i notice that you don't prune out the slot_id data from each of these entries, which means that every single element in each of those arrays has an identical slot_id element.. which is useless considering it's nested within the slot itself by then..

            suggested change:
            the ability code starting from line 59 in the old code:
            Code:
                    foreach($ability_upgrade as $a) {
                        if (!isset($ability_upgrade_formatted[$a['slot_id']])) {
                            $ability_upgrade_formatted[$a['slot_id']] = array();
                        }
                        $a_clone = $a;
                        unset($a_clone['slot_id']);
                        array_push($ability_upgrade_formatted[$a['slot_id']], $a_clone);
                    }
            and the additional unit code from line 68 in the old code:
            Code:
                    foreach($additional_units as $additional_unit) {
                        if (!isset($additional_units_formatted[$additional_unit['slot_id']])) {
                            $additional_units_formatted[$additional_unit['slot_id']] = array();
                        }
                        $additional_unit_clone = $additional_unit;
                        unset($additional_unit_clone['slot_id']);
                        array_push($additional_units_formatted[$additional_unit['slot_id']], $additional_unit_clone);
                    }
            all that those changes are doing is cloning then unsetting the slot_id field in the arrays before adding them to the slot.
            The API Bible: Things You Should Know Before Starting API Development

            Comment


            • #51
              I noticed that in your abilities.json file you have two abilities that have been accidentally duplicated:
              Code:
                      {
                          "name": "luna_lucent_beam",
                          "id": "5222"
                      },
              and
              Code:
                      {
                          "name": "pudge_dismember",
                          "id": "5077"
                      },
              Last edited by MuppetMaster42; 02-18-2014, 06:55 AM.
              The API Bible: Things You Should Know Before Starting API Development

              Comment


              • #52
                in your heroes.json file, you have incorrectly labelled necrophos and windranger,
                their in game code namesa are still necrolyte and windrunner, it's just their localized_name that changed

                i.e.. it is
                Code:
                        {
                            "name": "windranger",
                            "id": 21,
                            "localized_name": "Windranger"
                        },
                        {
                            "name": "necrophos",
                            "id": 36,
                            "localized_name": "Necrophos"
                        },
                but should be
                Code:
                        {
                            "name": "windrunner",
                            "id": 21,
                            "localized_name": "Windranger"
                        },
                        {
                            "name": "necrolyte",
                            "id": 36,
                            "localized_name": "Necrophos"
                        },
                The API Bible: Things You Should Know Before Starting API Development

                Comment


                • #53
                  MuppetMaster42, thanks for you response!
                  Both json files are already fixed.
                  About mappers:
                  match_mapper_db gets whole info about one match and does requests for tables - matches, slots, additional units, ability_upgrades and picks_bans (if CM). One request for each table.
                  matches_mapper_db gets info about several matches. It is written to do minimum requests to the db. It also does one request per slots, additional_units, ability_upgrades and picks_bans.
                  If I try to use match_mapper_db in the matches_mapper_db, I'll have much more requests - 5 * count of matches.
                  And about slot_id in the nested arrays - well, its not a big problem that child-element has key of his parent IMHO

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

                  Comment


                  • #54
                    the parent id in the child object is a problem when you're converting the object to json for use in a rest api!
                    well it's not exactly a problem as much as it's very inefficent in that case

                    yeah i didn't think of it like that re the matches/match mappers.
                    The API Bible: Things You Should Know Before Starting API Development

                    Comment


                    • #55
                      what about series id and series type
                      Steam Id Finder

                      Comment


                      • #56
                        Just wanted to say that I love this wrapper. I'm rather new to PHP and poring over this has really given me some more insight into how to code OOP PHP. I am making my own wrapper for dota 2 (only for personal use), using your wrapper as a "how to" guide. Hope this is ok with you? I will of course site/give reference to your original code

                        Thank you again for making this!!

                        Comment


                        • #57
                          lodagema, thanks for you response!
                          You may use it any way allowed by MIT license (so, almost any way ).
                          I'll be glad, if you put reference to dota2-api.
                          Good luck with you project!

                          SoloMidPlz, not yet supported (gonna do it, but can't make any estimates).

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

                          Comment


                          • #58
                            bump to keep this on the front page.

                            IMHO this should be stickied as it's hugely useful to pretty much all webapi users.
                            The API Bible: Things You Should Know Before Starting API Development

                            Comment


                            • #59
                              Mappers for prize pool are added - https://github.com/kronusme/dota2-api
                              Examples:
                              PHP Code:
                              <?php
                              require('config.php');
                              $league_prize_pool_mapper_web = new league_prize_pool_mapper_web();
                              $league_prize_pool_mapper_web->set_league_id(600);
                              $prize_pool_info $league_prize_pool_mapper_web->load();
                              print_r($prize_pool_info);
                              echo 
                              $prize_pool_info['prize_pool'];
                              echo 
                              $prize_pool_info['league_id'];
                              echo 
                              $prize_pool_info['status']; // may be undefined
                              PHP Code:
                              <?php
                              require('config.php');
                              $prize_pool_mapper_db = new league_prize_pool_mapper_db();
                              $pp $prize_pool_mapper_db->set_league_id(600)->load();
                              foreach(
                              $pp as $date=>$prize_pool) {
                                  echo 
                              $date.' - $ '.number_format($prize_pool2);
                              }
                              Example - http://dota2statistic.com/index.php/...tab=prize_pool

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

                              Comment


                              • #60
                                bump to keep this on the front page.

                                IMHO this should be stickied as it's hugely useful to pretty much all webapi users.
                                The API Bible: Things You Should Know Before Starting API Development

                                Comment

                                Working...
                                X