dolibarr  7.0.0-beta
Public Member Functions | Protected Member Functions | List of all members
PrestaShopWebservice Class Reference
+ Collaboration diagram for PrestaShopWebservice:

Public Member Functions

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

Protected Member Functions

 checkStatusCode ($status_code)
 Take the status code and throw an exception if the server didn't return 200 or 201 code. More...
 
 parseXML ($response)
 Load XML from string. More...
 

Detailed Description

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

Constructor & Destructor Documentation

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('http://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$keyAuthentification key
mixed$debugDebug mode Activated (true) or deactivated (false)

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

Member Function Documentation

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$optionsOptions
Returns
SimpleXMLElement status_code, response

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

PrestaShopWebservice::checkStatusCode (   $status_code)
protected

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

Parameters
int$status_codeStatus code of an HTTP return

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

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$optionsArray representing resource to edit.
Returns
SimpleXMLElement status_code, response

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

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

Handles a CURL request to PrestaShop Webservice.

Can throw exception.

Parameters
string$urlResource name
mixed$curl_paramsCURL parameters (sent to curl_set_opt)
Returns
array status_code, response

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

References printDebug().

PrestaShopWebservice::get (   $options)

Retrieve (GET) a resource.

Unique parameter must take :

'url' => Full URL for a GET request of Webservice (ex: http://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('http://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$optionsArray representing resource to get.
Returns
SimpleXMLElement status_code, response

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

PrestaShopWebservice::getVersion ( )

Return version.

Returns
string Version

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

PrestaShopWebservice::head (   $options)

Head method (HEAD) a resource.

Parameters
array$optionsArray representing resource for head request.
Returns
SimpleXMLElement status_code, response

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

PrestaShopWebservice::parseXML (   $response)
protected

Load XML from string.

Can throw exception

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

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

PrestaShopWebservice::printDebug (   $title,
  $content 
)

Output debug info.

Parameters
string$titleTitle
string$contentContent
Returns
void

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

Referenced by executeRequest().


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