public function _make_request($method, $payload = array(), $flatten_keys = true, $region = false)
 {
     if (in_array($method, $this->cached_methods)) {
         if (is_array($cache = get_transient('lift_request_' . $method))) {
             $key = substr(md5(serialize($payload)), 0, 25);
             if (isset($cache[$key])) {
                 $this->set_last_error($cache[$key]['set_last_error']);
                 $this->set_last_status_code($cache[$key]['last_status_code']);
                 return $cache[$key]['response'];
             }
         }
     }
     $result = parent::_make_request($method, $payload, $flatten_keys, $region);
     if (in_array($method, $this->cached_methods)) {
         $cache = get_transient('lift_request_' . $method);
         if (!is_array($cache)) {
             $cache = array();
         }
         $key = substr(md5(serialize($payload)), 0, 25);
         $cache[$key] = array('set_last_error' => $this->get_last_error(), 'last_status_code' => $this->last_status_code, 'response' => $result);
         set_transient('lift_request_' . $method, $cache, 60);
     } elseif (isset($this->clear_cache_methods[$method])) {
         foreach ($this->clear_cache_methods[$method] as $clear_methods) {
             delete_transient('lift_request_' . $clear_methods);
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 public function test_access($id = '', $secret = '')
 {
     $credentials = array('access-key-id' => $id, 'secret-access-key' => $secret);
     $error = false;
     try {
         if (Cloud_Config_API::TestConnection($credentials)) {
             $status_message = 'Success';
             self::__set_setting('access-key-id', $id);
             self::__set_setting('secret-access-key', $secret);
         } else {
             $status_message = 'There was an error authenticating. Please check your Access Key ID and Secret Access Key and try again.';
             $error = true;
         }
     } catch (Exception $e) {
         // @todo add exception logging?
         $status_message = 'There was an error authenticating your access keys. Please try again.';
         $error = true;
     }
     return array('error' => $error, 'message' => $status_message);
 }