/** * @param string Http\Request::GET|POST|... * @param string path like '/users/:user/repos' where ':user' is substitution * @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL * @param array[name => value] name is case-insensitive * @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set * @return Http\Request * * @throws MissingParameterException when substitution is used in URL but parameter is missing * @throws JsonException when encoding to JSON fails */ public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL) { $parameters += $this->defaultParameters; $this->substituteUrlParameters($urlPath, $parameters); $url = rtrim($this->url, '/') . '/' . trim($urlPath, '/'); if (count($parameters)) { $url .= '?' . http_build_query($parameters); } if ($content !== NULL && (is_array($content) || is_object($content))) { $headers['Content-Type'] = 'application/json; charset=utf-8'; $content = Helpers::jsonEncode($content); } return new Http\Request($method, $url, $headers, $content); }
/** * @param string Http\Request::GET|POST|... * @param string path like '/users/:user/repos' where ':user' is substitution * @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL * @param array[name => value] name is case-insensitive * @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set * @return Http\Request * * @throws MissingParameterException when substitution is used in URL but parameter is missing * @throws JsonException when encoding to JSON fails */ public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL) { if (stripos($urlPath, $this->url) === 0) { $urlPath = substr($urlPath, strlen($this->url)); } if (strpos($urlPath, '{') === FALSE) { $urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters); } else { $urlPath = $this->expandUriTemplate($urlPath, $parameters, $this->defaultParameters); } $url = rtrim($this->url, '/') . '/' . ltrim($urlPath, '/'); if ($content !== NULL && (is_array($content) || is_object($content))) { $headers['Content-Type'] = 'application/json; charset=utf-8'; $content = Helpers::jsonEncode($content); } return new Http\Request($method, $url, $headers, $content); }
protected function processRequestOutput_json(array $_) { return Helpers::jsonEncode($_["result"], 500); }
/** * @param string Http\Request::GET|POST|... * @param string path like '/users/:user/repos' where ':user' is substitution * @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL * @param array[name => value] name is case-insensitive * @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set * @return Http\Request * * @throws MissingParameterException when substitution is used in URL but parameter is missing * @throws JsonException when encoding to JSON fails */ public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL) { if (stripos($urlPath, $this->url) === 0) { # Allows non-HTTPS URLs $baseUrl = $this->url; $urlPath = substr($urlPath, strlen($this->url)); } elseif (preg_match('#^(https://[^/]+)(/.*)?$#', $urlPath, $m)) { $baseUrl = $m[1]; $urlPath = isset($m[2]) ? $m[2] : ''; } else { $baseUrl = $this->url; } if (strpos($urlPath, '{') === FALSE) { $urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters); } else { $urlPath = $this->expandUriTemplate($urlPath, $parameters, $this->defaultParameters); } $url = rtrim($baseUrl, '/') . '/' . ltrim($urlPath, '/'); if ($content !== NULL && (is_array($content) || is_object($content))) { $headers['Content-Type'] = 'application/json; charset=utf-8'; $content = Helpers::jsonEncode($content); } return new Http\Request($method, $url, $headers, $content); }
public function sendRequest_encodeData_json(array $_) { return Helpers::jsonEncode($_); }