Class: OEmbed::Providers
- Inherits:
-
Object
- Object
- OEmbed::Providers
- Defined in:
- lib/oembed/providers.rb
Overview
Allows OEmbed to perform tasks across several, registered, Providers at once.
Constant Summary collapse
- Youtube =
Provider for youtube.com apiblog.youtube.com/2009/10/oembed-support.html To get the iframe embed code, instead of flash-based, pass :flash=>1 as a query in your get request.
OEmbed::Provider.new("http://www.youtube.com/oembed")
- Flickr =
Provider for flickr.com developer.yahoo.com/blogs/ydn/posts/2008/05/oembed_embeddin/
OEmbed::Provider.new("http://www.flickr.com/services/oembed/")
- Viddler =
Provider for viddler.com developers.viddler.com/documentation/services/oembed/
OEmbed::Provider.new("http://lab.viddler.com/services/oembed/")
- Qik =
Provider for qik.com qik.com/blog/qik-embraces-oembed-for-embedding-videos/
OEmbed::Provider.new("http://qik.com/api/oembed.{format}")
- Revision3 =
Provider for revision3.com
OEmbed::Provider.new("http://revision3.com/api/oembed/")
- Hulu =
Provider for hulu.com
OEmbed::Provider.new("http://www.hulu.com/api/oembed.{format}")
- Vimeo =
Provider for vimeo.com vimeo.com/api/docs/oEmbed
OEmbed::Provider.new("http://www.vimeo.com/api/oembed.{format}")
- Instagram =
Provider for instagram.com instagr.am/developer/embedding/
OEmbed::Provider.new("http://api.instagram.com/oembed", :json)
OEmbed::Provider.new("http://www.slideshare.net/api/oembed/2")
- Yfrog =
Provider for yfrog code.google.com/p/imageshackapi/wiki/OEMBEDSupport
OEmbed::Provider.new("http://www.yfrog.com/api/oembed", :json)
- OohEmbed =
Provider for oohembed.com, which is a provider agregator. See OEmbed::Providers::OohEmbed.urls for a full list of supported url schemas. Embed.ly has taken over the oohembed.com domain and as of July 20 all oohEmbed request will require you use an API key. For details on the transition see blog.embed.ly/oohembed
OEmbed::Provider.new("http://oohembed.com/oohembed/", :json)
- Embedly =
Provider for Embedly.com, which is a provider agregator. See OEmbed::Providers::Embedly.urls for a full list of supported url schemas. embed.ly/docs/endpoints/1/oembed You’ll need to add your Embed.ly API key to each request as the “key” parameter. To get an API key you’ll need to sign up here: embed.ly/pricing
OEmbed::Provider.new("http://api.embed.ly/1/oembed")
- PollEverywhere =
Provider for polleverywhere.com
OEmbed::Provider.new("http://www.polleverywhere.com/services/oembed/")
- MyOpera =
Provider for my.opera.com my.opera.com/devblog/blog/2008/12/02/embedding-my-opera-content-oembed
OEmbed::Provider.new("http://my.opera.com/service/oembed", :json)
- ClearspringWidgets =
Provider for clearspring.com
OEmbed::Provider.new("http://widgets.clearspring.com/widget/v1/oembed/")
- NFBCanada =
Provider for nfb.ca
OEmbed::Provider.new("http://www.nfb.ca/remote/services/oembed/")
- Scribd =
Provider for scribd.com
OEmbed::Provider.new("http://www.scribd.com/services/oembed")
- MovieClips =
Provider for movieclips.com
OEmbed::Provider.new("http://movieclips.com/services/oembed/")
- TwentyThree =
Provider for 23hq.com
OEmbed::Provider.new("http://www.23hq.com/23/oembed")
- @@urls =
{}
- @@fallback =
[]
Class Method Summary collapse
-
.fallback ⇒ Object
Returns an array of all registerd fallback Provider instances.
-
.find(url) ⇒ Object
Returns a Provider instance who’s url scheme matches the given url.
-
.get(url, options = {}) ⇒ Object
Finds the appropriate Provider for this url and returns an OEmbed::Response, using Provider#get.
-
.raw(url, options = {}) ⇒ Object
deprecated
Deprecated.
Note: This method will be made private in the future.
-
.register(*providers) ⇒ Object
Given one ore more Provider instances, register their url schemes for future get calls.
-
.register_all ⇒ Object
Register a standard set of common Provider instances, including: * Flickr * Hulu * Qik * Revision3 * Viddler * Vimeo * Youtube.
-
.register_fallback(*providers) ⇒ Object
Takes an array of Provider instances or ProviderDiscovery Use this method to register fallback providers.
-
.unregister(*providers) ⇒ Object
Given one ore more Provider instances, un-register their url schemes.
-
.unregister_all ⇒ Object
Unregister all currently-registered Provider instances.
-
.urls ⇒ Object
A Hash of all url schemes, where the keys represent schemes supported by all registered Provider instances and values are an Array of Providers that support that scheme.
Class Method Details
.fallback ⇒ Object
Returns an array of all registerd fallback Provider instances.
74 75 76 |
# File 'lib/oembed/providers.rb', line 74 def fallback @@fallback end |
.find(url) ⇒ Object
Returns a Provider instance who’s url scheme matches the given url.
79 80 81 82 |
# File 'lib/oembed/providers.rb', line 79 def find(url) providers = @@urls[@@urls.keys.detect { |u| u =~ url }] Array(providers).first || nil end |
.get(url, options = {}) ⇒ Object
Finds the appropriate Provider for this url and returns an OEmbed::Response, using Provider#get.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/oembed/providers.rb', line 100 def get(url, = {}) provider = find(url) if provider provider.get(url, ) else fallback.each do |p| return p.get(url, ) rescue OEmbed::Error end raise(OEmbed::NotFound) end end |
.raw(url, options = {}) ⇒ Object
Note: This method will be made private in the future.
Finds the appropriate Provider for this url and return the raw response.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/oembed/providers.rb', line 86 def raw(url, = {}) provider = find(url) if provider provider.raw(url, ) else fallback.each do |p| return p.raw(url, ) rescue OEmbed::Error end raise(OEmbed::NotFound) end end |
.register(*providers) ⇒ Object
Given one ore more Provider instances, register their url schemes for future get calls.
21 22 23 24 25 26 27 28 |
# File 'lib/oembed/providers.rb', line 21 def register(*providers) providers.each do |provider| provider.urls.each do |url| @@urls[url] ||= [] @@urls[url] << provider end end end |
.register_all ⇒ Object
Register a standard set of common Provider instances, including:
-
Flickr
-
Hulu
-
Qik
-
Revision3
-
Viddler
-
Vimeo
-
Youtube
51 52 53 |
# File 'lib/oembed/providers.rb', line 51 def register_all register(Youtube, Flickr, Viddler, Qik, Revision3, Hulu, Vimeo) end |
.register_fallback(*providers) ⇒ Object
Takes an array of Provider instances or ProviderDiscovery Use this method to register fallback providers. When the raw or get methods are called, if the URL doesn’t match any of the registerd url patters the fallback providers will be called (in order) with the URL.
A common example:
OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery, OEmbed::Providers::OohEmbed)
69 70 71 |
# File 'lib/oembed/providers.rb', line 69 def register_fallback(*providers) @@fallback += providers end |
.unregister(*providers) ⇒ Object
Given one ore more Provider instances, un-register their url schemes. Future get calls will not use these Providers.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/oembed/providers.rb', line 32 def unregister(*providers) providers.each do |provider| provider.urls.each do |url| if @@urls[url].is_a?(Array) @@urls[url].delete(provider) @@urls.delete(url) if @@urls[url].empty? end end end end |
.unregister_all ⇒ Object
Unregister all currently-registered Provider instances.
56 57 58 59 |
# File 'lib/oembed/providers.rb', line 56 def unregister_all @@urls = {} @@fallback = [] end |
.urls ⇒ Object
A Hash of all url schemes, where the keys represent schemes supported by all registered Provider instances and values are an Array of Providers that support that scheme.
15 16 17 |
# File 'lib/oembed/providers.rb', line 15 def urls @@urls end |