Skip to content

Commit

Permalink
OpenDota API version 17.6.0, issues #2 #4
Browse files Browse the repository at this point in the history
  • Loading branch information
leamare committed Apr 18, 2018
1 parent 34cefe9 commit 2b96b02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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

Expand Down
29 changes: 22 additions & 7 deletions simple_opendota.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Simple OpenDota API library for PHP
* API version: 17.5.0
* API version: 17.6.0
*
* It's quite simple implemetation, that you can use by just requiring it
* from your code.
Expand All @@ -27,14 +27,26 @@ class odota_api {
private $last_request = 0;
private $report_status;

function __construct($cli_report_status=false, $hostname="https://api.opendota.com/api/", $cooldown=400) {
function __construct($cli_report_status=false, $hostname="", $cooldown=1000, $api_key="") {
/**
* $hostname = URL of API instance. Uses public OpenDota instance by default.
* $cooldown = API cooldown, 3000ms by default (recommended by OpenDota docs).
*/

$this->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 ) {
Expand Down Expand Up @@ -133,16 +145,19 @@ 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 {
$result = $this->post($url, $data);
}

$this->set_last_request();

$result = json_decode($result, true);

if(isset($result['error']) || empty($result)) {
if ( $mode == 0 ) {
if ( $this->report_status )
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2b96b02

Please sign in to comment.