datawrapper/datawrapper — pull request #109 by fangel (2014-07-17 16:16:09+00:00)
Title: Feature: add oEmbed-endpoint for charts

Hi,

We are in the process of building an automated embedding-system for our CMS. The automation relies on oEmbed and oEmbed discovery.
And since we sometimes have to embed Datawrapper-contents, we thought it would be awesome if Datawrapper could support oEmbed and oEmbed Discovery (basically a `` on the exported charts.

We (Casper Thomsen) have discussed adding such a functionality with Mirko Lorenz via e-mail, and settled on us trying to add the functionality. So here's our attempt at adding the functionality.s of building an automated embedding-system for our CMS. The automation relies on oEmbed and oEmbed discovery.
And since we sometimes have to embed Datawrapper-contents, we thought it would be awesome if Datawrapper could support oEmbed and oEmbed Discovery (basically a `` on the exported charts.

We (Casper Thomsen) have discussed adding such a functionality with Mirko Lorenz via e-mail, and settled on us trying to add the functionality. So here's our attempt at adding the functionality.

It consists of a small change to the `chart.twig`-template that adds the ``, and then a new API-endpoint (located in `lib/api/oembed.php`) at the path `api/oembed`.

The oEmbed is performed by checking if the URL to embed matches the URL to see if it's a chart URL, and if it is, extract the id. If the chart is public, then it generates a oEmbed document with an iframe in it.

We have updated the API tests to check if the API-endpoint works. To get this to work, I had to also modify the tests such that the created user is activated and authenticated. The chart has the user added as an author, and then the chart is published. I've also added clean-up functionality such that the created user and chart is removed again.
During my process of adding in the test of the user-deletion endpoint I stumbled across a bug where a user couldn't be removed if the user was given by an ID from a non-admin user, because it used strict equality, but there was a type-mismatch as the provided user-id is represented as a string (from its nature if coming from the URL).

TODO:
[ ] Ensure that the oEmbed functionality works on CDN paths.

Kind Regards
Morten Fangel
TV2 DANMARK