/**
  * Make API request.
  * 
  * @access public
  * @param string $path
  * @param array $options
  * @param bool $return_status (default: false)
  * @param string $method (default: 'GET')
  * @return void
  */
 function make_request($path, $options = array(), $method = 'GET', $return_key = null)
 {
     /* Build base request options string. */
     $request_options = '?format=json&auth_token=' . $this->oauth_token;
     /* Add options if this is a GET request. */
     $request_options .= $method == 'GET' ? '&' . http_build_query($options) : null;
     /* Build request URL. */
     $request_url = $this->api_url . $path . $request_options;
     /* Setup request arguments. */
     $args = array('method' => $method, 'sslverify' => $this->verify_ssl);
     /* Add request options to body of POST and PUT requests. */
     if ($method == 'POST' || $method == 'PUT') {
         $args['body'] = $options;
     }
     /* Execute request. */
     $result = wp_remote_request($request_url, $args);
     /* If WP_Error, throw exception */
     if (is_wp_error($result)) {
         throw new Exception('Request failed. ' . $result->get_error_messages());
     }
     /* Decode JSON. */
     $decoded_result = json_decode($result['body'], true);
     /* If invalid JSON, return original result body. */
     if (json_last_error() !== JSON_ERROR_NONE) {
         return $result['body'];
     }
     /* If return key is set and exists, return array item. */
     if ($return_key && array_key_exists($return_key, $decoded_result)) {
         return $decoded_result[$return_key];
     }
     return $decoded_result;
 }
 public static function PATCH($url, $headers = array(), $data = array())
 {
     if (function_exists("wp_remote_request")) {
         return wp_remote_request($url, array("headers" => $headers, "body" => $data));
     }
     return Requests::patch($url, $headers, $data);
 }
 /**
  * Override the curl-based function to use baseline WordPress
  */
 protected function request($options)
 {
     if (!$this->api_token) {
         return FALSE;
     }
     //end if
     $url = $this->api_url . $options['function'];
     $args = array('method' => $options['method'], 'user-agent' => $this->useragent, 'headers' => array('Token' => $this->api_token, 'Content-Type' => 'application/json'), 'sslverify' => $this->ssl_verifypeer);
     if ('POST' == $options['method'] || 'PUT' == $options['method']) {
         $args['body'] = json_encode($options['data']);
     }
     //end if
     $res = wp_remote_request(esc_url_raw($url), $args);
     if (is_wp_error($res)) {
         return FALSE;
     }
     //end if
     // the following variables are primarily for debugging purposes
     // Let's utilise the WP Remote functions to retrieve metadata
     $this->request_http_code = wp_remote_retrieve_response_code($res);
     $this->request_info = $res;
     $this->request_url = $url;
     $this->request_response = wp_remote_retrieve_body($res);
     $return = json_decode($this->request_response);
     return $return ?: $this->request_response;
 }
