public static function deploy($remote_url, $public_key, $private_key)
 {
     $fail = false;
     self::$elapsed_time = microtime(true);
     if (!class_exists('Pods_Migrate_Packages')) {
         return new WP_Error('pods-deploy-need-packages', __('You must activate the Packages Component on both the site sending and receiving this package.', 'pods-deploy'));
     }
     //@todo add options for these params
     $params = array('pods' => true, 'templates' => true, 'page' => true, 'helpers' => true);
     $data = Pods_Migrate_Packages::export($params);
     $url = trailingslashit($remote_url) . 'pods-components?package';
     $request_token = Pods_Deploy_Auth::generate_token($public_key, $private_key);
     $url = Pods_Deploy_Auth::add_to_url($public_key, $request_token, $url);
     $data = json_encode($data);
     $response = wp_remote_post($url, array('method' => 'POST', 'body' => $data));
     if (self::check_return($response)) {
         echo self::output_message(__('Package deployed successfully. ', 'pods-deploy'), $url);
         $responses = array();
         $api = pods_api();
         $params['names'] = true;
         $pod_names = $api->load_pods($params);
         $pod_names = array_flip($pod_names);
         $data = Pods_Deploy::get_relationships();
         $pods_api_url = trailingslashit($remote_url) . 'pods-api/';
         foreach ($pod_names as $pod_name) {
             $url = $pods_api_url . "{$pod_name}/update_rel";
             $url = Pods_Deploy_Auth::add_to_url($public_key, $request_token, $url);
             $responses[] = $response = wp_remote_post($url, array('method' => 'POST', 'body' => json_encode($data)));
             if (self::check_return($response)) {
                 echo self::output_message(__(sprintf('Relationships for the %1s Pod were updated.', $pod_name), 'pods-deploy'), $url);
             } else {
                 $fail = true;
                 echo self::output_message(__(sprintf('Relationships for the %1s Pod were not updated.', $pod_name), 'pods-deploy'), $url);
                 var_dump($response);
             }
         }
         if (!$fail) {
             echo self::output_message(__('Deployment complete :)', 'pods-deploy'));
         } else {
             echo self::output_message(__('Deployment completed with mixed results :|', 'pods-deploy'));
         }
     } else {
         echo self::output_message(__('Package could not be deployed :(', 'pods-deploy'));
         var_dump($response);
     }
 }
 /**
  * Update components
  *
  * @since 0.3.0 ?
  *
  * @param null $components
  *
  * @return array|bool|WP_Error
  */
 private static function do_deploy_components($components = null)
 {
     if (true === $components) {
         $components = self::active_components();
     }
     if (!is_array($components)) {
         $components = array('migrate-packages' => 'Migrate Packages');
     }
     if (!array_key_exists('migrate-packages', $components)) {
         $components['migrate-packages'] = 'Migrate Packages';
     }
     $url = trailingslashit(self::$remote_url) . 'pods-components';
     $url = Pods_Deploy_Auth::add_to_url(self::$public_key, self::$token, $url);
     $response = wp_remote_post($url, array('method' => 'GET', 'timeout' => self::$timeout));
     if (!self::check_return($response)) {
         echo self::output_message(__('Could not get activate components from remote site:(', 'pod-deploy'), $url, true, false);
         return false;
     } else {
         echo self::output_message(__('Remote site active components determined:)', 'pods-deploy'), $url);
     }
     $remote_components = json_decode(wp_remote_retrieve_body($response));
     if (!is_object($remote_components)) {
         $remote_components = array('migrate-packages');
     }
     $data = array();
     foreach ($components as $component => $label) {
         if (false == pods_v($component, $remote_components)) {
             $data[] = $component;
         }
     }
     if (!empty($data)) {
         $data = array('activate' => $data);
     }
     $response = wp_remote_post($url, array('method' => 'PUT', 'body' => json_encode($data), 'timeout' => self::$timeout));
     if (self::check_return($response)) {
         self::output_message(__('Successfully activated remote components.', 'pods-deploy'), $url);
     } else {
         self::output_message(__('Remote component activation failed.', 'pods-deploy'), $url, true, false);
         return false;
     }
     return $response;
 }