Esempio n. 1
0
 /**
  * Get the Twilio Services Account object for communicating with Twilio HQ
  * 
  * Will return the proper account for communications with Twilio.
  * This method is sub-account & twilio connect aware
  * 
  * Optional: Pass different Account Sid & Token values to communicate
  * with a different Twilio Account
  * 
  * Twilio Connect Aware. Will return the connect account if applicable.
  *
  * @throws OpenVBXException if invalid parameters are passed in for new object generation
  *
  * @static
  * @param bool/string $twilio_sid Optional - Twilio Account Sid
  * @param bool/string $twilio_token Optional - Twilio Account Token
  * @param string $api_version - default api version to use
  * @return object Services_Twilio_Rest_Account
  */
 public static function getAccount($twilio_sid = false, $twilio_token = false, $api_version = '2010-04-01')
 {
     $ci =& get_instance();
     // if sid & token are passed, make sure they're not the same as our master
     // values. If they are, make a new object, otherwise use the same internal object
     if (!empty($twilio_sid) || !empty($twilio_token)) {
         if (!empty($twilio_sid) && !empty($twilio_token)) {
             if (empty($ci->twilio_sid) && empty($ci->twilio_token) || $twilio_sid != $ci->twilio_sid && $twilio_token != $ci->twilio_token) {
                 try {
                     $_http_opts = self::get_http_opts();
                     $_http = new Services_Twilio_TinyHttp($_http_opts['host'], $_http_opts['opts']);
                     $service = new Services_Twilio($twilio_sid, $twilio_token, $api_version, $_http);
                     return $service->account;
                 } catch (Exception $e) {
                     throw new OpenVBXException($e->getMessage());
                 }
             }
         } else {
             throw new OpenVBXException('Both a Sid & Token are required to get a new Services Object');
         }
     }
     // return standard service object
     if (!self::$_twilioService instanceof Services_Twilio) {
         try {
             $_http_opts = self::get_http_opts();
             $_http = new Services_Twilio_TinyHttp($_http_opts['host'], $_http_opts['opts']);
             self::$_twilioService = new Services_Twilio($ci->twilio_sid, $ci->twilio_token, $api_version, $_http);
         } catch (Exception $e) {
             throw new OpenVBXException($e->getMessage());
         }
     }
     return self::$_twilioService->account;
 }