예제 #1
0
 /**
  * Initializes Slack API if credentials are valid.
  * 
  * @access public
  * @return bool
  */
 public function initialize_api()
 {
     if (!is_null($this->api)) {
         return true;
     }
     /* Load the API library. */
     if (!class_exists('Slack')) {
         require_once 'includes/class-slack.php';
     }
     /* Get the OAuth token. */
     $auth_token = $this->get_plugin_setting('auth_token');
     /* If the OAuth token, do not run a validation check. */
     if (rgblank($auth_token)) {
         return null;
     }
     $this->log_debug(__METHOD__ . "(): Validating API Info.");
     /* Setup a new Slack object with the API credentials. */
     $slack = new Slack($auth_token);
     /* Run an authentication test. */
     $auth_test = $slack->auth_test();
     if (rgar($auth_test, 'ok')) {
         $this->api = $slack;
         $this->log_debug(__METHOD__ . '(): API credentials are valid.');
         return true;
     } else {
         $this->log_error(__METHOD__ . '(): API credentials are invalid; ' . $auth_test['error']);
         return false;
     }
 }