Recommendation
Extends:
Container class for all metadata pertaining to a recommendation.
Provides metadata and the recordAction method, which sends feedback on user actions to NPR's APIs and advances the flow of audio recommendations to the user
Test:
Constructor Summary
Public Constructor | ||
public |
constructor(json: CollectionDocJSON) |
Member Summary
Public Members | ||
public |
The metadata used to describe this recommendation, such as type and title |
|
public |
The actual audio files associated with this recommendation; should never be empty |
|
public |
This is the |
|
public |
A list of images associated with this recommendation; could be empty |
|
public |
A list of API calls to make if this recommendation is of type |
|
public |
A list of links that are used as the canonical link(s) when sharing this story on social media |
|
public |
An internal store of ratings collected for this application; should never be accessed directly by consumers |
|
public |
A list of API calls the app can make to retrieve subsequent recommendations; should never be accessed directly by consumers |
|
public |
A list of API calls to make if this recommendation is of type |
|
public |
A list of links to places where the app can take the user if they interact with this |
|
public |
A list of links to other places where this story can be found on the web (for example, on NPR.org); could be empty |
Method Summary
Public Methods | ||
public |
This method looks through the recommendation's action and related array to search for any URL starting with For many recommendations, this will not exist and getRecommendationUrl is used instead. |
|
public |
Returns the actual audio files associated with this recommendation |
|
public |
This is the An example of what might be contained within this is array is a link to full-length content for a promo recommendation. |
|
public |
Returns a list of images associated with this recommendation |
|
public |
Returns a list of API calls to make if this recommendation is of type |
|
public |
getOnRamps(): Array<Link> Returns a list of links that are used as the canonical link(s) when sharing this story on social media. |
|
public |
getRatings(): Array<Rating> Returns an internal store of ratings collected for this application. |
|
public |
Returns the URL that should be used to obtain the next set of recommendations. |
|
public |
Returns a list of API calls to make if this recommendation is of type |
|
public |
Returns a list of links to places where the app can take the user if they interact with this |
|
public |
Returns a list of links to other places where this story can be found on the web (for example, on NPR.org) |
|
public |
Returns whether this recommendation has a given action |
|
public |
Returns whether this recommendation has received a rating indicating it is no longer being presented to the user |
|
public |
Returns whether this recommendation is shareable on social media |
|
public |
Returns whether this recommendation is of type |
|
public |
recordAction(action: string, elapsedTimeInSeconds: number) Record a user action taken and the time it was taken against this recommendation |
|
public |
setRatingReceivedCallback(callback: Function) A callback which provides for communication of a received rating |
|
public |
A convenience function to cast this object back to a string, generally only used by the Logger class. |
Protected Methods | ||
protected |
Determines whether the collection doc has the required fields for a valid recommendation |
Inherited Summary
From class CollectionDoc | ||
public get |
Exposed for legacy reasons. |
|
protected |
|
|
protected |
Ensure that the given Collection Doc is valid |
Public Constructors
public constructor(json: CollectionDocJSON) source
Override:
CollectionDoc#constructorParams:
Name | Type | Attribute | Description |
json | CollectionDocJSON | The decoded JSON object that should be used as the basis for this model |
Public Members
public attributes: RecommendationAttributes source
The metadata used to describe this recommendation, such as type and title
public audio: Array<Link> source
The actual audio files associated with this recommendation; should never be empty
public callsToAction: Array<Link> source
This is the action
array from the API within links
, and NOT this SDK's notion of Action
public images: Array<ImageLink> source
A list of images associated with this recommendation; could be empty
public impressions: Array<FormFactorLink> source
A list of API calls to make if this recommendation is of type sponsorship
and the consuming client
has played the accompanying audio
public onramps: Array<Link> source
A list of links that are used as the canonical link(s) when sharing this story on social media
public ratings: Array<Rating> source
An internal store of ratings collected for this application; should never be accessed directly by consumers
public recommendations: Array<Link> source
A list of API calls the app can make to retrieve subsequent recommendations; should never be accessed directly by consumers
public relatedImpressions: Array<FormFactorLink> source
A list of API calls to make if this recommendation is of type sponsorship
and the consuming client has
chosen to interact with the sponsorship item using the contents of relateds
public relateds: Array<FormFactorLink> source
A list of links to places where the app can take the user if they interact with this sponsorship
item
Public Methods
public getActionRecommendationUrl(): string source
This method looks through the recommendation's action and related array to search for any URL starting with 'nprone://listen'
.
If found, everything from the query params is appended to the original recommendation URL.
This value is then used anytime a user indicates they want more similar stories by clicking or tapping on this recommendation.
For many recommendations, this will not exist and getRecommendationUrl is used instead.
public getAudio(): Array<Link> source
Returns the actual audio files associated with this recommendation
Test:
public getCallsToAction(): Array<Link> source
This is the action
array from the API within links
, and NOT this SDK's notion of Action
An example of what might be contained within this is array is a link to full-length content for a promo recommendation.
public getImages(): Array<ImageLink> source
Returns a list of images associated with this recommendation
Test:
public getImpressions(): Array<FormFactorLink> source
Returns a list of API calls to make if this recommendation is of type sponsorship
and the consuming client
has played the accompanying audio. Note that the SDK will take care of this automatically as long as the client
uses recordAction to send the rating.
public getOnRamps(): Array<Link> source
Returns a list of links that are used as the canonical link(s) when sharing this story on social media.
public getRatings(): Array<Rating> source
Returns an internal store of ratings collected for this application. This should never be accessed directly by consumers; use recordAction to send ratings, and the SDK will figure out the appropriate time to make the API call that submits them to the server.
public getRecommendationUrl(): string source
Returns the URL that should be used to obtain the next set of recommendations. This should typically not be used by clients directly; use recordAction followed by NprOneSDK#getRecommendation instead.
public getRelatedImpressions(): Array<FormFactorLink> source
Returns a list of API calls to make if this recommendation is of type sponsorship
and the consuming client
has chosen to interact with the sponsorship item using the contents returned by getRelateds. Note that
the SDK will take care of this automatically as long as the client uses recordAction to send the rating.
public getRelateds(): Array<FormFactorLink> source
Returns a list of links to places where the app can take the user if they interact with this sponsorship
item
(such as by clicking/tapping on the image or using a voice command to learn more)
public getWeb(): Array<Link> source
Returns a list of links to other places where this story can be found on the web (for example, on NPR.org)
Test:
public hasAction(action: string): boolean source
Returns whether this recommendation has a given action
Test:
public hasEndAction(): boolean source
Returns whether this recommendation has received a rating indicating it is no longer being presented to the user
public isShareable(): boolean source
Returns whether this recommendation is shareable on social media
public recordAction(action: string, elapsedTimeInSeconds: number) source
Record a user action taken and the time it was taken against this recommendation
public setRatingReceivedCallback(callback: Function) source
A callback which provides for communication of a received rating
Params:
Name | Type | Attribute | Description |
callback | Function |
|
A function to call whenever this recommendation has received a rating (action) |
public toString(): string source
A convenience function to cast this object back to a string, generally only used by the Logger class.
Test:
Protected Methods
protected _validate() source
Determines whether the collection doc has the required fields for a valid recommendation
Override:
CollectionDoc#_validateThrow:
if the collection doc is invalid |