Advertisement
Guest User

bbb_api_call()

a guest
Nov 27th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Connect to BBB API and return response.
  5.  *
  6.  * @param $params
  7.  *   Associative array of additional url parameters. See bbb_api_create().
  8.  * @param $call
  9.  *   API call name. Possible values:
  10.  *   - 'create'
  11.  *   - 'isMeetingRunning'
  12.  *   - 'endMeeting'
  13.  *   - 'getMeetingInfo'
  14.  * @todo: test for other API calls, see http://code.google.com/p/bigbluebutton/wiki/API#API_Calls
  15.  *
  16.  * @return
  17.  *   Response stdClass or FALSE if BBB service is not available at given url.
  18.  */
  19. function bbb_api_call($params, $call) {
  20.   $query_string = bbb_api_generate_querystring($params, $call);
  21.   $url = BIGBLUEBUTTON_BASE_URL . '/api/' . $call . '?' . $query_string;
  22.   // Set options for the HTTP request.
  23.   $options = array(
  24.     'method' => 'POST',
  25.     // @todo: implement as a setting variable.
  26.     'timeout' => 5,
  27.   );
  28.   $result = drupal_http_request($url, $options);
  29.   // If errors occured, return FALSE.
  30.   if ($result->code != 200) {
  31.     // Log error to watchdog.
  32.     watchdog('bigbluebutton', 'BigBlueButton connection error. API call: %call <br/>Request URL: %url <br/>Result code: %code <br/>Result error: %error', array(
  33.       '%call' => $call,
  34.       '%url' => $url,
  35.       '%code' => $result->code,
  36.       '%error' => $result->error,
  37.     ), WATCHDOG_DEBUG);
  38.     return FALSE;
  39.   }
  40.   else {
  41.     // If XML is available, process data.
  42.     if (!empty($result->data)) {
  43.       // Process XML string into SimpleXMLElement object.
  44.       $xml = simplexml_load_string($result->data);
  45.       // Process SimpleXMLElement object.
  46.       $response = bbb_api_parse_response($xml);
  47.       // Check if request was successful.
  48.       if (isset($response->returncode) && $response->returncode == 'SUCCESS') {
  49.         // Everything is fine.
  50.       }
  51.       else {
  52.         // If errors occured, log them.
  53.         if (isset($response->message)) {
  54.           watchdog('bigbluebutton', '%message', array('%message' => $response->message), WATCHDOG_ERROR);
  55.         }
  56.       }
  57.       return $response;
  58.     }
  59.     else {
  60.       return FALSE;
  61.     }
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement