-
Notifications
You must be signed in to change notification settings - Fork 1
PHP API library
The source code for the PHP client library can be found in lib/php/premium-api.php
here. A limited usage example is provided in lib/php/example.php
. It can be downloaded here.
- PHP 5.2 or newer
- One of these:
- pecl_http extension is recommended but not mandatory.
- enabled cURL library.
- allow_url_fopen set to true.
First, of course, the library files must be included in your code, for example:
require('lib/php/premium-api.php');
An API object must be created (the API key and campaign code you've been given must be passed as parameters to the constructor:
// "1234567890abcdef" is the API key and "demo" is the campaign code
$Premium = new PremiumAPI('1234567890abcdef', 'demo')
After all that you can use the object's methods to retrieve data from Premium:
-
array Info_Get()
Retrieves an array with general campaign information, no parameters required.
-
int Messages_Create(array Parameters)
Creates a message with the given values. -
array Messages_Get(int ID)
Retrieves a single message by ID. The structure is described in the Messages page. -
array Messages_List(array Filter1, [array Filter2 = null, [int Offset = 0]])
Retrieves a number of messages filtered by the given parameters at the given offset of the list
-
array Statistics_General()
Retrieves general campaign statistics and aggregate data
After any API call you can check object properties int ErrNo
and int Error
for errors - ErrNo
will contain error code (as described in Making API calls) and Error will contain a human readable error description with more details.
$Premium -> Info_Get();
if ($Premium -> ErrNo)
{
// An error has occured
echo 'Error #'.$Premium -> ErrNo.': '.$Premium -> Error;
}
else
{
// Everything's fine, proceed
}
You can retrieve some debug information by reading the value of the Debug
property. For example:
$Premium -> Info_Get();
print_r($Premium -> Debug);
Outputs:
Array
(
[LastHTTPRequest] => Array
(
[URL] => https://premium.sales.lv/API:1.0/Key:1234567890abcdef/Code:demo/Info:Get
[Request] =>
[Response] => Array
(
[Headers] => Array
(
[Response Code] => 200
[Response Status] => OK
[Date] => Mon, 17 Sep 2012 14:18:28 GMT
[Content-Type] => text/html; charset=utf-8
...
)
[Body] => {"Title":"Demo loterija" ... }
)
[Method] => GET
)
)
The returned content in the example is contracted for readability