oembed

package
v0.0.0-...-f95c180 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	URL       string   `json:"url"`
	Discovery bool     `json:"discovery,omitempty"`
	Schemes   []string `json:"schemes,omitempty"`
}

Endpoint contains single endpoint to check against

type Info

type Info struct {
	Status          int    `json:"-"`
	Type            string `json:"type,omitempty"`
	CacheAge        uint64 `json:"cache_age,omitempty"`
	URL             string `json:"url,omitempty"`
	ProviderURL     string `json:"provider_url,omitempty"`
	ProviderName    string `json:"provider_name,omitempty"`
	Title           string `json:"title,omitempty"`
	Description     string `json:"description,omitempty"`
	Width           uint64 `json:"width,omitempty"`
	Height          uint64 `json:"height,omitempty"`
	ThumbnailURL    string `json:"thumbnail_url,omitempty"`
	ThumbnailWidth  uint64 `json:"thumbnail_width,omitempty"`
	ThumbnailHeight uint64 `json:"thumbnail_height,omitempty"`
	AuthorName      string `json:"author_name,omitempty"`
	AuthorURL       string `json:"author_url,omitempty"`
	HTML            string `json:"html,omitempty"`
}

Info returns information for embedding website

func NewInfo

func NewInfo() *Info

NewInfo creater new instance of oembed.Info

func (*Info) FillFromJSON

func (info *Info) FillFromJSON(r io.Reader) error

FillFromJSON fills the structure from provided Oembed JSON

func (*Info) MergeWith

func (info *Info) MergeWith(base *Info)

MergeWith adds missing data to the structure from another oembed.Info structure

func (*Info) String

func (info *Info) String() string

String return json representation of structure, or error string

func (*Info) ToJSON

func (info *Info) ToJSON() ([]byte, error)

ToJSON a simple wrapper around json.Marshal

type Item

type Item struct {
	IsEndpointURLComplete bool
	EndpointURL           string
	ProviderName          string
	ProviderURL           string
	// contains filtered or unexported fields
}

Item contains data for a schema

func (*Item) ComposeURL

func (item *Item) ComposeURL(u string) string

ComposeURL returns url of oembed resource ready to be queried

func (*Item) FetchOembed

func (item *Item) FetchOembed(opts Options) (*Info, error)

FetchOembed return oembed info from an url containing it

func (*Item) MatchURL

func (item *Item) MatchURL(url string) bool

MatchURL tests if given url applies to the endpoint

type Oembed

type Oembed struct {
	// contains filtered or unexported fields
}

Oembed contains list of available oembed items (official endpoints)

func NewOembed

func NewOembed() *Oembed

NewOembed creates Oembed instance

func (*Oembed) FindItem

func (o *Oembed) FindItem(url string) *Item

FindItem returns Oembed item based on provided url

func (*Oembed) ParseProviders

func (o *Oembed) ParseProviders(buf io.Reader) error

ParseProviders build oembed endpoint list based on provided json stream

type Options

type Options struct {
	Client         *http.Client
	URL            string
	MaxWidth       int
	MaxHeight      int
	AcceptLanguage string
	ExtraOpts      map[string]string
}

Options contains options to pass to FetchOembed method

type Provider

type Provider struct {
	Name      string     `json:"provider_name"`
	URL       string     `json:"provider_url"`
	Endpoints []Endpoint `json:"endpoints"`
}

Provider contains a single provider which can have multiple endpoints

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL