ruby-oembed
ruby-oembed copied to clipboard
ProviderDiscovery does not work for WordPress
The line of WordPress pages are not parsed correcty, I think.
It states:
<link rel="alternate" type="application/json+oembed" href="http://public-api.wordpress.com/oembed/1.0/?format=json&url=https%3A%2F%2Fsweetandweak.wordpress.com%2F2011%2F09%2F23%2Fnothing-starts-the-morning-like-a-good-dose-of-panic%2F&for=wpcom-auto-discovery"><link rel="alternate" type="application/xml+oembed" href="http://public-api.wordpress.com/oembed/1.0/?format=xml&url=https%3A%2F%2Fsweetandweak.wordpress.com%2F2011%2F09%2F23%2Fnothing-starts-the-morning-like-a-good-dose-of-panic%2F&for=wpcom-auto-discovery">
probably you just have to say
provider_endpoint ||= /<link.*href=['"]*([^\s'"]+)['"]*.*application\/json\+oembed.*>/.match(res.body)[0]
instead of
provider_endpoint ||= /<link.*href=['"]*([^\s'"]+)['"]*.*application\/json\+oembed.*>/.match(res.body)
in these lines: https://github.com/judofyr/ruby-oembed/blob/master/lib/oembed/provider_discovery.rb#L41
Oh, yes: If you need a page for testing this. It did not work for me for this page: https://sweetandweak.wordpress.com/2011/09/23/nothing-starts-the-morning-like-a-good-dose-of-panic/
After writing some tests for OEmbed::ProviderDiscovery I've discovered that this is (to some extent) WordPress's fault for not following the oEmbed specification. According to WordPress's API documentation their oEmbed endpoint requires a for parameter with each request. In its current state, OEmbed::ProviderDiscovery isn't intelligent enough to pass along extra parameters like for, and so WordPress returns an error.
All that to say, this is still an open issue, but at least it's an understood issue now and has some decent test coverage available once a fix is written.
ok, good to know. Thanks for ruby-oembed, btw!