Exemple #4
0
 /**
  * Send request with the specified action and parameters
  *
  * @param string $action
  * @param array $parameters
  */
 private function send_request($end_point, $method = 'GET', array $data = array(), $expected_response_code = 200)
 {
     // Request
     $url = self::API_URL . $end_point;
     $response = wp_remote_request($url, array('method' => $method, 'headers' => array('Authorization' => 'Bearer ' . $this->api_key), 'body' => $data));
     // Response code
     $response_code = wp_remote_retrieve_response_code($response);
     if ($expected_response_code != $response_code) {
         // WPCS: loose comparison ok.
         $this->error = new WP_Error('mollie_error', 'Unexpected response code.');
     }
     // Body
     $body = wp_remote_retrieve_body($response);
     $data = json_decode($body);
     if (!is_object($data)) {
         $this->error = new WP_Error('mollie_error', 'Could not parse response.');
         return false;
     }
     // Mollie error
     if (isset($data->error, $data->error->message)) {
         $this->error = new WP_Error('mollie_error', $data->error->message, $data->error);
         return false;
     }
     return $data;
 }
 public function update($body, $path)
 {
     global $wp_version;
     $params = array('api_key' => $this->api_key, 'expires' => time() + 900);
     $path = '/v2/assets/' . $path;
     $params['signature'] = $this->sign_request(array('path' => $path, 'method' => 'PATCH', 'body' => $body), $params);
     foreach ($params as &$param) {
         $param = rawurlencode($param);
     }
     $url = add_query_arg($params, 'https://api.ooyala.com' . $path);
     if ($wp_version >= 3.4) {
         return wp_remote_request($url, array('headers' => array('Content-Type' => 'application/json'), 'method' => 'PATCH', 'body' => $body, 'timeout' => apply_filters('ooyala_http_request_timeout', 10)));
     }
     // Workaround for core bug - http://core.trac.wordpress.org/ticket/18589
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
     curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($curl);
     $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     return array('body' => $response, 'response' => array('code' => $status));
 }
 function get_version_info($cache = true)
 {
     $raw_response = get_transient('slideshow_update_info');
     if (!$cache) {
         $raw_response = false;
     }
     if (!$raw_response) {
         $options = array('method' => 'POST', 'timeout' => 20);
         $options['headers'] = array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'User-Agent' => 'WordPress/' . get_bloginfo("version"), 'Referer' => home_url());
         $request_url = SLIDESHOW_MANAGER_URL . 'updates/13/' . $this->get_remote_request_params();
         $raw_response = wp_remote_request($request_url, $options);
         set_transient('slideshow_update_info', $raw_response, 43200);
     }
     if (is_wp_error($raw_response) || 200 != $raw_response['response']['code']) {
         return array("is_valid_key" => "1", "version" => "", "url" => "");
     } else {
         $array = explode("||", $raw_response['body']);
         $url = $array[2];
         //$url = "https://downloads.wordpress.org/plugin/slideshow-gallery.latest-stable.zip";
         $info = array("is_valid_key" => $array[0], "version" => $array[1], "url" => $url, "item_id" => $array[4]);
         if (count($array) == 4) {
             $info["expiration_time"] = $array[3];
         }
         return $info;
     }
 }
 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects, 'reject_unsafe_urls' => true);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             //Use default WP user agent unless custom has been specified
             $args['user-agent'] = $this->useragent;
         }
         $res = wp_remote_request($url, $args);
         if (is_wp_error($res)) {
             $this->error = 'WP HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = wp_remote_retrieve_headers($res);
             $this->body = wp_remote_retrieve_body($res);
             $this->status_code = wp_remote_retrieve_response_code($res);
         }
     } else {
         $this->error = '';
         $this->success = false;
     }
 }
 function http($url, $method, $postfields = NULL)
 {
     $this->http_info = null;
     // this is never used
     $options = array('method' => $method, 'timeout' => $this->timeout, 'user-agent' => $this->useragent, 'sslverify' => $this->ssl_verifypeer);
     switch ($method) {
         case 'POST':
             if (!empty($postfields)) {
                 $options['body'] = $postfields;
             }
             break;
         case 'DELETE':
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
     }
     $response = wp_remote_request($url, $options);
     if (is_wp_error($response)) {
         $this->http_code = null;
         $this->http_header = array();
         return false;
     }
     $this->http_code = $response['response']['code'];
     $this->http_header = $response['headers'];
     return $response['body'];
 }
 function locate($ip = null)
 {
     global $_SERVER;
     if (is_null($ip)) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     $host = str_replace('{IP}', $ip, $this->host);
     $host = str_replace('{CURRENCY}', $this->currency, $host);
     $data = array();
     /* Updated this class so it uses wp_remote_request instead of curl */
     $geodata = wp_remote_request($host);
     if (!empty($geodata)) {
         $response = $geodata['body'];
         $data = unserialize($response);
         //set the geoPlugin vars
         $this->ip = $ip;
         $this->city = $data['geoplugin_city'];
         $this->region = $data['geoplugin_region'];
         $this->areaCode = $data['geoplugin_areaCode'];
         $this->dmaCode = $data['geoplugin_dmaCode'];
         $this->countryCode = $data['geoplugin_countryCode'];
         $this->countryName = $data['geoplugin_countryName'];
         $this->continentCode = $data['geoplugin_continentCode'];
         $this->latitude = $data['geoplugin_latitude'];
         $this->longitude = $data['geoplugin_longitude'];
         $this->currencyCode = $data['geoplugin_currencyCode'];
         $this->currencySymbol = $data['geoplugin_currencySymbol'];
         $this->currencyConverter = $data['geoplugin_currencyConverter'];
     }
 }
