Class: OEmbed::Providers

Inherits:
Object
  • Object
show all
Defined in:
lib/oembed/providers.rb,
lib/oembed/providers/tiktok.rb,
lib/oembed/providers/spotify.rb,
lib/oembed/providers/instagram.rb,
lib/oembed/providers/matterport.rb,
lib/oembed/providers/facebook_post.rb,
lib/oembed/providers/facebook_video.rb,
lib/oembed/providers/builtin_providers.rb

Overview

Allows OEmbed to perform tasks across several, registered, Providers at once.

Constant Summary collapse

TikTok =

Provider for tiktok.com See developers.tiktok.com/doc/embed-videos

OEmbed::Provider.new(
  "https://www.tiktok.com/oembed",
  format: :json
)
Spotify =
OEmbed::Provider.new(
  "https://open.spotify.com/oembed",
  format: :json
)
Instagram =

Provider for instagram.com See developers.facebook.com/docs/instagram/oembed/

OEmbed::Provider.new(
  "https://graph.facebook.com/v8.0/instagram_oembed",
  required_query_params: { access_token: 'OEMBED_FACEBOOK_TOKEN' },
  format: :json
)
Matterport =

Provider for my.matterport.com

OEmbed::Provider.new(
  "https://my.matterport.com/api/v1/models/oembed/",
  format: :json
)
FacebookPost =
OEmbed::Provider.new(
  "https://graph.facebook.com/v8.0/oembed_post",
  required_query_params: { access_token: 'OEMBED_FACEBOOK_TOKEN' },
  format: :json
)
FacebookVideo =
OEmbed::Provider.new(
  "https://graph.facebook.com/v8.0/oembed_video",
  required_query_params: { access_token: 'OEMBED_FACEBOOK_TOKEN' },
  format: :json
)
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("https://www.youtube.com/oembed/?scheme=https")
CodePen =

Provider for codepen.io

OEmbed::Provider.new("https://codepen.io/api/oembed")
Flickr =

Provider for flickr.com

OEmbed::Provider.new("https://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("https://www.hulu.com/api/oembed.{format}")
Vimeo =

Provider for vimeo.com developer.vimeo.com/apis/oembed

OEmbed::Provider.new("https://vimeo.com/api/oembed.{format}")
Twitter =
OEmbed::Provider.new("https://publish.twitter.com/oembed", format: :json)
Vine =

Provider for vine.co dev.twitter.com/web/vine/oembed

OEmbed::Provider.new("https://vine.co/oembed.{format}")
Slideshare =

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

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

Provider for Giphy

OEmbed::Provider.new("http://giphy.com/services/oembed")
Imgur =

Provider for imgur.com

OEmbed::Provider.new("https://api.imgur.com/oembed.{format}")
Kickstarter =

Provider for Kickstarter

OEmbed::Provider.new("https://www.kickstarter.com/services/oembed")
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", format: :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("https://www.scribd.com/services/oembed")
SpeakerDeck =

Provider for speakerdeck.com speakerdeck.com/faq#oembed

OEmbed::Provider.new("https://speakerdeck.com/oembed.json")
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("https://soundcloud.com/oembed", format: :json)
Skitch =

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

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

Provider for TED

OEmbed::Provider.new("https://www.ted.com/talks/oembed.{format}")
Tumblr =

Provider for tumblr.com

OEmbed::Provider.new("http://www.tumblr.com/oembed/1.0/", format: :json)
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/", format: :json)
Noembed =

Provider for noembed.com, which is a provider aggregator. See OEmbed::Providers::Noembed.urls for a full list of supported url schemas. noembed.com/#supported-sites

OEmbed::Provider.new("https://noembed.com/embed")
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 =
{}
@@access_token_setters =
{}

Class Method Summary collapse

Class Method Details

.fallbackObject

Returns an array of all registerd fallback Provider instances.



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

def fallback
  @@fallback
end

.find(url) ⇒ Object

Returns a Provider instance whose url scheme matches the given url. Skips any Provider with missing required_query_params.



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

def find(url)
  @@urls.keys.each do |url_regexp|
    next unless url_regexp.match?(url)

    matching_provider = @@urls[url_regexp].detect { |p| p.include?(url) }

    # If we've found a matching provider, return it right away!
    return matching_provider if matching_provider
  end

  nil
end

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

Finds the appropriate Provider for this url and returns an OEmbed::Response, using Provider#get.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/oembed/providers.rb', line 112

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.



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

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.



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

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, access_tokens: {}) ⇒ 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

The access_tokens keys can be one of the following:



50
51
52
53
54
55
56
# File 'lib/oembed/providers.rb', line 50

def register_all(*including_sub_type, access_tokens: {})
  register(*@@to_register[""])
  including_sub_type.each do |sub_type|
    register(*@@to_register[sub_type.to_s])
  end
  set_access_tokens(access_tokens)
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::Noembed)


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

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.



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

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.



59
60
61
62
# File 'lib/oembed/providers.rb', line 59

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.



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

def urls
  @@urls
end