Skip to content

Commit

Permalink
minor fixes to API key support
Browse files Browse the repository at this point in the history
  • Loading branch information
leamare committed May 28, 2018
1 parent f0e3f10 commit 611d06d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions simple_opendota.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ function __construct($cli_report_status=false, $hostname="", $cooldown=0, $api_k
$this->report_status = $cli_report_status;

if ( $this->report_status ) {
echo "[I] OpenDotaPHP: Initialised OpenDota instance.\n[ ] \tHost: $hostname\n";
echo "[I] OpenDotaPHP: Initialised OpenDota instance.\n[ ] \tHost: ".$this->hostname."\n";
}
}

# Inner class functions

private function get($url, $data = []) {
if (!empty($this->api_key))
$data['api_key'] = $this->api_key;

if (!empty($data)) {
$url .= "?".http_build_query($data);
}
Expand Down Expand Up @@ -88,12 +91,15 @@ private function get($url, $data = []) {
}

private function post($url, $data = []) {
if (!empty($this->api_key))
$url .= "?api_key=".$this->api_key;

$curl = curl_init($this->hostname.$url);

if ( $this->report_status ) {
echo("...");
}

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
Expand Down Expand Up @@ -145,9 +151,6 @@ 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 {
Expand Down

0 comments on commit 611d06d

Please sign in to comment.