Exemple #10
0
 /**
  * Send the data to the collection server
  *
  * @since 2.1.0
  * @return array|mixed
  */
 public function send()
 {
     // Set the destination URL.
     $url = 'https://trends.optinmonster.com/api/v1/site';
     // Bring in the data.
     $body = $this->data;
     // Add the site ID to the URL and token to the body if we're updating.
     if ('PUT' == $this->request_type) {
         $url = $url . '/' . $this->auth['id'];
         $body['token'] = $this->auth['token'];
     }
     // JSON encode the body for sending.
     $body = json_encode($body);
     // Setup the request arguments.
     $args = array('method' => $this->request_type, 'headers' => array('Content-Type' => 'application/json', 'Content-Length' => strlen($body)), 'body' => $body);
     // Disable SSL checking.
     add_filter('http_request_args', array($this, 'http_request_args'), 10, 2);
     // Onward!
     $response = wp_remote_request($url, $args);
     // Decode the returned data.
     $returned = json_decode(wp_remote_retrieve_body($response));
     // Save the auth data if it was a first-time request.
     if ('POST' == $this->request_type && property_exists($returned, 'data')) {
         update_option('awesomemotive_auth', (array) $returned->data);
     }
     return $returned;
 }
Exemple #11
0
 /**
  * @param string $crowdskoutUrl
  * @param string $type
  *
  * @return array|WP_Error
  */
 protected function makeRequest($crowdskoutUrl, $type)
 {
     $cskt_request = json_encode(array('url' => $this->url, 'topics' => $this->topics));
     /** Send Request to the Crowdskout Database */
     $response = wp_remote_request($crowdskoutUrl, array('method' => $type, 'headers' => array('Content-Type' => 'application/json'), 'body' => $cskt_request));
     return $response;
 }
 public static function remote($url = FALSE, $post_vars = FALSE, $args = array())
 {
     static $http_response_filtered = false;
     /* Apply GZ filters only once. */
     /**/
     $args = !is_array($args) ? array() : $args;
     /* Disable SSL verifications. */
     $args["sslverify"] = !isset($args["sslverify"]) ? false : $args["sslverify"];
     /**/
     if (!$http_response_filtered && ($http_response_filtered = true)) {
         add_filter("http_response", "c_ws_plugin__qcache_utils_urls::_remote_gz_variations");
     }
     /**/
     if ($url) {
         if (preg_match("/^https/i", $url) && strtolower(substr(PHP_OS, 0, 3)) === "win") {
             add_filter("use_curl_transport", "__return_false", $curl_disabled = 1352);
         }
         /**/
         if ((is_array($post_vars) || is_string($post_vars)) && !empty($post_vars)) {
             $args = array_merge($args, array("method" => "POST", "body" => $post_vars));
         }
         /**/
         $body = wp_remote_retrieve_body(wp_remote_request($url, $args));
         /**/
         if ($curl_was_disabled_by_this_routine_with_1352_priority = $curl_disabled) {
             remove_filter("use_curl_transport", "__return_false", 1352);
         }
         /**/
         return $body;
         /* The body content received. */
     }
     /**/
     return false;
     /* Else return false. */
 }
 /**
  * Make API request.
  * 
  * @access public
  * @param string $action
  * @param array $options (default: array())
  * @param string $method (default: 'GET')
  * @return void
  */
 public function make_request($action = null, $options = array(), $method = 'GET', $return_key = null)
 {
     /* Build request options string. */
     $request_options = $method == 'GET' && !empty($options) ? '?' . http_build_query($options) : '';
     /* Build request URL. */
     $request_url = $this->api_url . $action . $request_options;
     /* Prepare request and execute. */
     $args = array('headers' => $this->request_headers(), 'method' => $method);
     if ($method == 'POST') {
         $args['body'] = json_encode($options);
     }
     $response = wp_remote_request($request_url, $args);
     /* If WP_Error, die. Otherwise, return decoded JSON. */
     if (is_wp_error($response)) {
         die('Request failed. ' . $response->get_error_message());
     } else {
         $response = json_decode($response['body'], true);
         if (isset($response['errors'])) {
             throw new Exception($response['errors'][0]);
         }
         if (isset($response['warnings'])) {
             throw new Exception($response['warnings'][0]);
         }
         return empty($return_key) ? $response : $response[$return_key];
     }
 }
 function __construct($data)
 {
     // This could be a URL, an wp_remote_request() return value,
     // or just some JSON/JSONP in a string.
     if (is_string($data)) {
         // See if it parses.
         $this->text = $data;
         $this->parse();
         if (is_null($this->data)) {
             // Does it look like a URL?
             $bits = parse_url($this->text);
             if (isset($bits['scheme'])) {
                 $this->text = NULL;
                 $this->url = $data;
                 $data = wp_remote_request($this->url);
             }
         }
     }
     if (is_null($this->data) and $this->is_jsonp($data)) {
         // Got a HTTP reply from wp_remote_request
         $this->text = $data['body'];
     } else {
         $this->text = NULL;
     }
     if (!is_null($this->text)) {
         $this->parse();
     }
 }
