oembed (on rails)

58
oEmbed on rails Kerstin Puschke Ruby Usergroup Hamburg January 2013 K. Puschke (Ruby Usergroup HH) oembed January 2013 1 / 17

Upload: kerstin-puschke

Post on 14-Jan-2015

1.088 views

Category:

Travel


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: oEmbed (on rails)

oEmbedon rails

Kerstin Puschke

Ruby Usergroup Hamburg

January 2013

K. Puschke (Ruby Usergroup HH) oembed January 2013 1 / 17

Page 2: oEmbed (on rails)

License

CC BY-SA 3.0Creative CommonsAttribution ShareAlike 3.0http://creativecommons.org/licenses/by-sa/3.0/

K. Puschke (Ruby Usergroup HH) oembed January 2013 2 / 17

Page 3: oEmbed (on rails)

Who am I

software engineer at XING

perl and rails@titanoboa42 on twittertitanoboa on githubtitanoboa on stackoverflow

K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17

Page 4: oEmbed (on rails)

Who am I

software engineer at XINGperl and rails

@titanoboa42 on twittertitanoboa on githubtitanoboa on stackoverflow

K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17

Page 5: oEmbed (on rails)

Who am I

software engineer at XINGperl and rails@titanoboa42 on twitter

titanoboa on githubtitanoboa on stackoverflow

K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17

Page 6: oEmbed (on rails)

Who am I

software engineer at XINGperl and rails@titanoboa42 on twittertitanoboa on github

titanoboa on stackoverflow

K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17

Page 7: oEmbed (on rails)

Who am I

software engineer at XINGperl and rails@titanoboa42 on twittertitanoboa on githubtitanoboa on stackoverflow

K. Puschke (Ruby Usergroup HH) oembed January 2013 3 / 17

Page 8: oEmbed (on rails)

third-party media embedding

Automated third-party media embeddingturn a url into an embedded representation of the resourcee.g. magically display embedded video instead of link

K. Puschke (Ruby Usergroup HH) oembed January 2013 4 / 17

Page 9: oEmbed (on rails)

third-party media embedding

screenscraping is a maintenance nightmare

provider specific APIs:additional effort for each additional provideroEmbed standardizes embedding

K. Puschke (Ruby Usergroup HH) oembed January 2013 5 / 17

Page 10: oEmbed (on rails)

third-party media embedding

screenscraping is a maintenance nightmareprovider specific APIs:additional effort for each additional provider

oEmbed standardizes embedding

K. Puschke (Ruby Usergroup HH) oembed January 2013 5 / 17

Page 11: oEmbed (on rails)

third-party media embedding

screenscraping is a maintenance nightmareprovider specific APIs:additional effort for each additional provideroEmbed standardizes embedding

K. Puschke (Ruby Usergroup HH) oembed January 2013 5 / 17

Page 12: oEmbed (on rails)

oEmbed

open embed format

open web standard for third-party media embeddingspecs published in 2008by Leah Culver (Pownce), Cal Henderson (Flickr), Mike Malone(Pownce), and Richard Crowley (OpenDNS)

K. Puschke (Ruby Usergroup HH) oembed January 2013 6 / 17

Page 13: oEmbed (on rails)

oEmbed

open embed formatopen web standard for third-party media embedding

specs published in 2008by Leah Culver (Pownce), Cal Henderson (Flickr), Mike Malone(Pownce), and Richard Crowley (OpenDNS)

K. Puschke (Ruby Usergroup HH) oembed January 2013 6 / 17

Page 14: oEmbed (on rails)

oEmbed

open embed formatopen web standard for third-party media embeddingspecs 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

Page 15: oEmbed (on rails)

oEmbed

open embed formatopen web standard for third-party media embeddingspecs published in 2008by Leah Culver (Pownce), Cal Henderson (Flickr), Mike Malone(Pownce), and Richard Crowley (OpenDNS)

K. Puschke (Ruby Usergroup HH) oembed January 2013 6 / 17

Page 16: oEmbed (on rails)

oEmbed providers

youtube

vimeoflickrtwitterslidesharespeakerdeckintermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 17: oEmbed (on rails)

oEmbed providers

youtubevimeo

flickrtwitterslidesharespeakerdeckintermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 18: oEmbed (on rails)

oEmbed providers

youtubevimeoflickr

twitterslidesharespeakerdeckintermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 19: oEmbed (on rails)

oEmbed providers

youtubevimeoflickrtwitter

slidesharespeakerdeckintermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 20: oEmbed (on rails)

