OEmbedProvider
Extends:
Converts a pattern of URLs into markup via an oembed provider
Test:
Constructor Summary
Public Constructor | ||
public |
constructor(providerURL: String, urlPatterns: Array<RegExp>, format: String) |
Member Summary
Public Members | ||
public |
format: * |
|
public |
providerURL: * |
|
public |
timeoutMs: * |
|
public |
The version number of the url-embed module |
Method Summary
Public Methods | ||
public |
buildAPIURL(embed: Embed): String Builds the API URL string |
|
public |
buildRequestOptions(embed: Embed): Object Builds the HTTP request options (headers, etc.) |
|
public |
Configures the provider |
|
public |
Converts high-bit-value escaped unicode code points to unicode surrogate pair code points. |
|
public |
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 Methods
public buildAPIURL(embed: Embed): String source
Builds the API URL string
Params:
Name | Type | Attribute | Description |
embed | Embed | Embed object |
public buildRequestOptions(embed: Embed): Object source
Builds the HTTP request options (headers, etc.)
Params:
Name | Type | Attribute | Description |
embed | Embed | Embed object |
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:
Name | Type | Attribute | Description |
body | String | The raw body of the HTTP response from the oembed provider's API |
public getEmbed(embed: Embed, callback: function(embed: Embed)) source
Resolves options.embedURL to an embed and passes it to callback.
Throw:
throws when provider API returns a non-200 response. |