Home Manual Reference Source Repository
public class | source

ContentRetriever

Retrieves a full hydrated content model from Hypatia for a given supported url. A supported url is any content that is indexed by Hypatia. This includes all content on http://www.cnn.com, http://edition.cnn.com, http://money.cnn.com, and http://www.greatbigstory.com. It is important to understand that all of the content on edition.cnn.com is the same as www.cnn.com. When querying an edition.cnn.com url make sure to use the www.cnn.com domain.

The example can be found in the repository in example/example.js.

Example:

const ContentRetriever = require('cnn-content-retriever'),
    url = 'http://www.cnn.com/2016/02/18/entertainment/kanye-west-rants-feat/index.html',
    contentRetriever = new ContentRetriever(url);

contentRetriever.getBaseContentModel().then(function success(baseModel) {
    contentRetriever.getRelatedContent(baseModel).then(function success(hydratedModel) {
        console.log(JSON.stringify(hydratedModel, null, 2));
    });
});

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get

Gets the hypata host to connect to.

public set

Sets the hypatia host and defaults to http://hypatia.api.cnn.com/.

public get

Gets the hypata route to use.

public set

Gets the hypata route to use and defaults to svc/content/v2/search/collection1/.

public get

Gets the timeout value, in milliseconds, for use with http requests.

public set

Sets the timeout value, in seconds, for all http requests to hypatia; Default is 5 seconds (5000 milliseconds)

public

The url to retrieve from Hypatia.

Method Summary

Public Methods
public

Gets a base content model from Hypatia for a given url.

public

Gets the related content for a base content model.

Private Methods
private

Gets the slides from Hypatia for a gallery query.

private

getVideoUrl(url: String, dataSource: String): Promise

Gets the video url by calling the cvpXmlUrl and finding the correct .m3u8 url.

private

processParagraphs(data: Object, callback: Function)

Loops though an array of paragraphs to fetch referenced data.

private

processRelatedMedia(data: Object, callback: Function)

Loops though an array of relatedMedia to fetch and referenced data.

private

For a video content type (not an article content type), get the .m3u8Url

Public Constructors

public constructor(url: String) source

Params:

NameTypeAttributeDescription
url String

A url to lookup in Hypatia.

Example:

const ContentRetriever = require('cnn-content-retriever'),
    url = 'http://www.cnn.com/2016/02/18/entertainment/kanye-west-rants-feat/index.html',
    contentRetriever = new ContentRetriever(url);

Public Members

public get hypatiaHost: String source

Gets the hypata host to connect to.

Example:

console.log(contentRetriever.hypatiaHost);

public set hypatiaHost: String source

Sets the hypatia host and defaults to http://hypatia.api.cnn.com/.

Example:

contentRetriever.hypatiaHost = 'http://hypatia.api.cnn.com/';

public get hypatiaRoute: String source

Gets the hypata route to use.

Example:

console.log(contentRetriever.hypatiaRoute);

public set hypatiaRoute: String source

Gets the hypata route to use and defaults to svc/content/v2/search/collection1/.

Example:

contentRetriever.hypatiaRoute = 'svc/content/v2/search/collection1/';

public get timeout: String source

Gets the timeout value, in milliseconds, for use with http requests.

Example:

console.log(contentRetriever.timeout);

public set timeout: Number source

Sets the timeout value, in seconds, for all http requests to hypatia; Default is 5 seconds (5000 milliseconds)

Example:

contentRetriever.timeout = 5;

public url: String source

The url to retrieve from Hypatia. This should only be set by the constructor when the class is instantiated.

Example:

http://www.cnn.com/2016/02/18/entertainment/kanye-west-rants-feat/index.html

Public Methods

public getBaseContentModel(): Promise source

Gets a base content model from Hypatia for a given url. This is not a complete content model, there may be elements in this model that are just references to other models that must be fetched. An example of this would be the images that go in a gallery.

Return:

Promise

Returns a promise with the content model on success or an error message on failure.

Example:

contentRetriever.getBaseContentModel().then(function success(baseModel) {
    console.log(baseModel);
});

public getRelatedContent(data: Object): Promise source

Gets the related content for a base content model.

Params:

NameTypeAttributeDescription
data Object

The base content model returned from getBaseContentModel.

Return:

Promise

Returns a promise with the complete content model on success or an error message on failure.

Example:

contentRetriever.getBaseContentModel().then(function success(baseModel) {
    contentRetriever.getRelatedContent(baseModel).then(function success(hydratedModel) {
        console.log(hydratedModel);
    });
});

Private Methods

private getGallerySlides(url: String): Promise source

Gets the slides from Hypatia for a gallery query.

Params:

NameTypeAttributeDescription
url String

The full url to call to return the content needed for a gallery. This is found in the base content model in the referenceUrl of a gallery element.

Return:

Promise

Returns a promise with the content model on success or an error message on failure.

private getVideoUrl(url: String, dataSource: String): Promise source

Gets the video url by calling the cvpXmlUrl and finding the correct .m3u8 url.

Params:

NameTypeAttributeDescription
url String

The url to the video XML file that has details for all of the different video files.

dataSource String

Should be a valid dataSource

Return:

Promise

private processParagraphs(data: Object, callback: Function) source

Loops though an array of paragraphs to fetch referenced data.

Params:

NameTypeAttributeDescription
data Object

A Hyptia response object.

callback Function

An async parallel callback function from getRelatedContent()

private processRelatedMedia(data: Object, callback: Function) source

Loops though an array of relatedMedia to fetch and referenced data.

Params:

NameTypeAttributeDescription
data Object

A Hypatia response object.

callback Function

An async parallel callback function from getRelatedContent()

private processVideoContentType(data: Object, callback: Function) source

For a video content type (not an article content type), get the .m3u8Url

Params:

NameTypeAttributeDescription
data Object

A Hyptia response object.

callback Function

An async parallel callback function from getRelatedContent()