Returns JSON from URL.

@param array $parameters Parameters, just URL for now.

@return string
495365
public function fetchJson($parameters = [])
    {
        if (!isset($parameters['url'])) {
            Craft::error('URL parameter not set', __METHOD__);
            return false;
        }

        $data = self::getUrl($parameters['url']);
        return json_decode($data, true);
    }
451259
private function executeRequest($parameters = array()) {

        $curl_options = array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => 2,
            CURLOPT_CUSTOMREQUEST  => 'POST',
            CURLOPT_CONNECTTIMEOUT => $this->curlTimeout,
            CURLOPT_TIMEOUT        => $this->curlConnectTimeout,
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => $parameters,
            CURLOPT_URL            => $this->apiUrl[$this->mode]
        );

        $ch = curl_init();
        curl_setopt_array($ch, $curl_options);

        $result = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if ($curl_error = curl_error($ch)) {
            throw new CFException($curl_error, CFException::CURL_ERROR);
        }

        $json_decode = json_decode($result, true);
        curl_close($ch);

        // Handling API errors
        if ((is_array($json_decode) && !empty($json_decode['err_code'])) || $json_decode['result'] == 'error') {
            throw new BadResponseException($json_decode['msg']);
        }
        if ($http_code !== 200) {
            throw new \HttpResponseException('HTTP Non-200 response', $http_code);
        }
        if (json_last_error() !== \JSON_ERROR_NONE) {
            throw new DecodeException('JSON decoding error', json_last_error());
        }

        return $json_decode;
    }
819397
private static function formatParameters(array $params)
    {
        return '[' . implode(', ', array_map(static function ($param) {
            if (is_resource($param)) {
                return (string) $param;
            }

            $json = @json_encode($param);

            if (! is_string($json) || $json === 'null' && is_string($param)) {
                // JSON encoding failed, this is not a UTF-8 string.
                return sprintf('"%s"', preg_replace('/.{2}/', '\\x$0', bin2hex($param)));
            }

            return $json;
        }, $params)) . ']';
    }
158329
public function loadResource(string $url, array $parameters): array
    {
        $signature = $this->createSignature($url, $parameters);
        if ($this->cache->has($signature)) {
            return $this->cache->get($signature);
        }

        $parameters['format'] = 'json';
        $parameters['api_key'] = $this->config->getApiKey();
        $url = $this->config->getApiEndpoint().$this->buildQueryUrl($url, $parameters);

        $response = $this->guzzle->request('GET', $url);
        $body = $this->processResponse($response);

        $this->cache->set($signature, $body['results']);

        return $body['results'];
    }
288921
public function createUrl(array $parameters = array())
    {
        $final_parameters = $this->getFinalParameters();
        $path = $this->getBaseURL();

        // Override default parameters
        $final_parameters = array_merge($final_parameters, $parameters);

        return $path . "?" . http_build_query($final_parameters, null, '&') . $this->buildFragment();
    }
26256
public function request($url, array $parameters = [], $requestMethod = 'GET')
    {
        try {
            $method = strtolower($requestMethod) === 'get' ? 'query' : 'form_params';
            $response = $this->getClient()->request($requestMethod, $url, [
                $method  => array_merge($this->getParams(), $parameters),
                'Accept' => 'application/json'
            ]);
            return json_decode($response->getBody());
        } catch (RequestException $e) {
            $this->printErrorMessage(Psr7\str($e->getResponse()), false);
        }
        return [];
    }
206613
public static function normalize(string $url, array $parameters = []):string
    {
        $normalizedUrl = $url;
        if (!empty($parameters)) {
            $normalizedUrl .= (false !== strpos($url, '?') ? '&' : '?') . http_build_query($parameters, '', '&');
        }
        return $normalizedUrl;
    }
888386
public function view($parameters)
    {
        if (!headers_sent()) {
            header('Content-Type: application/json;charset=utf-8');
        }

        //If JSONP requested (if callback is requested though GET)
        if (($callback = \Phramework\Phramework::getCallback())) {
            echo $callback;
            echo '([';
            echo json_encode($parameters);
            echo '])';
        } else {
            echo json_encode($parameters);
        }
    }
1297136
protected function getDateTimeFormat($parameters) {
        $format          = 'Y-m-d H:i:s';
        $parametersCount = count($parameters);
        if ($parametersCount > $this->amountOfParameters) {
            $format = $parameters[$parametersCount - 1];
        }
        return $format;
    }
1215180
public function getRelativeUrl(array $parameters = array())
    {
        $route = $this->request->attributes->get('_route');

        $parameters = array_merge($this->getParameters(), $parameters);

        return $this->router->generate($route, $parameters);
    }
792803
public function toJson($options = 0)
    {
        $items = array_map(function ($value)
        {
            if ($value instanceof JsonableInterface) {
                return json_decode($value->toJson(), true);
            } elseif ($value instanceof ArrayableInterface) {
                return $value->toArray();
            } else {
                return $value;
            }
        }, $this->items);

        return json_encode($items, $options);
    }
776201
public function view($parameters)
    {
        self::header();

        if (!is_object($parameters)) {
            $parameters = (object)$parameters;
        }

        //Include JSON API version object
        $parameters->jsonapi = (object)[
            'version' => '1.0'
        ];

        echo json_encode($parameters);
    }
740259
protected function getObjectsRawData(array $parameters = array())
    {
        $cacheKey = md5(json_encode(array($this->getName(), $parameters)));

        if (!array_key_exists($cacheKey, self::$listObjectsCache)) {
            $tmp = array();

            foreach ($parameters as $k => $v) {
                if (in_array($k, self::$allowedParameters)) {
                    $tmp[$k] = $v;
                }
            }

            $response = $this->connection->makeRequest(Client::GET, array($this->name), array(), $tmp);
            self::$listObjectsCache[$cacheKey] = $response['body'];
        }

        return self::$listObjectsCache[$cacheKey];
    }
877949
public function get($uri, $parameters = array())
    {
        return $this->request(self::METHOD_GET, $this->getUrl($uri), $parameters);
    }
415221
protected function doCall(array $parameters = array())
    {
        // check if curl is available
        if (!function_exists('curl_init')) {
            throw Exception::CurlNotInstalled();
        }

        // init curl
        $curl = curl_init();

        // set options
        curl_setopt($curl, CURLOPT_URL, $this->createUrl($parameters));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        }

        // execute
        $response = curl_exec($curl);

        // fetch errors
        $errorNumber = curl_errno($curl);
        $errorMessage = curl_error($curl);

        // close curl
        curl_close($curl);

        // we have errors
        if ($errorNumber != '') {
            throw new Exception($errorMessage);
        }

        // redefine response as json decoded
        $response = json_decode($response);

        // API returns with an error
        if (isset($response->error_message)) {
            throw new Exception($response->error_message);
        }

        // return the content
        return $response->results;
    }
612549
public function toJSON($options = 0)
    {
        // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option
        // Instead we would use the str_replace command for now.
        if (version_compare(phpversion(), '5.4.0', '>=') === true) {
            return json_encode($this->toArray(), $options | 64);
        }
        return str_replace('\\/', '/', json_encode($this->toArray(), $options));
    }
455222
public static function dump(array $parameters)
    {
        $content = '';

        foreach ($parameters as $key => $value) {
            if (is_bool($value)) {
                $value = $value ? 'true' : 'false';
            }
            $content .= "{$key} = {$value}\n";
        }

        return $content;
    }