Exemplo n.º 1
0
 /**
  * This method will load internal telapi.json schema in case it's not being loaded
  * 
  * @throws TelApi_Exception 
  * @return void
  */
 public function loadSchema()
 {
     if (is_null(self::$_schemaData)) {
         $schema_file = realpath(dirname(dirname(dirname(__FILE__)))) . self::TELAPI_SCHEMA_FILE;
         $json_schema = file_get_contents($schema_file);
         $error = '';
         $result = json_decode(trim($json_schema), false);
         if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
             switch (json_last_error()) {
                 case JSON_ERROR_DEPTH:
                     $error = ' - Maximum stack depth exceeded';
                     break;
                 case JSON_ERROR_CTRL_CHAR:
                     $error = ' - Unexpected control character found';
                     break;
                 case JSON_ERROR_STATE_MISMATCH:
                     $error = ' - Invalid or Malformed JSON';
                     break;
                 case JSON_ERROR_SYNTAX:
                     $error = ' - Syntax error, malformed JSON';
                     break;
                 case JSON_ERROR_NONE:
                 default:
                     $error = '';
             }
         }
         if (!empty($error)) {
             throw new TelApi_Exception('JSON SCHEMA Error: ' . $error);
         }
         self::$_schemaData = $result;
     }
 }
Exemplo n.º 2
0
 /**
  * Get the attribute of an object. If attribute doesn't exist TelApi_Exception
  * will be raised. If attribute exists but it's not set,
  * then default_value will be returned. Default is null
  * 
  * @param  string  $key
  * @param  mixed   $default_value
  * @return mixed
  * @throws TelApi_Exception 
  */
 function attr($key, $default_value = null)
 {
     $schemas = TelApi_Schemas::getInstance();
     if (!$schemas->isPagingProperty($key)) {
         $available_attrs = implode(", ", $schemas->getPagingProperties());
         throw new TelApi_Exception("Attribute you've requested '{$key}' cannot be found. Available attributes are: '{$available_attrs}'");
     }
     if ($this->response_association == false) {
         return isset($this->curl_data['response']->{$key}) ? $this->curl_data['response']->{$key} : $default_value;
     } else {
         return isset($this->curl_data['response'][$key]) ? $this->curl_data['response'][$key] : $default_value;
     }
 }
Exemplo n.º 3
0
 /**
  * This will build URL of TelAPI wrapper after the AccountSid with or without
  * possible GET parameters like ?PageSize=20
  * 
  * @param  array|string $component
  * @param  array $parameters
  * @return string
  * @throws TelApi_Exception
  */
 private function _buildUrl($component, array $parameters = array())
 {
     $return_url = '';
     $schemas = TelApi_Schemas::getInstance();
     if (is_array($component)) {
         $is_component = $schemas->isRestComponent(strtolower($component[0]));
         if (!$is_component) {
             $available_components = implode(", ", array_keys((array) $schemas->getAvailableRestComponents()));
             throw new TelApi_Exception("Component you've requested '{$component[0]}' cannot be found. Available components are: '{$available_components}'");
         }
         if (is_null($schemas->getRestComponentName(strtolower($component[0])))) {
             throw new TelApi_Exception("First resource argument in array cannot be null!");
         }
         $this->_component = strtolower($component[0]);
         $return_url = str_ireplace($component[0], $this->_components[strtolower($component[0])], implode('/', $component));
     } else {
         $is_component = $schemas->isRestComponent(strtolower($component));
         if (!$is_component) {
             $available_components = implode(", ", array_keys((array) $schemas->getAvailableRestComponents()));
             throw new TelApi_Exception("Component you've requested '{$component}' cannot be found. Available components are: '{$available_components}'");
         }
         $this->_component = strtolower($component);
         if (!is_null($this->_components[strtolower($component)])) {
             $return_url .= $this->_components[strtolower($component)] . '/';
         }
     }
     return $return_url;
 }
Exemplo n.º 4
0
 /**
  * Validate if attribute of verb exists. If not, throw exception, otherwise, return true.
  * 
  * @param  string $attr
  * @param  string $verb
  * @return boolean
  * @throws TelApi_Exception 
  */
 private function _validateAttribute($attr, $verb)
 {
     $schemas = TelApi_Schemas::getInstance();
     if (!$schemas->isValidAttribute($attr, ucfirst($verb))) {
         $verb_attribuges = implode(', ', $schemas->getAvailableAttributes(ucfirst($verb)));
         throw new TelApi_Exception("Attribute '{$attr}' does not exist for verb '{$verb}'. Available attributes are: '{$verb_attribuges}'");
     }
     return true;
 }