You are here

class SampleProcessor in Web Service Data 7

Sample implementation of WsData

This class is responsible for all data functions on your web service data. It parses the data from the service call and exports it in the appropriate format. For example, you can have a processor for json data and have it output the data in formatted arrays to be used with fields.

Hierarchy

Expanded class hierarchy of SampleProcessor

File

modules/wsconfig/wsconfig.api.php, line 76
Describe the file

View source
class SampleProcessor extends WsData {

  /**
   * WsData provides a default getData implementation. This function must
   * return a properly structured field array (including language, array of
   * values, field names, etc...).
   *
   * The default function returns a structured array as follows:
   *  Ex: array(LANGUAGE_NONE => array(0 => array('value' => 'somevalue')));
   *
   * It is the same structure as generated by the default fields in Drupal
   * core.
   */
  function getData($key) {

    // Your code here if need be
  }

  /**
   * Parser function
   *
   * Each instance of WsData must include an implementation of parse. This
   * is the function which takes in data from the web service and converts
   * it into data which Drupal can understand and use in fields.
   *
   * The parsed data must be converted into an array which follows the same
   * data hierarchy as your source data to work with the default getData()
   * method.
   *
   * For example, this function may accept an XML string and return an array
   * of data representing that string.
   *
   * @param $data
   *  Data to be parsed
   * @return array|boolean
   *  Return the parsed data, FALSE otherwise.
   */
  function parse($data) {

    // Do something
  }

  /**
   * Accepted data formats
   *
   * Tells the WsConnector the type of data the parser can accept as input.
   * Some web services offer data in a variety of formats (ex: json, xml).
   * This function tells the WsConnector instance what type of data to request
   * from the service.
   *
   * At the same time, if the WsConnector doesn't support the sepcified data
   * format, the service call is skipped and a warning is logged.
   *
   * You can define any kind of data format in the accepts array as long as
   * the WsConnector knows how to interpret it. By default, "xml" and "json"
   * are supported by the base class of WsConnector.
   *
   * @return array
   *  Returns an array of strings.
   */
  function accepts() {
    return array(
      'xml',
      'json',
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SampleProcessor::accepts function Accepted data formats Overrides WsData::accepts
SampleProcessor::getData function WsData provides a default getData implementation. This function must return a properly structured field array (including language, array of values, field names, etc...). Overrides WsData::getData
SampleProcessor::parse function Parser function Overrides WsData::parse
WsData::$data public property
WsData::$error protected property
WsData::$languages protected property
WsData::addData public function Add data to an empty object or replace all existing data
WsData::getError public function
WsData::__construct public function