oEmbed providers

youtubevimeoflickrtwitterslideshare

speakerdeckintermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 21: oEmbed (on rails)

oEmbed providers

youtubevimeoflickrtwitterslidesharespeakerdeck

intermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 22: oEmbed (on rails)

oEmbed providers

youtubevimeoflickrtwitterslidesharespeakerdeckintermediaries, e.g. embed.ly

K. Puschke (Ruby Usergroup HH) oembed January 2013 7 / 17

Page 23: oEmbed (on rails)

oEmbed consumers

drupal

wordpresselggdiasporaxing

K. Puschke (Ruby Usergroup HH) oembed January 2013 8 / 17

Page 24: oEmbed (on rails)

oEmbed consumers

drupalwordpress

elggdiasporaxing

K. Puschke (Ruby Usergroup HH) oembed January 2013 8 / 17

Page 25: oEmbed (on rails)

oEmbed consumers

drupalwordpresselgg

diasporaxing

K. Puschke (Ruby Usergroup HH) oembed January 2013 8 / 17

Page 26: oEmbed (on rails)

oEmbed consumers

drupalwordpresselggdiaspora

xing

K. Puschke (Ruby Usergroup HH) oembed January 2013 8 / 17

Page 27: oEmbed (on rails)

oEmbed consumers

drupalwordpresselggdiasporaxing

K. Puschke (Ruby Usergroup HH) oembed January 2013 8 / 17

Page 28: oEmbed (on rails)

oEmbed spec

http GET request to API endpoint with query param url

optional additional params: maxwidth, maxheight, formatresponse format xml or jsoninforms consumer how to embed, e.g. gives html snippet

K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17

Page 29: oEmbed (on rails)

oEmbed spec

http GET request to API endpoint with query param url

optional additional params: maxwidth, maxheight, format

response format xml or jsoninforms consumer how to embed, e.g. gives html snippet

K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17

Page 30: oEmbed (on rails)

oEmbed spec

http GET request to API endpoint with query param url

optional additional params: maxwidth, maxheight, formatresponse format xml or json

informs consumer how to embed, e.g. gives html snippet

K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17

Page 31: oEmbed (on rails)

oEmbed spec

http GET request to API endpoint with query param url

optional additional params: maxwidth, maxheight, formatresponse format xml or jsoninforms consumer how to embed, e.g. gives html snippet

K. Puschke (Ruby Usergroup HH) oembed January 2013 9 / 17

Page 32: oEmbed (on rails)

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

Page 33: oEmbed (on rails)

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

Page 34: oEmbed (on rails)

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

Page 35: oEmbed (on rails)

oEmbed gems

quite a few consumer gemsoembed-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

Page 36: oEmbed (on rails)

oEmbed gems

quite a few consumer gemsoembed-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

Page 37: oEmbed (on rails)

oembed-provider-engineturning your app into an oEmbed provider

mount OembedProviderEngine::Engine in routes.rbto 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::OembedProvidablecall oembed_providable_as with media type, e.g.oembed_providable_as :video

K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17

Page 38: oEmbed (on rails)

oembed-provider-engineturning your app into an oEmbed provider

mount OembedProviderEngine::Engine in routes.rbto provide route to API endpointyour media item’s model

needs a method for each field to be part of the oEmbed response,e.g.html, thumbnail_url,. . .include OembedProviderEngine::OembedProvidablecall oembed_providable_as with media type, e.g.oembed_providable_as :video

K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17

Page 39: oEmbed (on rails)

oembed-provider-engineturning your app into an oEmbed provider

mount OembedProviderEngine::Engine in routes.rbto provide route to API endpointyour media item’s model

needs a method for each field to be part of the oEmbed response,e.g.html, thumbnail_url,. . .

include OembedProviderEngine::OembedProvidablecall oembed_providable_as with media type, e.g.oembed_providable_as :video

K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17

Page 40: oEmbed (on rails)

oembed-provider-engineturning your app into an oEmbed provider

mount OembedProviderEngine::Engine in routes.rbto provide route to API endpointyour 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

Page 41: oEmbed (on rails)

oembed-provider-engineturning your app into an oEmbed provider

mount OembedProviderEngine::Engine in routes.rbto provide route to API endpointyour media item’s model

needs a method for each field to be part of the oEmbed response,e.g.html, thumbnail_url,. . .include OembedProviderEngine::OembedProvidablecall oembed_providable_as with media type, e.g.oembed_providable_as :video

K. Puschke (Ruby Usergroup HH) oembed January 2013 13 / 17

