OEmbedProviders (OEmbed Providers v0.1.0) View Source

Build OEmbed URLs with a list of providers.

Link to this section Summary

Functions

Get a list of available providers.

Construct the OEmbed endpoint URL for the given URL.

Link to this section Functions

Specs

find_provider(url :: String.t()) :: OEmbedProviders.Provider.t()

Get the OEmbedProviders.Provider for a URL.

iex(2)> OEmbedProviders.find_provider("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
%OEmbedProviders.Provider{
  endpoints: [
    %OEmbedProviders.Provider.Endpoint{
      discovery: true,
      formats: [],
      schemes: ["https://*.youtube.com/watch*", "https://*.youtube.com/v/*",
       "https://youtu.be/*"],
      url: "https://www.youtube.com/oembed"
    }
  ],
  provider_name: "YouTube",
  provider_url: "https://www.youtube.com/"
}

Specs

list_providers() :: [OEmbedProviders.Provider.t()]

Get a list of available providers.

iex(1)> OEmbedProviders.list_providers()
[
  %OEmbedProviders.Provider{
    endpoints: [
      %OEmbedProviders.Provider.Endpoint{
        discovery: nil,
        formats: [],
        schemes: ["http://www.23hq.com/*/photo/*"],
        url: "http://www.23hq.com/23/oembed"
      }
    ],
    provider_name: "23HQ",
    provider_url: "http://www.23hq.com"
  },
  %OEmbedProviders.Provider{...},
  %OEmbedProviders.Provider{...},
  %OEmbedProviders.Provider{...},
  ...
]

Specs

oembed_url(url :: String.t()) :: {:ok, String.t()} | {:error, any()}

Construct the OEmbed endpoint URL for the given URL.

iex(1)> OEmbedProviders.oembed_url("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
{:ok,
 "https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ"}
iex(2)> OEmbedProviders.oembed_url("https://gleasonator.com/@alex")
{:error, :no_provider}