Documentation ¶
Overview ¶
Package oembed implements functions to discover oEmbed providers for given URL and parse providers' response.
Index ¶
Constants ¶
const ( TypePhoto Type = "photo" TypeVideo = "video" TypeLink = "link" TypeRich = "rich" )
Predefined oEmbed types (http://oembed.com 2.3.4.1-2.3.4.4):
Variables ¶
This section is empty.
Functions ¶
func Discover ¶
Discover parses htmlBodyReader as utf-8 encoded html text and tries to discover oEmbed endpoint as described in http://oembed.com/#section4
Use NewReader from golang.org/x/net/html/charset to ensure data is properly encoded.
Types ¶
type LookupFunc ¶
LookupFunc checks whether provided url matches any known oEmbed provider and returns url of oEmbed endpoint that should return metadata about original url.
func Providers ¶
func Providers(r io.Reader) (LookupFunc, error)
Providers decodes r as content of http://oembed.com/providers.json and returns LookupFunc matching url against providers list.
type Metadata ¶
type Metadata struct { Type Type // resource type Provider string // provider name Title string // resource title AuthorName string // name of the author/owner AuthorURL string // URL for the author/owner of the resource Thumbnail string // URL of the thumbnail image ThumbnailWidth int // width of the optional thumbnail ThumbnailHeight int // height of the optional thumbnail // HTML snippet required to display the embedded resource — as returned // by provider, may be unsafe. Set for video and rich types. HTML string URL string // source URL of the original image, set for photo types Width, Height int // width/height in pixels of the image/snippet specified by the URL/HTML }
Metadata describes resource as returned by oEmbed provider (http://oembed.com, section 2.3.4)
func FromJSON ¶
FromJSON decodes json-encoded oEmbed metadata read from r. It ensures that result contains only valid http/https urls and metadata satisfies one of the predefined types.
func FromResponse ¶
FromResponse verifies status code of r, and calls FromJSON or FromXML depending on Content-Type of r. Only responses with status code 200 and Content-Type of either application/json or text/xml are allowed, otherwise error is returned.