Class: OEmbed::Providers

Inherits:
Object
  • Object
show all
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

Options:

  • To get the iframe embed code

    OEmbed::Providers::Youtube.endpoint += "?iframe=1"
    
  • To get the flash/object embed code

    OEmbed::Providers::Youtube.endpoint += "?iframe=0"
    
  • To require https embed code

    OEmbed::Providers::Youtube.endpoint += "?scheme=https"
    
OEmbed::Provider.new("http://www.youtube.com/oembed")
Flickr =
OEmbed::Provider.new("http://www.flickr.com/services/oembed/")
Viddler =
OEmbed::Provider.new("http://lab.viddler.com/services/oembed/")
Qik =
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 developer.vimeo.com/apis/oembed

OEmbed::Provider.new("http://vimeo.com/api/oembed.{format}")
Instagram =

Provider for instagram.com instagr.am/developer/embedding/

OEmbed::Provider.new("http://api.instagram.com/oembed", :json)
Slideshare =

Provider for slideshare.net www.slideshare.net/developers/oembed

OEmbed::Provider.new("http://www.slideshare.net/api/oembed/2")
Yfrog =
OEmbed::Provider.new("http://www.yfrog.com/api/oembed", :json)
MlgTv =

provider for mlg-tv tv.majorleaguegaming.com/oembed

OEmbed::Provider.new("http://tv.majorleaguegaming.com/oembed")
PollEverywhere =

Provider for polleverywhere.com

OEmbed::Provider.new("http://www.polleverywhere.com/services/oembed/")
MyOpera =
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")
SoundCloud =

Provider for soundcloud.com developers.soundcloud.com/docs/oembed

OEmbed::Provider.new("http://soundcloud.com/oembed", :json)
Spotify =
OEmbed::Provider.new("https://embed.spotify.com/oembed/")
Skitch =

Provider for skitch.com skitch.com/oembed/%3C/endpoint

OEmbed::Provider.new("http://skitch.com/oembed")
OohEmbed =

Provider for oohembed.com, which is a provider aggregator. 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 aggregator. See OEmbed::Providers::Embedly.urls for a full list of supported url schemas. embed.ly/docs/endpoints/1/oembed

You can append your Embed.ly API key to the provider so that all requests are signed

OEmbed::Providers::Embedly.endpoint += "?key=#{my_embedly_key}"

If you don’t yet have an API key you’ll need to sign up here: embed.ly/pricing

OEmbed::Provider.new("http://api.embed.ly/1/oembed")
@@urls =
{}
@@fallback =
[]
@@to_register =
{}

Class Method Summary collapse

Class Method Details

.fallbackObject

Returns an array of all registerd fallback Provider instances.



73
74
75
# File 'lib/oembed/providers.rb', line 73

def fallback
  @@fallback
end

.find(url) ⇒ Object

Returns a Provider instance who’s url scheme matches the given url.



78
79
80
81
# File 'lib/oembed/providers.rb', line 78

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.



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/oembed/providers.rb', line 99

def get(url, options = {})
  provider = find(url)
  if provider
    provider.get(url, options)
  else
    fallback.each do |p|
      return p.get(url, options) rescue OEmbed::Error
    end
    raise(OEmbed::NotFound)
  end
end

.raw(url, options = {}) ⇒ Object

Deprecated.

Note: This method will be made private in the future.

Finds the appropriate Provider for this url and return the raw response.



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/oembed/providers.rb', line 85

def raw(url, options = {})
  provider = find(url)
  if provider
    provider.raw(url, options)
  else
    fallback.each do |p|
      return p.raw(url, options) 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.



22
23
24
25
26
27
28
29
# File 'lib/oembed/providers.rb', line 22

def register(*providers)
  providers.each do |provider|
    provider.urls.each do |url|
      @@urls[url] ||= []
      @@urls[url] << provider
    end
  end
end

.register_all(*including_sub_type) ⇒ Object

Register all Providers built into this gem. The including_sub_type parameter should be one of the following values:

  • :aggregators: also register provider aggregator endpoints, like Embedly



47
48
49
50
51
52
# File 'lib/oembed/providers.rb', line 47

def register_all(*including_sub_type)
  register(*@@to_register[""])
  including_sub_type.each do |sub_type|
    register(*@@to_register[sub_type.to_s])
  end
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)


68
69
70
# File 'lib/oembed/providers.rb', line 68

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.



33
34
35
36
37
38
39
40
41
42
# File 'lib/oembed/providers.rb', line 33

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_allObject

Unregister all currently-registered Provider instances.



55
56
57
58
# File 'lib/oembed/providers.rb', line 55

def unregister_all
  @@urls = {}
  @@fallback = []
end

.urlsObject

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.



16
17
18
# File 'lib/oembed/providers.rb', line 16

def urls
  @@urls
end