Calls the API with the given parameters.

@param string $url URL call URL.

@return $this

@throws RuntimeException Thrown in case of API communication errors.
513783
protected function callApi($url)
    {
        $url = $this->apiBaseUrl . $url;

        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-Type: application/x-www-form-urlencoded',
                'ignore_errors' => true,
                'content' => http_build_query($this->parameters, '', '&')
            )
        );

        $context = stream_context_create($options);

        $fp = fopen($url, 'rb', false, $context);
        if (!$fp) {
            throw new RuntimeException(
                sprintf(
                    'Could not connect to NMA API URL %s',
                    var_export($url, true)
                ),
                500
            );
        }

        $res = stream_get_contents($fp);
        if ($res === false) {
            throw new RuntimeException(
                sprintf(
                    'Could not fetch data from NMA API URL %s',
                    var_export($url, true)
                ),
                500
            );
        }

        $xml = simplexml_load_string($res);
        if ($xml === null) {
            throw new RuntimeException(
                sprintf(
                    'Could not decode NMA API response for URL %s as XML. ' .
                    'Response was: %s',
                    var_export($url, true),
                    var_export($res, true)
                ),
                500
            );
        }

        return $this->processXmlReturn($xml);
    }
1116322
protected function getResponse(string $url):ResponseInterface {
		curl_setopt($this->curl, CURLOPT_URL, $url);

		return new Response($this->curl);
	}
348381
public function loadFile($url)
    {
        //Locate the template
        $locator = $this->getObject('template.locator.factory')->createLocator($url);

        if (!$file = $locator->locate($url)) {
            throw new InvalidArgumentException(sprintf('The template "%s" cannot be located.', $url));
        }

        //Load the template
        if(!$source = file_get_contents($file)) {
            throw new RuntimeException(sprintf('The template "%s" cannot be loaded.', $file));
        }

        $this->_source = $source;

        return $this;
    }
281768
protected static function _applyUrlFilters($url)
    {
        $request = static::getRequest(true);
        $e = null;
        foreach (static::$_urlFilters as $filter) {
            try {
                $url = $filter($url, $request);
            } catch (Exception $e) {
                // fall through
            } catch (Throwable $e) {
                // fall through
            }
            if ($e !== null) {
                if (is_array($filter)) {
                    $ref = new ReflectionMethod($filter[0], $filter[1]);
                } else {
                    $ref = new ReflectionFunction($filter);
                }
                $message = sprintf(
                    'URL filter defined in %s on line %s could not be applied. The filter failed with: %s',
                    $ref->getFileName(),
                    $ref->getStartLine(),
                    $e->getMessage()
                );
                throw new RuntimeException($message, $e->getCode(), $e);
            }
        }

        return $url;
    }
1204188
public function setUrl($url)
    {
        if (!filter_var($url, FILTER_VALIDATE_URL))
        {
            throw new InvalidDataException('Invalid url link');
        }

        $this->url = $url;

        return $this;
    }
454954
public static function setApiUrl($url)
    {
        $apiUrl = filter_var($url, FILTER_VALIDATE_URL);

        if (!$apiUrl) {
            throw new Exception\InvalidArgumentException(
                'API URL should be a valid url'
            );
        }

        self::$apiUrl = rtrim($url, '\\/');
    }
827184
final public function buildUrl(string $url, array $parameters = []) : string
    {
        if (! $this->builder) {
            throw new \RuntimeException('No URL builder has been registered');
        }

        return $this->builder->buildUrl($url, $parameters);
    }
63577
public function setUrl($url)
    {
        if (!empty($url) && ctype_print($url)) {
            $this->url = trim($url);
        }

        return $this;
    }
62008
public function setUrl($url)
    {
        $this->meta()->setUrl($url);
        $this->openGraph()->setUrl($url);

        return $this;
    }
229087
public function setServiceUrl ($url)
    {
        if ($this->hasBeenOpened()) {
            throw new CAS_OutOfSequenceException(
                'Cannot set the URL, stream already opened.'
            );
        }
        if (!is_string($url) || !strlen($url)) {
            throw new CAS_InvalidArgumentException('Invalid url.');
        }

        $this->_url = $url;
    }
189963
protected function api_call($url, $params) {
        $url = $this->build_rest_url($url, $params);
        $result = $this->curl($url);
        return json_decode($result);
    }
289059
protected function request($url, $method = 'GET', array $data = [])
    {
        try {
            return call_user_func_array([$this, strtolower($method)], [$url, $data]);
        } catch (\Exception $exception) {
            throw new \RuntimeException('Http method is not valid.');
        }
    }
1135497
public static function call($url)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);

        $result = curl_exec($ch);

        if (! $result) {
            throw new \Exception(sprintf('The endpoint "%s" is not returning anything.', $url));
        }

        return simplexml_load_string($result);
    }
1357417
protected function set($url)
    {
        $parts = parse_url($url);
        if (!$parts) {
            throw new \InvalidArgumentException('URL malformed');
        }

        $this->scheme   = isset($parts['scheme']) ? strtolower($parts['scheme']) : '';
        $this->username = $parts['user'] ?? '';
        $this->password = $parts['pass'] ?? '';
        $this->host     = isset($parts['host']) ? strtolower($parts['host']) : '';
        $this->port     = isset($parts['port']) ? intval($parts['port']) : null;
        $this->path     = $parts['path'] ?? '';
        $this->query    = $parts['query'] ?? '';
        $this->fragment = $parts['fragment'] ?? '';
    }
1082745
public function addUrl(Url $url)
    {
        if (!$this->urls->contains($url)) {
            $this->urls->add($url);
            $url->setSiteroot($this);
        }

        return $this;
    }
1052098
public function setUrl(string $url)
    {
        $url = filter_var($url, FILTER_VALIDATE_URL);

        if ($url == false) {
            throw new Exception("Invalid url");
        } else {
            curl_setopt($this->curl, CURLOPT_URL, $url);
        }
    }
219243
public function url(string $url) : self
    {
        $this->route = $url;

        $this->active($url);

        return $this;
    }