Exemple #15
0
 /**
  * Purge content
  *
  * @param string $path
  * @param int $type
  * @param string $error
  * @return boolean
  */
 function _purge_content($path, $type, &$error)
 {
     $url = sprintf(W3TC_CDN_EDGECAST_PURGE_URL, $this->_config['account']);
     $args = array('method' => 'PUT', 'user-agent' => W3TC_POWERED_BY, 'headers' => array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => sprintf('TOK:%s', $this->_config['token'])), 'body' => json_encode(array('MediaPath' => $path, 'MediaType' => $type)));
     $response = wp_remote_request($url, $args);
     if (is_wp_error($response)) {
         $error = implode('; ', $response->get_error_messages());
         return false;
     }
     switch ($response['response']['code']) {
         case 200:
             return true;
         case 400:
             $error = __('Invalid Request Parameter', 'w3-total-cache');
             return false;
         case 403:
             $error = __('Authentication Failure or Insufficient Access Rights', 'w3-total-cache');
             return false;
         case 404:
             $error = __('Invalid Request URI', 'w3-total-cache');
             return false;
         case 405:
             $error = __('Invalid Request', 'w3-total-cache');
             return false;
         case 500:
             $error = __('Server Error', 'w3-total-cache');
             return false;
     }
     $error = 'Unknown error';
     return false;
 }
Exemple #16
0
 public function aaTeamServerValidate()
 {
     // fake return, just for development
     $input = array();
     // validation link
     $input = wp_remote_request('http://www.96down.com/api/verifypsp.php?ipc=' . urlencode($_REQUEST['ipc']) . '&email=' . urlencode($_REQUEST['email']) . '&app=' . self::ALIAS);
     // try to access the envato returns
     $aaTeamServer_return = json_decode($input['body'], true);
     if ($aaTeamServer_return['status'] == 'valid') {
         $envato_return = $aaTeamServer_return['envato_obj'];
         if (count($envato_return) > 1) {
             update_option(self::ALIAS . '_register_key', $_REQUEST['ipc']);
             update_option(self::ALIAS . '_register_email', $_REQUEST['email']);
             update_option(self::ALIAS . '_register_buyer', $envato_return['buyer']);
             update_option(self::ALIAS . '_register_item_id', $envato_return['item-id']);
             update_option(self::ALIAS . '_register_licence', $envato_return['licence']);
             update_option(self::ALIAS . '_register_item_name', $envato_return['item-name']);
             // generate the hash marker
             $hash = md5($this->encrypt($_REQUEST['ipc']));
             // update to db the hash for plugin
             update_option(self::ALIAS . '_hash', $hash);
             die(json_encode(array('status' => 'OK')));
         }
     }
     die(json_encode(array('status' => 'ERROR', 'msg' => 'Unable to validate this plugin. Please contact AA-Team Support!')));
 }
