-
- /**
- * Hit some web API and return data on success.
- * @param string $url
- * @param array $params
- * @return string
- */
- static protected function http($url, $params=array())
- {
- $client = HTTPClient::start();
- if ($params) {
- $query = http_build_query($params, null, '&');
- if (strpos($url, '?') === false) {
- $url .= '?' . $query;
- } else {
- $url .= '&' . $query;
- }
- }
- $response = $client->get($url);
- if ($response->isOk()) {
- return $response->getBody();
- } else {
- throw new Exception('Bad HTTP response code: ' . $response->getStatus());
- }
- }