Home Reference Source Test Repository
import OEmbedProvider from 'url-embed/lib/classes/OEmbedProvider.js'
public interface | source

OEmbedProvider

Extends:

lib/classes/EmbedEngine.js~URLEmbedProvider → OEmbedProvider

Converts a pattern of URLs into markup via an oembed provider

See:

Test:

Constructor Summary

Public Constructor
public

constructor(providerURL: String, urlPatterns: Array<RegExp>, format: String)

Member Summary

Public Members
public

format: *

public
public
public

The version number of the url-embed module

Method Summary

Public Methods
public

Builds the API URL string

public

Builds the HTTP request options (headers, etc.)

public

configure(configOptions: Object)

Configures the provider

public

Converts high-bit-value escaped unicode code points to unicode surrogate pair code points.

public

getEmbed(embed: Embed, callback: function(embed: Embed))

Resolves options.embedURL to an embed and passes it to callback.

public

makeAPIRequest(embed: Embed, callback: function(embed: Ebmed))

Makes the requests to the oembed provider's API

public

parseResponseBody(body: String, callback: function(error: Error, data: Object))

Parses the provider API response into a data object

Public Constructors

public constructor(providerURL: String, urlPatterns: Array<RegExp>, format: String) source

Params:

NameTypeAttributeDescription
providerURL String

the URL of the provider's oembed service

urlPatterns Array<RegExp>

array of regular expressions that this provider will match

format String

the data format of the provider's oembed service. Must be either 'json' or 'xml'.

Test:

Public Members

public format: * source

public providerURL: * source

public timeoutMs: * source

public version: String source

The version number of the url-embed module

Public Methods

public buildAPIURL(embed: Embed): String source

Builds the API URL string

Params:

NameTypeAttributeDescription
embed Embed

Embed object

Return:

String

API URL

Test:

public buildRequestOptions(embed: Embed): Object source

Builds the HTTP request options (headers, etc.)

Params:

NameTypeAttributeDescription
embed Embed

Embed object

Return:

Object

request options

See:

public configure(configOptions: Object) source

Configures the provider

Params:

NameTypeAttributeDescription
configOptions Object
configOptions.timeoutMs number

Request timeout in milliseconds.

public convertHighBitUnicodeToSurrogates(body: String): String source

Converts high-bit-value escaped unicode code points to unicode surrogate pair code points.

JSON.parse yields a parse error when it encounters unicode literals > 16-bits. Notably, many newer emojis fall into this category.

To solve for this you need to split the > 16-bit unicode escapedcode point into surrogate pairs.

Great and entertaining explaination here: https://gist.github.com/mranney/1707371

Algorithm for calculating surrogate pairs cribbed from here: http://www.russellcottrell.com/greek/utilities/surrogatepaircalculator.htm

Params:

NameTypeAttributeDescription
body String

The raw body of the HTTP response from the oembed provider's API

Return:

String

The transformed body with surrogate pairs

Test:

public getEmbed(embed: Embed, callback: function(embed: Embed)) source

Resolves options.embedURL to an embed and passes it to callback.

Params:

NameTypeAttributeDescription
embed Embed

Embed object

callback function(embed: Embed)

callback to invoke after resolving embed

Throw:

UnexpectedStatusError

throws when provider API returns a non-200 response.

Test:

public makeAPIRequest(embed: Embed, callback: function(embed: Ebmed)) source

Makes the requests to the oembed provider's API

Params:

NameTypeAttributeDescription
embed Embed

embed object

callback function(embed: Ebmed)

callback to invoke after resolving embed

public parseResponseBody(body: String, callback: function(error: Error, data: Object)) source

Parses the provider API response into a data object

Params:

NameTypeAttributeDescription
body String

API response

callback function(error: Error, data: Object)

callback to invoke with resulting oembed data