public function getObject(array $parameters = array())
    {
        if ($this->url === null) {
            throw new \InvalidArgumentException('Missing URL.');
        }

        if ($this->endpoint === null) {
            $this->endpoint = $this->discover($this->url);
        }

        $sign = '?';
        if ($query = parse_url($this->endpoint, PHP_URL_QUERY)) {
            $sign = '&';

            parse_str($query, $parameters);
        }

        if (!isset($parameters['url'])) {
            $parameters['url'] = $this->url;
        }
        if (!isset($parameters['format'])) {
            $parameters['format'] = 'json';
        }

        $client = new Client(
            sprintf('%s%s%s', $this->endpoint, $sign, http_build_query($parameters))
        );

        $data = $client->send();

        switch ($parameters['format']) {
            case 'json':
                $data = json_decode($data);
                if (!is_object($data)) {
                    throw new \InvalidArgumentException('Could not parse JSON response.');
                }

                break;

            case 'xml':
                libxml_use_internal_errors(true);
                $data = simplexml_load_string($data);
                if (!$data instanceof \SimpleXMLElement) {
                    $errors = libxml_get_errors();
                    $error  = array_shift($errors);
                    libxml_clear_errors();
                    libxml_use_internal_errors(false);
                    throw new \InvalidArgumentException($error->message, $error->code);
                }

                break;
        }

        return Object::factory($data);
    }
public function getObject(array $parameters = array())
    {
        if ($this->url === null) {
            throw new \InvalidArgumentException('Missing URL.');
        }

        if ($this->endpoint === null) {
            $this->endpoint = $this->discover($this->url);
        }

        $sign = '?';
        if ($query = parse_url($this->endpoint, PHP_URL_QUERY)) {
            $sign = '&';

            parse_str($query, $parameters);
        }

        if (!isset($parameters['url'])) {
            $parameters['url'] = $this->url;
        }
        if (!isset($parameters['format'])) {
            $parameters['format'] = 'json';
        }

        $client = new Client(
            sprintf('%s%s%s', $this->endpoint, $sign, http_build_query($parameters))
        );

        $data = $client->send();

        switch ($parameters['format']) {
            case 'json':
                $data = json_decode($data);
                if (!is_object($data)) {
                    throw new \InvalidArgumentException('Could not parse JSON response.');
                }

                break;

            case 'xml':
                libxml_use_internal_errors(true);
                $data = simplexml_load_string($data);
                if (!$data instanceof \SimpleXMLElement) {
                    $errors = libxml_get_errors();
                    $error  = array_shift($errors);
                    libxml_clear_errors();
                    libxml_use_internal_errors(false);
                    throw new \InvalidArgumentException($error->message, $error->code);
                }

                break;
        }

        return Object::factory($data);
    }
public function getObject ( array $ parameters = array ( ) ) { if ( $ this -> url === null ) { throw new \ InvalidArgumentException ( 'Missing URL.' ) ; } if ( $ this -> endpoint === null ) { $ this -> endpoint = $ this -> discover ( $ this -> url ) ; } $ sign = '?' ; if ( $ query = parse_url ( $ this -> endpoint , PHP_URL_QUERY ) ) { $ sign = '&' ; parse_str ( $ query , $ parameters ) ; } if ( ! isset ( $ parameters [ 'url' ] ) ) { $ parameters [ 'url' ] = $ this -> url ; } if ( ! isset ( $ parameters [ 'format' ] ) ) { $ parameters [ 'format' ] = 'json' ; } $ client = new Client ( sprintf ( '%s%s%s' , $ this -> endpoint , $ sign , http_build_query ( $ parameters ) ) ) ; $ data = $ client -> send ( ) ; switch ( $ parameters [ 'format' ] ) { case 'json' : $ data = json_decode ( $ data ) ; if ( ! is_object ( $ data ) ) { throw new \ InvalidArgumentException ( 'Could not parse JSON response.' ) ; } break ; case 'xml' : libxml_use_internal_errors ( true ) ; $ data = simplexml_load_string ( $ data ) ; if ( ! $ data instanceof \ SimpleXMLElement ) { $ errors = libxml_get_errors ( ) ; $ error = array_shift ( $ errors ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( false ) ; throw new \ InvalidArgumentException ( $ error -> message , $ error -> code ) ; } break ; } return Object :: factory ( $ data ) ; }
Get the oEmbed response

@param array $params Optional parameters for

@return object The oEmbed response as an object

@throws \RuntimeException         On HTTP errors
@throws \InvalidArgumentException when result is not parsable
Get the oEmbed response