- Apis\Fetch
class Apis \ Fetch
Method Summary
| Name | Description |
|---|---|
| checkJSend($json) | Checks the JSON to make sure it adheres to the JSend format http://labs.omniti.com/labs/jsend. Throws an JSendException if the JSON returned a 'fail', otherwise returns the wrapped data. |
| checkResponse($string) | |
| get($url, $options = array(), $headers = array()) |
Wraps #file_get_contents with timeout information etc. Actually uses curl to do the fetch. Optionally uses the user agent defined in Config::get('fetch_user_agent'). |
| initCurl() |
Extends #curl_init to also set CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT appropriately. These are set based on Config::get('get_contents_timeout') and Config::get('get_contents_timeout') |
| jsonDecode($string) | Try to decode a JSON string, or try and work out why it failed to decode but throw an exception if it was not a valid JSON string. |
| post($url, $post_data, $options = array(), $headers = array()) |
Uses curl to POST data to a URL. Optionally uses the user agent defined in Config::get('fetch_user_agent'). |
static function checkJSend($json)
Checks the JSON to make sure it adheres to the JSend format http://labs.omniti.com/labs/jsend. Throws an JSendException if the JSON returned a 'fail', otherwise returns the wrapped data.
- Returns:
$json['data'] if there were no problems- Throws:
JSendException - if there was a failure in the response
static function checkResponse($string)
- Throws:
a - CloudFlareException or IncapsulaException if the given remote response suggests something about CloudFlare or Incapsulaan - FetchException if the response suggests something else that was unexpected
static function get($url, $options = array(), $headers = array())
Wraps #file_get_contents with timeout information etc. Actually uses
curlto do the fetch. Optionally uses the user agent defined in Config::get('fetch_user_agent').TODO currently sets CURLOPT_SSL_VERIFYPEER to FALSE globally; this should be an option
- Parameters:
$options- additional CURL options to pass- Defaults:
options= array()headers= array()- Throws:
a - FetchHttpException if the remote server returned HTTP 400 or higher
static function initCurl()
Extends #curl_init to also set
CURLOPT_TIMEOUTandCURLOPT_CONNECTTIMEOUTappropriately. These are set based on Config::get('get_contents_timeout') and Config::get('get_contents_timeout')
static function jsonDecode($string)
Try to decode a JSON string, or try and work out why it failed to decode but throw an exception if it was not a valid JSON string.
- Throws:
a - FetchException if the JSON is not valid
static function post($url, $post_data, $options = array(), $headers = array())
Uses
curlto POST data to a URL. Optionally uses the user agent defined in Config::get('fetch_user_agent').TODO currently sets CURLOPT_SSL_VERIFYPEER to FALSE globally; this should be an option
- Parameters:
$options- additional CURL options to pass$headers- additional headers to pass- Defaults:
options= array()headers= array()- Throws:
a - FetchHttpException if the remote server returned HTTP 400 or higher