diff --git a/README.md b/README.md index edbd0ac..7621df5 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,18 @@ PHP client library is located in `lib/php/premium-api.php`. An usage example is Requirements: * [PHP 5.5 or newer](http://www.php.net/) * One of these: - * [pecl_http](http://pecl.php.net/package/pecl_http) extension is recommended but not mandatory. - * enabled [cURL library](http://www.php.net/manual/en/book.curl.php). + * [cURL extension](http://www.php.net/manual/en/book.curl.php). + * [pecl_http](http://pecl.php.net/package/pecl_http) extension. * [allow_url_fopen](http://php.net/manual/en/filesystem.configuration.php) set to true (attachment file upload is not currently supported for this method.) Library usage is [described in the wiki](https://github.com/Sales-LV/premium-api/wiki/PHP-API-library). Changelog ------------ +1.3.0: +- Changed to prefer cURL for making HTTP requests. +- PHP version number passed to Premium in user agent. + 1.2.1: - Minor fixes for PHP 8.1 compatibility. diff --git a/lib/php/premium-api.php b/lib/php/premium-api.php index 8fa1f13..72c8c7e 100644 --- a/lib/php/premium-api.php +++ b/lib/php/premium-api.php @@ -6,7 +6,7 @@ */ class PremiumAPI { - private static $Version = '1.2.1'; + private static $Version = '1.3.0'; private static $UserAgent = 'SalesLV/Premium-API'; private static $UAString = ''; @@ -133,6 +133,7 @@ public function __construct($Key, $CampaignCode) { self::$UAString .= '-stream'; } + self::$UAString .= '/php'.PHP_VERSION; $this -> APIKey = $Key; $this -> CampaignCode = $CampaignCode; @@ -188,7 +189,6 @@ public function Messages_Get($ID) return $this -> ParseResponse($Data); } - /** * Method for retrieving a message list from a campaign by the given parameters * @@ -325,7 +325,8 @@ private function SetError($ErrorCode, $ErrorMessage) * * @param string URL to make the request to * @param array POST data if it is a POST request. If this is empty, a GET request will be made, if populated - POST. Optional. - * @param array Additional headers to pass to the service, optional. + * @param array Additional headers to pass to the service, optional. Each item in the array is a string with a complete header including name + * and value, e.g. "Content-Type: application/x-www-form-urlencoded". * * @return array Array containing response data: array( * 'Code' => int HTTP status code (200, 403, etc.), @@ -342,15 +343,21 @@ private function HTTPRequest($URL, array $POSTData = null, array $Headers = null $Result = []; + if (!$Headers) + { + $Headers = []; + } + $Headers[] = 'Content-Type: application/x-www-form-urlencoded'; + try { - if (extension_loaded('http')) + if (extension_loaded('curl')) { - $Result = self::HTTPRequest_http($URL, $POSTData, $Headers, $Files); + $Result = self::HTTPRequest_curl($URL, $POSTData, $Headers, $Files); } - elseif (extension_loaded('curl')) + elseif (extension_loaded('http')) { - $Result = self::HTTPRequest_curl($URL, $POSTData, $Headers, $Files); + $Result = self::HTTPRequest_http($URL, $POSTData, $Headers, $Files); } elseif (ini_get('allow_url_fopen')) {