From 41205a024db1b72f9f27f89716e6e03adb3878f3 Mon Sep 17 00:00:00 2001 From: 15 <15@mail.ru> Date: Fri, 29 Dec 2023 16:54:56 +0300 Subject: [PATCH] All version API exsept v4 will send API-KEY as header entry. --- composer.json | 2 +- src/Route4Me/Route4Me.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 32af2e2..211bf5e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "route4me/route4me-php", "description": "Access Route4Me's logistics-as-a-service API using our PHP SDK", "minimum-stability": "stable", - "version": "1.2.10", + "version": "1.2.11", "authors": [ { "name": "Igor Route4Me", diff --git a/src/Route4Me/Route4Me.php b/src/Route4Me/Route4Me.php index 35dc572..97fa9ac 100644 --- a/src/Route4Me/Route4Me.php +++ b/src/Route4Me/Route4Me.php @@ -78,13 +78,19 @@ public static function makeRequst($options) $ch = curl_init(); - $url = isset($options['url']) - ? $options['url'] . '?' . http_build_query(array_merge( - $query, - ['api_key' => self::getApiKey()] - )) : ''; - $baseUrl = self::getBaseUrl(); + $host = parse_url($baseUrl . (isset($options['url']) ? $options['url'] : ''), PHP_URL_HOST); + $url = null; + if (isset($host) && strtolower(substr($host, 0, 2)) == "wh") { + $url = (isset($options['url']) ? $options['url'] . '?' . http_build_query($query) : ''); + $headers[] = 'Authorization: Bearer ' . self::getApiKey(); + } else { + $url = (isset($options['url']) + ? $options['url'] . '?' . http_build_query(array_merge( + $query, + ['api_key' => self::getApiKey()] + )) : ''); + } $curlOpts = [ CURLOPT_URL => $baseUrl.$url,