From 2b96b02c2de0721006a1c6489c693446e32b6829 Mon Sep 17 00:00:00 2001 From: Ilia Silakov Date: Wed, 18 Apr 2018 19:42:36 +0100 Subject: [PATCH] OpenDota API version 17.6.0, issues #2 #4 --- README.md | 9 ++++++--- simple_opendota.php | 29 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 437737d..aea3b9e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Simple OpenDota API library for PHP -### API version: 17.5.0 +### API version: 17.6.0 Simple OpenDota API support realization for PHP. @@ -22,11 +22,14 @@ You can find the list of methods and their API counterparts in [ENDPOINTS.md](EN ### Additional odota_api() parameters -Full version: `odota_api($cli_report_status, $hostname, $cooldown)` +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: `334`** (approximately 1/3 second) +* `$cooldown`: (int) API's cooldown between requests in milliseconds. **Default: `1000` or `200` 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 diff --git a/simple_opendota.php b/simple_opendota.php index 9526599..bc8ddf3 100644 --- a/simple_opendota.php +++ b/simple_opendota.php @@ -1,7 +1,7 @@ hostname = $hostname; - $this->api_cooldown = $cooldown/1000; + if (!empty($hostname)) + $this->hostname = $hostname; + else + $this->hostname = "https://api.opendota.com/api/"; + + $this->api_key = $api_key; + + if ($cooldown) + $this->api_cooldown = $cooldown/1000; + else if (!empty($this->api_key)) + $this->api_cooldown = 0.2; + else + $this->api_cooldown = 1; + $this->report_status = $cli_report_status; if ( $this->report_status ) { @@ -133,6 +145,9 @@ private function request($url, $mode, $data = [], $post = false) { } } + if (!empty($this->api_key)) + $data['api_key'] = $this->api_key; + if($post === FALSE) { $result = $this->get($url, $data); } else { @@ -140,9 +155,9 @@ private function request($url, $mode, $data = [], $post = false) { } $this->set_last_request(); - + $result = json_decode($result, true); - + if(isset($result['error']) || empty($result)) { if ( $mode == 0 ) { if ( $this->report_status ) @@ -496,7 +511,7 @@ public function request_status($job_id = "", $mode = 0) { return $this->request("request/".$job_id, $mode); } - + public function request_match($match_id, $mode = 0) { # POST /request/{match_id} # Submit a new parse request