Sample Web Service Usage

This section contains a sample usage of web services to show you how most web service calls work. In this example we're going to retrieve a list of files using the assets web service.

The algorithm for achieving this is as follows:

  1. Build the options used for retrieving the list of files. We use the Recite_Assets_Options_GetFiles class for this.

  2. Create the SoapClient object used for accessing the assets web service. We use the Recite_Webservices::Factory() method for this.

  3. Call the getFiles() method on the SOAP client.

  4. Use returned files as required. The returned files are contained in an instance of Recite_Assets_GetFilesResult.

Example 3.1. Sample Web Service Usage

<?php
    require_once('Recite/Webservices.php');
    
    // set credentials
    Recite_Webservices::SetCredentials('wsuser', 'wspass');
    Recite_Webservices::SetUrl('http://xyz.example.com');
    
    // build the SoapClient object for assets
    $client = Recite_Webservices::Factory('assets');
    
    $options = new Recite_Assets_Options_GetFiles();
    
    // return all files
    $options->includeSubFolders = true;
    
    // return paged results with a limit of 10 per page
    $options->paged = true;
    $options->pageNumber = 1;
    $options->limit = 10;
    
    // perform the web service method
    $result = $client->getFiles($options);
    
    // use the returned data
    foreach ($result->files as $file) {
        // output file details
    }
    
    // you can also output paging data from $result->pager
?>