From 611d06de46bcfbea8feaee6da7c817fd47c071e4 Mon Sep 17 00:00:00 2001 From: Ilia Silakov Date: Mon, 28 May 2018 14:17:32 +0100 Subject: [PATCH] minor fixes to API key support --- simple_opendota.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/simple_opendota.php b/simple_opendota.php index ec6af66..b469efb 100644 --- a/simple_opendota.php +++ b/simple_opendota.php @@ -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); } @@ -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); @@ -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 {