Skip to content

Commit

Permalink
v.1.3.0
Browse files Browse the repository at this point in the history
- Changed to prefer cURL for making HTTP requests.
- PHP version number passed to Premium in user agent.
  • Loading branch information
pilsetnieks committed Sep 14, 2022
1 parent 693b687 commit 409a9bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 14 additions & 7 deletions lib/php/premium-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand Down Expand Up @@ -133,6 +133,7 @@ public function __construct($Key, $CampaignCode)
{
self::$UAString .= '-stream';
}
self::$UAString .= '/php'.PHP_VERSION;

$this -> APIKey = $Key;
$this -> CampaignCode = $CampaignCode;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.),
Expand All @@ -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'))
{
Expand Down

0 comments on commit 409a9bc

Please sign in to comment.