Download the PHP package leamare/simple-opendota-php without Composer
On this page you can find all versions of the php package leamare/simple-opendota-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leamare/simple-opendota-php
More information about leamare/simple-opendota-php
Files in leamare/simple-opendota-php
Package simple-opendota-php
Short Description Simple class interface to work with OpenDota API
License GPL-3.0
Informations about the package simple-opendota-php
Simple OpenDota API library for PHP
API version: 18.0.0
Simple OpenDota API support for PHP.
Handles API cooldown (to not get banned), API key usage, usage of various instances of OpenDota, Cli reporting.
It's sync only version with weird methods naming. It's intended to be used for simple PHP scripts (cli ones in the first place). For Async version made for ReactPHP look for reactive-opendota-php.
Note: It doesn't have an implementation for /feed endpoint. The endpoint tends to be unstable and it also requires HTTP streams support which doesn't work well with sync PHP.
Requirements
- PHP >=5.3.0
- cURL in PHP
You can use Composer to check all the requirements.
How to use
- Include
simple_opendota.php
in your project - Create
new odota_api()
instance.
That's it. You can work with OpenDota API through odota_api
methods. Every method returns associative array made out of JSON response.
You can find the list of methods and their API counterparts in ENDPOINTS.md.
Important Notes
Additional odota_api() parameters
Full version: odota_api($cli_report_status, $hostname, $cooldown, $api_key)
$cli_report_status
: (bool) report about every action to console. Default:false
$hostname
: (string) address of OpenDota API instance you're going to work with. Default:"https://api.opendota.com/api/"
$cooldown
: (int) API's cooldown between requests in milliseconds. Default:1000
or200
if API key was specified (approximately 1 per second)$api_key
: (string) OpenDota API Key. Default: none
If you need to skip one of parameters, you can left it empty for default value.
Work modes
Every method's last parameter is $mode
. It may have one of three values:
0
: Safe mode, sleep until API is ready (default)1
: Force mode, don't wait for API cooldown-1
: Fast mode, drop request if API isn't ready
Setting custom callbacks
set_get_callback(function($url, $data) {})
for GET requests onlyset_post_callback(function($url, $data) {})
for POST requests onlyset_request_callback(function($url, $data, $post) {})
for all requests (recommended)
API Endpoints with multiple parameters
API Endpoints with multiple GET parameters (for example, /players/{account_id}/matches
) use additional parameter:
$params
: (array) array of parameters. Every key is parameter's name, every value is its value.
It's second to last for the methods of those endpoints. Parameters names are directly translated to API endpoint, so if you'll need them, just check OpenDota Docs and use the same names.
To see what methods use $params
array and what don't, check ENDPOINTS.md (or you can check the code itself).