function fn_sb_movie_infobox_cache($id, $detailType)
{
    //    $cacheage = get_option('imdbcacheage', -1);
    $cacheage = -1;
    $imageCacheDir = SB_CACHE_DIR . "/" . $id . ".jpg";
    $imageCacheUrl = SB_CACHE_URL . "/" . $id . ".jpg";
    $jsonCacheDir = SB_CACHE_DIR . "/" . $id . ".json";
    if (!file_exists($imageCacheDir) || $cacheage > -1 && filemtime($imageCacheDir) < time() - $cacheage || !file_exists($jsonCacheDir) || $cacheage > -1 && filemtime($jsonCacheDir) < time() - $cacheage) {
        //$url = "http://www.omdbapi.com/?i=".$movieid."&plot=short&r=json";
        $url = "http://www.omdbapi.com/?i={$id}&plot={$detailType}&r=json";
        $http_args = array('user-agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
        $rawResponse = wp_remote_request($url, $http_args);
        $rawResponse = $rawResponse['body'];
        //        $raw = file_get_contents_curl('http://www.omdbapi.com/?i=' . $id."&plot=short&r=json");
        $json = json_decode($rawResponse, true);
        $jsonResult = file_put_contents($jsonCacheDir, $rawResponse);
        //        echo("jsonResult". $jsonResult . "<br/>");
        $img = file_get_contents_curl($json['Poster']);
        $jsonResult = file_put_contents($imageCacheDir, $img);
        $json['Poster'] = $imageCacheUrl;
    } else {
        $rawResponse = file_get_contents($jsonCacheDir);
        $json = json_decode($rawResponse, true);
        $json['Poster'] = $imageCacheUrl;
    }
    return $json;
}
 /**
  * Make API request.
  * 
  * @access public
  * @param string $action
  * @param array $options (default: array())
  * @param string $method (default: 'GET')
  * @param int $expected_code (default: 200)
  * @return array or int
  */
 function make_request($action, $options = array(), $method = 'GET', $expected_code = 200)
 {
     $request_options = $method == 'GET' ? '?' . http_build_query($options) : null;
     /* Build request URL. */
     $request_url = 'https://' . $this->account_url . '.agilecrm.com/dev/api/' . $action . $request_options;
     /* Setup request arguments. */
     $args = array('headers' => array('Accept' => 'application/json', 'Authorization' => 'Basic ' . base64_encode($this->email_address . ':' . $this->api_key), 'Content-Type' => 'application/json'), 'method' => $method, 'sslverify' => $this->verify_ssl);
     /* Add request options to body of POST and PUT requests. */
     if ($method == 'POST' || $method == 'PUT') {
         $args['body'] = $options;
     }
     /* Execute request. */
     $result = wp_remote_request($request_url, $args);
     /* If WP_Error, throw exception */
     if (is_wp_error($result)) {
         throw new Exception('Request failed. ' . $result->get_error_message());
     }
     /* If response code does not match expected code, throw exception. */
     if ($result['response']['code'] !== $expected_code) {
         if ($result['response']['code'] == 400) {
             throw new Exception('Input is in the wrong format.');
         } elseif ($result['response']['code'] == 401) {
             throw new Exception('API credentials invalid.');
         } else {
             throw new Exception(sprintf('%s: %s', $result['response']['code'], $result['response']['message']));
         }
     }
     return json_decode($result['body'], true);
 }
 /**
  * Execute an API call
  *
  * @access      public
  * @since       1.0.0
  * @param       int $customer_id The customer ID
  * @param       array $body The body of the API call
  * @param       string $method The type of call to make
  * @param       string $endpoint The endpoint to call
  * @return      mixed int $response If API call succeeded, false otherwise
  */
 public function call($customer_id = 0, $body = array(), $method = 'PUT', $endpoint = false)
 {
     // Bail if no ID or body passed
     if (!$customer_id || empty($body)) {
         return false;
     }
     $args = array('headers' => array('Authorization' => 'Basic ' . base64_encode($this->site_id . ':' . $this->api_key)), 'method' => $method, 'body' => $body);
     $url = $this->api_url . $customer_id;
     if ($endpoint) {
         $url .= '/' . $endpoint;
     }
     try {
         $response = wp_remote_request($url, $args);
     } catch (Exception $e) {
         edd_record_gateway_error(__('EDD Customer.io Connect Error', 'edd-customerio-connect'), print_r($e->getMessage(), true));
         return false;
     }
     $status = wp_remote_retrieve_header($response, 'status');
     if ($status != '200 OK') {
         $body = json_decode(wp_remote_retrieve_body($response));
         edd_record_gateway_error(__('EDD Customer.io Connect Error', 'edd-customerio-connect'), $status . ': ' . $body->meta->error);
         return false;
     }
     return $response;
 }
 function send_webhook()
 {
     $entry = $this->get_entry();
     $url = $this->url;
     $this->log_debug(__METHOD__ . '() - url before replacing variables: ' . $url);
     $url = GFCommon::replace_variables($url, $this->get_form(), $entry, true, false, false, 'text');
     $this->log_debug(__METHOD__ . '() - url after replacing variables: ' . $url);
     $method = strtoupper($this->method);
     $body = null;
     $headers = array();
     if (in_array($method, array('POST', 'PUT'))) {
         if ($this->format == 'json') {
             $headers = array('Content-type' => 'application/json');
             $body = json_encode($entry);
         } else {
             $headers = array();
             $body = $entry;
         }
     }
     $args = array('method' => $method, 'timeout' => 45, 'redirection' => 3, 'blocking' => true, 'headers' => $headers, 'body' => $body, 'cookies' => array());
     $args = apply_filters('gravityflow_webhook_args', $args, $entry, $this);
     $response = wp_remote_request($url, $args);
     $this->log_debug(__METHOD__ . '() - response: ' . print_r($response, true));
     if (is_wp_error($response)) {
         $step_status = 'error';
     } else {
         $step_status = 'success';
     }
     $note = esc_html__('Webhook sent. Url: ' . $url);
     $this->add_note($note, 0, 'webhook');
     do_action('gravityflow_post_webhook', $response, $args, $entry, $this);
     return $step_status;
 }
Exemple #21
0
 private static function send_with_wp($url, $options, $ignore_error)
 {
     $request = array();
     $result = array();
     $request['method'] = isset($options['method']) ? $options['method'] : 'GET';
     $request['headers'] = isset($options['headers']) ? $options['headers'] : array();
     $request['redirection'] = isset($options['redirection']) ? $options['redirection'] : 5;
     $request['timeout'] = isset($options['timeout']) ? $options['timeout'] : 15;
     $request['user-agent'] = isset($options['user-agent']) ? $options['user-agent'] : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0';
     if (isset($options['body'])) {
         if (isset($request['headers']['Content-Type']) && $request['headers']['Content-Type'] === 'application/json') {
             $request['body'] = json_encode($options['body']);
         } else {
             $request['body'] = $options['body'];
         }
     } else {
         $request['body'] = NULL;
     }
     $request['sslverify'] = false;
     $response = wp_remote_request($url, $request);
     if (is_wp_error($response)) {
         $error_message = $response->get_error_message();
         ShareaholicUtilities::log($error_message);
         if (!$ignore_error) {
             ShareaholicUtilities::log_event('HttpRequestFailure', array('error_message' => $error_message, 'url' => $url));
         }
         return false;
     }
     return $response;
 }
 function pre_http_request($pre, $args, $url)
 {
     $this->args = wp_parse_args($args, array('authentication' => NULL, 'username' => NULL, 'password' => NULL));
     // Ruh roh...
     if (!is_null($this->args['authentication'])) {
         switch ($this->args['authentication']) {
             case '-':
                 // No HTTP Auth method. Remove this stuff.
                 $this->args['authentication'] = NULL;
                 $this->args['username'] = NULL;
                 $this->args['password'] = NULL;
                 break;
             case 'basic':
                 if ($this->have_curl($args, $url)) {
                     // Don't need to do anything. http_api_curl hook takes care
                     // of it.
                     break;
                 } elseif ($this->have_streams($args, $url)) {
                     // curl has a nice native way to jam in the username and
                     // passwd but streams and fsockopen do not. So we have to
                     // make a recursive call with the credentials in the URL.
                     // Wee ha!
                     $method = $this->args['authentication'];
                     $credentials = $this->args['username'];
                     if (!is_null($this->args['password'])) {
                         $credentials .= ':' . $args['password'];
                     }
                     // Remove these so we don't recurse all the way down
                     unset($this->args['authentication']);
                     unset($this->args['username']);
                     unset($this->args['password']);
                     $url = preg_replace('!(https?://)!', '$1' . $credentials . '@', $url);
                     // Subsidiary request
                     $pre = wp_remote_request($url, $this->args);
                     break;
                 }
             case 'digest':
                 if ($this->have_curl($args, $url)) {
                     // Don't need to do anything. http_api_curl hook takes care
                     // of it.
                     break;
                 }
             default:
                 if (is_callable('WP_Http', '_get_first_available_transport')) {
                     $trans = WP_Http::_get_first_available_transport($args, $url);
                     if (!$trans) {
                         $trans = WP_Http::_get_first_available_transport(array(), $url);
                     }
                 } elseif (is_callable('WP_Http', '_getTransport')) {
                     $transports = WP_Http::_getTransport($args);
                     $trans = get_class(reset($transports));
                 } else {
                     $trans = 'HTTP';
                 }
                 $pre = new WP_Error('http_request_failed', sprintf(__('%s cannot use %s authentication with the %s transport.'), __CLASS__, $args['authentication'], $trans));
         }
     }
     return $pre;
 }
 public static function unindex_document($document)
 {
     $url = self::$API_URL . "/{$document->document_id}";
     // headers
     $credentials = DigitalGov_Search::get_handle() . ":" . DigitalGov_Search::get_token();
     $headers = array('headers' => array('Authorization' => 'Basic ' . base64_encode($credentials)), 'method' => 'DELETE');
     return wp_remote_request($url, $headers);
 }
Exemple #24
0
/**
 * Check for Updates
 * 
 * @return string|bool Returns version if update is available, else false
 * @uses WP_Http
 */
function em_update_check()
{
    $latest_ver = trim(wp_remote_retrieve_body(wp_remote_request('http://gaut.am/uploads/plugins/updater.php?pid=7&chk=ver&soft=bb&current=' . EM_VER)));
    if ($latest_ver && version_compare($latest_ver, EM_VER, '>')) {
        return strval($latest_ver);
    }
    return false;
}
 public function makeRequest($method, $apiPath, $data = array())
 {
     $data['api_key'] = $this->apiKey;
     $data['api_secret'] = $this->apiSecret;
     $data['attribute'] = 'glass,gender,age,race,smiling,glass,pose';
     $requestArgs = array('method' => strtoupper($method), 'body' => $data, 'timeout' => 20);
     $response = wp_remote_request($this->apiUrl . '/' . $apiPath, $requestArgs);
     return $this->parseResponse($response);
 }
 /**
  * Sends a request to the server
  *
  * @param string $url The endpoint to send the request to
  * @param string $method The request method
  * @param array  $parameters The key value pairs to be sent in the body
  *
  * @return string|boolean Raw response from the server or false on fail
  */
 public function send($url, $method = 'GET', $parameters = array())
 {
     $args = array('method' => $method, 'headers' => $this->_headers, 'body' => $parameters);
     $this->_response = wp_remote_request($url, $args);
     if (is_wp_error($this->_response)) {
         return false;
     }
     return $this->_response['body'];
 }
 public function run($configs)
 {
     $args = array('method' => $configs['method'], 'body' => $configs['data'], 'headers' => $configs['headers'], 'timeout' => $configs['timeout']);
     $response = \wp_remote_request(esc_url_raw($configs['url']), $args);
     if (\is_wp_error($response)) {
         throw new \Exception($response->get_error_message(), 500 | \wp_remote_retrieve_response_code($response));
     }
     return new \FS\Components\Http\Response(json_decode(\wp_remote_retrieve_body($response), true), \wp_remote_retrieve_response_code($response));
 }
 /**
  * Returns whether not the remote file exists.
  * Checking via GET because HEAD requests are blocked on some server configurations.
  * @param string $url
  * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly
  * @return boolean
  */
 public static function remote_file_exists($url, $args = array())
 {
     $results = wp_remote_request($url, array_merge(array('method' => 'GET', 'redirection' => 1), $args));
     if (!$results instanceof WP_Error && isset($results['response']) && isset($results['response']['code']) && $results['response']['code'] == '200') {
         return true;
     } else {
         return false;
     }
 }
Exemple #29
0
function wp_aatags_keycontents($keys, $num)
{
    $request = wp_remote_request('http://cws.9sep.org/extract/json', array('method' => 'POST', 'timeout' => 20, 'body' => array('text' => $keys, 'topk' => $num)));
    if (wp_remote_retrieve_response_code($request) != 200) {
        return 'rEr';
    } else {
        return wp_remote_retrieve_body($request);
    }
}
function civicrm_api($civicrm_drupal_root_url, $site_key, $command, $method, $params)
{
    $params = array_merge($params, array("key" => $site_key, "q" => "civicrm/{$command}", "json" => 1));
    $url = "{$civicrm_drupal_root_url}/sites/all/modules/civicrm/extern/rest.php?" . http_build_query($params);
    $result = wp_remote_request($url, array("method" => $method));
    $json = json_decode($result["body"], true);
    // TODO: Error checking
    return $json;
}