Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 2.22 KB

04-fake-responses.md

File metadata and controls

51 lines (38 loc) · 2.22 KB

Fake Responses / Offline Support

One of the key features of Embera is offline support. This feature allows you to get at least the html embed code for some services, without having to make a real http request to the oembed provider. What Offline support really means, is that the html embed code is constructed from the original url given, this also means that most of the other information such as the title or the author's name, is probably going to be missing. Lets call that a fake response.

Take a look at the 02-providers.md to see which providers allow offline support.

There is a configuration setting called fake_responses that should be used in order to change the way the library communicates with the oembed endpoint. By default the value equals Embera::ALLOW_FAKE_RESPONSES, which means that Embera will first try to get the data from the oembed endpoint and if that fails it tries to return a fake response. This behaviour is useful when there are problems connecting with the oembed provider! This means that you get at least an html embeddable code.

When the fake_responses setting equals Embera::DISABLE_FAKE_RESPONSES the library gets the data directly from the oembed provider. If something goes wrong with the request, Embera skips the usage of fake responses.

On the other hand you can set the fake_responses setting to Embera::ONLY_FAKE_RESPONSES and by doing that, you will always get fake responses. By doing this you are skipping the request to the supported oembed providers.

Knowing when a fake response was given

When using the getUrlData() method, it is possible to see if the information from the provider came directly from the oembed endpoint or if it was generated by the offline feature.

If the response contains the key embera_using_fake_response and its equal to 0 it means that the library got the results from the Oembed provider. When it equals 1, the html embed code was generated by the library.

Example:

$config = [
    'fake_responses' => Embera::ONLY_FAKE_RESPONSES,
];

$embera = new Embera($config);

$text = 'http://vimeo.com/groups/shortfilms/videos/66185763 and http://www.flickr.com/photos/bees/8597283706/in/photostream';
echo $embera->autoEmbed($text);