dolibarr 21.0.0-alpha
PrestaShopWebservice Class Reference
Collaboration diagram for PrestaShopWebservice:

Public Member Functions

 __construct ($url, $key, $debug=true)
 PrestaShopWebservice constructor.
 
 executeRequest ($url, $curl_params=array())
 Handles a CURL request to PrestaShop Webservice.
 
 printDebug ($title, $content)
 Output debug info.
 
 getVersion ()
 Return version.
 
 add ($options)
 Add (POST) a resource.
 
 get ($options)
 Retrieve (GET) a resource.
 
 head ($options)
 Head method (HEAD) a resource.
 
 edit ($options)
 Edit (PUT) a resource.
 
 delete ($options)
 Delete (DELETE) a resource.
 

Protected Member Functions

 checkStatusCode ($request)
 Take the status code and throw an exception if the server didn't return 200 or 201 code.
 
 getCurlDefaultParams ()
 Provides default parameters for the curl connection(s)
 
 parseXML ($response)
 Load XML from string.
 

Detailed Description

Definition at line 34 of file PSWebServiceLibrary.class.php.

Constructor & Destructor Documentation

◆ __construct()

PrestaShopWebservice::__construct ( $url,
$key,
$debug = true )

PrestaShopWebservice constructor.

Throw an exception when CURL is not installed/activated <?php require_once('./PrestaShopWebservice.php'); try { $ws = new PrestaShopWebservice('https://mystore.com/', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ', false); // Now we have a webservice object to play with } catch (PrestaShopWebserviceException $ex) { echo 'Error : '.$ex->getMessage(); } ?>

Parameters
string$urlRoot URL for the shop
string$keyAuthentication key
bool$debugDebug mode Activated (true) or deactivated (false)
Exceptions
PrestaShopWebserviceExceptionif curl is not loaded

Definition at line 76 of file PSWebServiceLibrary.class.php.

Member Function Documentation

◆ add()

PrestaShopWebservice::add ( $options)

Add (POST) a resource.

Unique parameter must take :

'resource' => Resource name
'postXml' => Full XML string to add resource<br>
Examples are given in the tutorial

Parameters
array{url?:string,resource?:string,id?:string,id_shop?:string,id_group_shop?:string,postXml:mixed}$options Array representing resource to add.
Returns
SimpleXMLElement status_code, response
Exceptions
PrestaShopWebserviceException

Definition at line 324 of file PSWebServiceLibrary.class.php.

References checkStatusCode(), executeRequest(), and parseXML().

◆ checkStatusCode()

PrestaShopWebservice::checkStatusCode ( $request)
protected

Take the status code and throw an exception if the server didn't return 200 or 201 code.

Unique parameter must take :

'status_code' => Status code of an HTTP return
'response' => CURL response

Parameters
array{status_code:int,response:string}$request Response elements of CURL request
Returns
void
Exceptions
PrestaShopWebserviceExceptionif HTTP status code is not 200 or 201

Definition at line 101 of file PSWebServiceLibrary.class.php.

References parseXML().

Referenced by add(), delete(), edit(), get(), and head().

◆ delete()

PrestaShopWebservice::delete ( $options)

Delete (DELETE) a resource.

Unique parameter must take :

'resource' => Resource name
'id' => ID or array which contains IDs of a resource(s) you want to delete<br>
<?php require_once('./PrestaShopWebservice.php'); try { $ws = new PrestaShopWebservice('https://mystore.com/', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ', false); $xml = $ws->delete(array('resource' => 'orders', 'id' => 1)); // Following code will not be executed if an exception is thrown. echo 'Successfully deleted.'; } catch (PrestaShopWebserviceException $ex) { echo 'Error : '.$ex->getMessage(); } ?>

Parameters
array{url?:string,resource?:string,id?:string,id_shop?:string,id_group_shop?:string}$options Array representing resource to delete.
Returns
bool
Exceptions
PrestaShopWebserviceException

Definition at line 512 of file PSWebServiceLibrary.class.php.

References checkStatusCode(), and executeRequest().

◆ edit()

PrestaShopWebservice::edit ( $options)

Edit (PUT) a resource.

Unique parameter must take :

'resource' => Resource name ,
'id' => ID of a resource you want to edit,
'putXml' => Modified XML string of a resource<br>
Examples are given in the tutorial

Parameters
array{url?:string,resource?:string,id?:string,id_shop?:string,id_group_shop?:string,putXml:mixed}$options Array representing resource to edit.
Returns
SimpleXMLElement
Exceptions
PrestaShopWebserviceException

Definition at line 461 of file PSWebServiceLibrary.class.php.

References checkStatusCode(), executeRequest(), and parseXML().

◆ executeRequest()

PrestaShopWebservice::executeRequest ( $url,
$curl_params = array() )

Handles a CURL request to PrestaShop Webservice.

Can throw exception.

Parameters
string$urlResource name
array<int,null|int|bool|string|float>$curl_params CURL parameters (sent to curl_set_opt)
Returns
array{status_code:int,response:?string,header:string}
Exceptions
PrestaShopWebserviceException

Definition at line 174 of file PSWebServiceLibrary.class.php.

References dol_syslog(), getCurlDefaultParams(), and printDebug().

Referenced by add(), delete(), edit(), get(), and head().

◆ get()

PrestaShopWebservice::get ( $options)

Retrieve (GET) a resource.

Unique parameter must take :

'url' => Full URL for a GET request of Webservice (ex: https://mystore.com/api/customers/1/)
OR
'resource' => Resource name,
'id' => ID of a resource you want to get<br>

<?php require_once('./PrestaShopWebservice.php'); try { $ws = new PrestaShopWebservice('https://mystore.com/', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ', false); $xml = $ws->get(array('resource' => 'orders', 'id' => 1)); // Here in $xml, a SimpleXMLElement object you can parse foreach ($xml->children()->children() as $attName => $attValue) echo $attName.' = '.$attValue.'
'; } catch (PrestaShopWebserviceException $ex) { echo 'Error : '.$ex->getMessage(); } ?>

Parameters
array<string,string>$options Array representing resource to get.
Returns
SimpleXMLElement status_code, response
Exceptions
PrestaShopWebserviceException

Definition at line 377 of file PSWebServiceLibrary.class.php.

References checkStatusCode(), executeRequest(), and parseXML().

◆ getCurlDefaultParams()

PrestaShopWebservice::getCurlDefaultParams ( )
protected

Provides default parameters for the curl connection(s)

Returns
array<int,bool|int|string|string[]|array<int,string>> Default parameters for curl connection(s)

Definition at line 148 of file PSWebServiceLibrary.class.php.

Referenced by executeRequest().

◆ getVersion()

PrestaShopWebservice::getVersion ( )

Return version.

Returns
string Version

Definition at line 275 of file PSWebServiceLibrary.class.php.

◆ head()

PrestaShopWebservice::head ( $options)

Head method (HEAD) a resource.

Parameters
array<string,string>$options Array representing resource for head request.
Returns
string
Exceptions
PrestaShopWebserviceException

Definition at line 418 of file PSWebServiceLibrary.class.php.

References checkStatusCode(), and executeRequest().

◆ parseXML()

PrestaShopWebservice::parseXML ( $response)
protected

Load XML from string.

Can throw exception

Parameters
string$responseString from a CURL response
Returns
SimpleXMLElement status_code, response
Exceptions
PrestaShopWebserviceException

Definition at line 288 of file PSWebServiceLibrary.class.php.

Referenced by add(), checkStatusCode(), edit(), and get().

◆ printDebug()

PrestaShopWebservice::printDebug ( $title,
$content )

Output debug info.

Parameters
string$titleTitle
string$contentContent
Returns
void

Definition at line 257 of file PSWebServiceLibrary.class.php.

Referenced by executeRequest().


The documentation for this class was generated from the following file: