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 |
constructor(url: String) |
Member Summary
Public Members | ||
public get |
Gets the hypata host to connect to. |
|
public set |
Sets the hypatia host and defaults to |
|
public get |
Gets the hypata route to use. |
|
public set |
Gets the hypata route to use and defaults to
|
|
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 |
getRelatedContent(data: Object): Promise Gets the related content for a base content model. |
Private Methods | ||
private |
getGallerySlides(url: String): Promise Gets the slides from Hypatia for a gallery query. |
|
private |
getVideoUrl(url: String, dataSource: String): Promise Gets the video url by calling the |
|
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 |
processVideoContentType(data: Object, callback: Function) For a video content type (not an article content type), get the .m3u8Url |
Public Constructors
public constructor(url: String) source
Params:
Name | Type | Attribute | Description |
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 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.
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:
Name | Type | Attribute | Description |
data | Object | The base content model returned from |
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:
Name | Type | Attribute | Description |
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 |
private getVideoUrl(url: String, dataSource: String): Promise source
Gets the video url by calling the cvpXmlUrl
and finding the correct
.m3u8 url.
private processParagraphs(data: Object, callback: Function) source
Loops though an array of paragraphs to fetch referenced data.