Page 42: oEmbed (on rails)

oembed-provider-engineinner workings

oembed_providable_as creates scoped OembedResponsemodel, e.g. MediaItem::OembedResponse

response model has attributes for each field to be included intothe responseits initializer sets attributes to the respective values from the app’smedia itemhas methods to format the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17

Page 43: oEmbed (on rails)

oembed-provider-engineinner workings

oembed_providable_as creates scoped OembedResponsemodel, e.g. MediaItem::OembedResponseresponse model has attributes for each field to be included intothe response

its initializer sets attributes to the respective values from the app’smedia itemhas methods to format the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17

Page 44: oEmbed (on rails)

oembed-provider-engineinner workings

oembed_providable_as creates scoped OembedResponsemodel, e.g. MediaItem::OembedResponseresponse model has attributes for each field to be included intothe responseits initializer sets attributes to the respective values from the app’smedia item

has methods to format the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17

Page 45: oEmbed (on rails)

oembed-provider-engineinner workings

oembed_providable_as creates scoped OembedResponsemodel, e.g. MediaItem::OembedResponseresponse model has attributes for each field to be included intothe responseits initializer sets attributes to the respective values from the app’smedia itemhas methods to format the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 14 / 17

Page 46: oEmbed (on rails)

oembed-provider-engineinner workings

API endpoint routes to engine’s controller

param url parsed to determine media item modelmedia item object initializedscoped response model created (if not already existing)response object initializedresponse formatted and returned

K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17

Page 47: oEmbed (on rails)

oembed-provider-engineinner workings

API endpoint routes to engine’s controllerparam url parsed to determine media item model

media item object initializedscoped response model created (if not already existing)response object initializedresponse formatted and returned

K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17

Page 48: oEmbed (on rails)

oembed-provider-engineinner workings

API endpoint routes to engine’s controllerparam url parsed to determine media item modelmedia item object initializedscoped response model created (if not already existing)

response object initializedresponse formatted and returned

K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17

Page 49: oEmbed (on rails)

oembed-provider-engineinner workings

API endpoint routes to engine’s controllerparam url parsed to determine media item modelmedia item object initializedscoped response model created (if not already existing)response object initialized

response formatted and returned

K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17

Page 50: oEmbed (on rails)

oembed-provider-engineinner workings

API endpoint routes to engine’s controllerparam url parsed to determine media item modelmedia item object initializedscoped response model created (if not already existing)response object initializedresponse formatted and returned

K. Puschke (Ruby Usergroup HH) oembed January 2013 15 / 17

Page 51: oEmbed (on rails)

oembed-provider-enginetodo

still very rails 2-ish :-( needs polishing

proper handling of authorizationcachingimprove test coverage, maybe migrate from shoulda to rspecallow for custom fields to be added to the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17

Page 52: oEmbed (on rails)

oembed-provider-enginetodo

still very rails 2-ish :-( needs polishingproper handling of authorization

cachingimprove test coverage, maybe migrate from shoulda to rspecallow for custom fields to be added to the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17

Page 53: oEmbed (on rails)

oembed-provider-enginetodo

still very rails 2-ish :-( needs polishingproper handling of authorizationcaching

improve test coverage, maybe migrate from shoulda to rspecallow for custom fields to be added to the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17

Page 54: oEmbed (on rails)

oembed-provider-enginetodo

still very rails 2-ish :-( needs polishingproper handling of authorizationcachingimprove 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

Page 55: oEmbed (on rails)

oembed-provider-enginetodo

still very rails 2-ish :-( needs polishingproper handling of authorizationcachingimprove test coverage, maybe migrate from shoulda to rspecallow for custom fields to be added to the response

K. Puschke (Ruby Usergroup HH) oembed January 2013 16 / 17

Page 56: oEmbed (on rails)

Feedback & Co

Questions, comments,. . .twitter: @titanoboa42

email: [email protected]: https://github.com/xing/oembed_provider_engine. . . we are happy to accept pull requests

K. Puschke (Ruby Usergroup HH) oembed January 2013 17 / 17

Page 57: oEmbed (on rails)

Feedback & Co

Questions, comments,. . .twitter: @titanoboa42email: [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

Page 58: oEmbed (on rails)

Feedback & Co

Questions, comments,. . .twitter: @titanoboa42email: [email protected]: https://github.com/xing/oembed_provider_engine. . . we are happy to accept pull requests

K. Puschke (Ruby Usergroup HH) oembed January 2013 17 / 17