/**
  * Helper method to make a Configuration API request, stores error if encountered
  *
  * @param string $method
  * @param array $payload
  * @return array [response string, Cloud_Config_Request object used for request]
  */
 protected function _make_request($method, $payload = array(), $flatten_keys = true, $region = false)
 {
     if ($payload && $flatten_keys) {
         $payload = $this->_flatten_keys($payload);
     }
     $credentials['access-key-id'] = $this->access_key;
     $credentials['secret-access-key'] = $this->secret_key;
     if (!($region && Lift_Search::is_valid_region($region))) {
         $region = Lift_Search::get_domain_region();
     }
     $config = new Cloud_Config_Request($credentials, $this->http_api, $region);
     $r = $config->send_request($method, $payload);
     $this->set_last_status_code($config->status_code);
     if ($r && false !== ($r_json = json_decode($r))) {
         $r_json = json_decode($r);
         if (isset($r_json->Error) || $this->last_status_code != '200') {
             $this->set_last_error(array('code' => $r_json->Error->Code, 'message' => $r_json->Error->Message));
             return false;
         }
         $response_name = $method . 'Response';
         $result_name = $method . 'Result';
         return $r_json->{$response_name}->{$result_name};
     } else {
         $this->set_last_error(array('code' => 'invalid_response', 'message' => $config->error));
     }
     return $r;
 }
Пример #2
0
 public function action__wp_ajax_lift_domains()
 {
     $response = array('domains' => array(), 'error' => false, 'nonce' => wp_create_nonce('lift_domain'));
     if (!Lift_Search::get_access_key_id() && !Lift_Search::get_secret_access_key()) {
         $response['error'] = array('code' => 'emptyCredentials', 'message' => 'The Access Credential are not yet set.');
     } else {
         $dm = Lift_Search::get_domain_manager();
         $region = !empty($_REQUEST['region']) ? $_REQUEST['region'] : Lift_Search::get_domain_region();
         $domains = $dm->get_domains($region);
         if ($domains === false) {
             $response['error'] = $dm->get_last_error();
         } else {
             $response['domains'] = $domains;
         }
     }
     header('Content-Type: application/json');
     die(json_encode($response));
 }