Upgrade to Pro — share decks privately, control downloads, hide ads and more …

oEmbed (on rails)

oEmbed (on rails)

short introductory talk about oembed and how to turn a rails app into an oembed provider. ruby usergroup hamurg, January 2013

Kerstin Puschke

January 09, 2013
Tweet

More Decks by Kerstin Puschke

Other Decks in Programming

Transcript

  1. oEmbed on rails Kerstin Puschke Ruby Usergroup Hamburg January 2013

    K. Puschke (Ruby Usergroup HH) oembed January 2013 1 / 17
  2. Who am I software engineer at XING K. Puschke (Ruby

    Usergroup HH) oembed January 2013 3 / 17
  3. Who am I software engineer at XING perl and rails

    K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17
  4. Who am I software engineer at XING perl and rails

    @titanoboa42 on twitter K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17
  5. Who am I software engineer at XING perl and rails

    @titanoboa42 on twitter titanoboa on github K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17
  6. Who am I software engineer at XING perl and rails

    @titanoboa42 on twitter titanoboa on github titanoboa on stackoverflow K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17
  7. third-party media embedding Automated third-party media embedding turn a url

    into an embedded representation of the resource e.g. magically display embedded video instead of link K. Puschke (Ruby Usergroup HH) oembed January 2013 4 / 17
  8. third-party media embedding screenscraping is a maintenance nightmare provider specific

    APIs: additional effort for each additional provider K. Puschke (Ruby Usergroup HH) oembed January 2013 5 / 17
  9. third-party media embedding screenscraping is a maintenance nightmare provider specific

    APIs: additional effort for each additional provider oEmbed standardizes embedding K. Puschke (Ruby Usergroup HH) oembed January 2013 5 / 17
  10. oEmbed open embed format open web standard for third-party media

    embedding K. Puschke (Ruby Usergroup HH) oembed January 2013 6 / 17
  11. oEmbed open embed format open web standard for third-party media

    embedding specs published in 2008 K. Puschke (Ruby Usergroup HH) oembed January 2013 6 / 17
  12. oEmbed open embed format open web standard for third-party media

    embedding specs published in 2008 by Leah Culver (Pownce), Cal Henderson (Flickr), Mike Malone (Pownce), and Richard Crowley (OpenDNS) K. Puschke (Ruby Usergroup HH) oembed January 2013 6 / 17
  13. oEmbed providers youtube vimeo flickr twitter slideshare speakerdeck intermediaries, e.g.

    embed.ly K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17
  14. oEmbed spec http GET request to API endpoint with query

    param url K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17
  15. oEmbed spec http GET request to API endpoint with query

    param url optional additional params: maxwidth, maxheight, format K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17
  16. oEmbed spec http GET request to API endpoint with query

    param url optional additional params: maxwidth, maxheight, format response format xml or json K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17
  17. oEmbed spec http GET request to API endpoint with query

    param url optional additional params: maxwidth, maxheight, format response format xml or json informs consumer how to embed, e.g. gives html snippet K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17
  18. Example: video http://www.youtube.com /oembed?url=http://www.youtube.com/watch?v=zwk1KvnZxGw { "author_name": "XINGcom", "html": "<iframe width=\"480\"

    height=\"270\" src= "version": "1.0", "author_url": "http://www.youtube.com/user/XING... "thumbnail_width": 480, "height": 270, "provider_url": "http://www.youtube.com/", "type": "video", "width": 480, "thumbnail_height": 360, "thumbnail_url": "http://i3.ytimg.com/vi/... "provider_name": "YouTube", "title": "Was ist XING?" } K. Puschke (Ruby Usergroup HH) oembed January 2013 10 / 17
  19. Example response: photo { "type": "photo", "title": "Ba... "author_name": "...

    "author_url": "http://www.flickr.com/photos/... "width": "1024", "height": "768", "url": "http://farm4.staticflickr.com/3040/2362... "web_page": "http://www.flickr.com/photos/be... "thumbnail_url": "http://farm4.staticfli... "thumbnail_width": 75, "thumbnail_height": 75, "web_page_short_url": "http://flic.kr/p/4... "license": "All Rights Reserved", "version": "1.0", "cache_age": 3600, "provider_name": "Flickr", K. Puschke (Ruby Usergroup HH) oembed January 2013 11 / 17
  20. oEmbed gems quite a few consumer gems K. Puschke (Ruby

    Usergroup HH) oembed January 2013 12 / 17
  21. oEmbed gems quite a few consumer gems oembed-provider (rails 2

    only) K. Puschke (Ruby Usergroup HH) oembed January 2013 12 / 17
  22. oEmbed gems quite a few consumer gems oembed-provider (rails 2

    only) oembed-provider-engine (rails 3 only) mountable rails 3 engine, heavily based on oembed-provider K. Puschke (Ruby Usergroup HH) oembed January 2013 12 / 17
  23. oembed-provider-engine turning your app into an oEmbed provider mount OembedProviderEngine::Engine

    in routes.rb to provide route to API endpoint K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17
  24. oembed-provider-engine turning your app into an oEmbed provider mount OembedProviderEngine::Engine

    in routes.rb to provide route to API endpoint your media item’s model K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17
  25. oembed-provider-engine turning your app into an oEmbed provider mount OembedProviderEngine::Engine

    in routes.rb to provide route to API endpoint your media item’s model needs a method for each field to be part of the oEmbed response, e.g. html, thumbnail_url,. . . K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17
  26. oembed-provider-engine turning your app into an oEmbed provider mount OembedProviderEngine::Engine

    in routes.rb to provide route to API endpoint your media item’s model needs a method for each field to be part of the oEmbed response, e.g. html, thumbnail_url,. . . include OembedProviderEngine::OembedProvidable K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17
  27. oembed-provider-engine turning your app into an oEmbed provider mount OembedProviderEngine::Engine

    in routes.rb to provide route to API endpoint your media item’s model needs a method for each field to be part of the oEmbed response, e.g. html, thumbnail_url,. . . include OembedProviderEngine::OembedProvidable call oembed_providable_as with media type, e.g. oembed_providable_as :video K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17
  28. oembed-provider-engine inner workings oembed_providable_as creates scoped OembedResponse model, e.g. MediaItem::OembedResponse

    response model has attributes for each field to be included into the response K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17
  29. oembed-provider-engine inner workings oembed_providable_as creates scoped OembedResponse model, e.g. MediaItem::OembedResponse

    response model has attributes for each field to be included into the response its initializer sets attributes to the respective values from the app’s media item K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17
  30. oembed-provider-engine inner workings oembed_providable_as creates scoped OembedResponse model, e.g. MediaItem::OembedResponse

    response model has attributes for each field to be included into the response its initializer sets attributes to the respective values from the app’s media item has methods to format the response K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17
  31. oembed-provider-engine inner workings API endpoint routes to engine’s controller K.

    Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17
  32. oembed-provider-engine inner workings API endpoint routes to engine’s controller param

    url parsed to determine media item model K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17
  33. oembed-provider-engine inner workings API endpoint routes to engine’s controller param

    url parsed to determine media item model media item object initialized scoped response model created (if not already existing) K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17
  34. oembed-provider-engine inner workings API endpoint routes to engine’s controller param

    url parsed to determine media item model media item object initialized scoped response model created (if not already existing) response object initialized K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17
  35. oembed-provider-engine inner workings API endpoint routes to engine’s controller param

    url parsed to determine media item model media item object initialized scoped response model created (if not already existing) response object initialized response formatted and returned K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17
  36. oembed-provider-engine todo still very rails 2-ish :-( needs polishing K.

    Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17
  37. oembed-provider-engine todo still very rails 2-ish :-( needs polishing proper

    handling of authorization K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17
  38. oembed-provider-engine todo still very rails 2-ish :-( needs polishing proper

    handling of authorization caching K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17
  39. oembed-provider-engine todo still very rails 2-ish :-( needs polishing proper

    handling of authorization caching improve test coverage, maybe migrate from shoulda to rspec K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17
  40. oembed-provider-engine todo still very rails 2-ish :-( needs polishing proper

    handling of authorization caching improve test coverage, maybe migrate from shoulda to rspec allow for custom fields to be added to the response K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17
  41. Feedback & Co Questions, comments,. . . twitter: @titanoboa42 K.

    Puschke (Ruby Usergroup HH) oembed January 2013 17 / 17
  42. Feedback & Co Questions, comments,. . . twitter: @titanoboa42 email:

    [email protected] K. Puschke (Ruby Usergroup HH) oembed January 2013 17 / 17
  43. Feedback & Co Questions, comments,. . . twitter: @titanoboa42 email:

    [email protected] github: https://github.com/xing/oembed_provider_engine . . . we are happy to accept pull requests K. Puschke (Ruby Usergroup HH) oembed January 2013 17 / 17