Пример #1
0
 /**
  * Constructor.
  *
  * @param object $type
  */
 public function __construct($type)
 {
     $this->type = $type;
     parent::$hours = 12;
     if (!isset(self::$options['gitlab_private_token'])) {
         self::$options['gitlab_private_token'] = null;
     }
     if (!isset(self::$options['gitlab_enterprise_token'])) {
         self::$options['gitlab_enterprise_token'] = null;
     }
     if (empty(self::$options['gitlab_private_token']) || empty(self::$options['gitlab_enterprise_token']) && !empty($type->enterprise)) {
         Messages::create_error_message('gitlab');
     }
     add_site_option('github_updater', self::$options);
 }
Пример #2
0
 /**
  * Call the API and return a json decoded body.
  * Create error messages.
  *
  * @see http://developer.github.com/v3/
  *
  * @param string $url
  *
  * @return boolean|object
  */
 protected function api($url)
 {
     $type = $this->return_repo_type();
     $response = wp_remote_get($this->_get_api_url($url));
     $code = (int) wp_remote_retrieve_response_code($response);
     $allowed_codes = array(200, 404);
     if (is_wp_error($response)) {
         return false;
     }
     if (!in_array($code, $allowed_codes, false)) {
         self::$error_code = array_merge(self::$error_code, array($this->type->repo => array('repo' => $this->type->repo, 'code' => $code, 'name' => $this->type->name)));
         if ('github' === $type['repo']) {
             GitHub_API::_ratelimit_reset($response, $this->type->repo);
         }
         Messages::create_error_message($type['repo']);
         return false;
     }
     return json_decode(wp_remote_retrieve_body($response));
 }