NprOneSDK
This SDK attempts to abstract away most of the interaction with the NPR One API. In general, a consumer of this API should be primarily concerned with asking for recommendations and recording user actions against those recommendations.
Test:
Static Member Summary
Static Public Members | ||
public static get |
Exposes the Action class for clients to record actions |
|
public static get |
Exposes the Logger class for clients to adjust logging if desired |
|
public static get |
|
|
public static set |
|
|
public static get |
|
|
public static set |
Updates private |
|
public static set |
Sets a callback to be triggered whenever the SDK rotates the access token for a new one, usually when
the old token expires and a |
Static Method Summary
Static Public Methods | ||
public static |
getServiceUrl(service: string): string Returns the foundational path for a given service |
|
public static |
refreshExistingAccessToken(numRetries: number): Promise<AccessToken> See Authorization.refreshExistingAccessToken for description. |
Constructor Summary
Public Constructor | ||
public |
Instantiates the NPR One SDK. |
Method Summary
Static Public Members
public static get Action: Action source
Exposes the Action class for clients to record actions
Test:
public static get Logger: Logger source
Exposes the Logger class for clients to adjust logging if desired
Test:
public static set config: Config source
Updates private _config
member attributes but does not overwrite entire _config
object
public static set onAccessTokenChanged: Function source
Sets a callback to be triggered whenever the SDK rotates the access token for a new one, usually when
the old token expires and a refresh_token
is used to generate a fresh token. Clients who wish to persist
access tokens across sessions are urged to use this callback to be notified whenever a token change has
occurred; the only other alternative is to call get accessToken()
after every API call.
Throw:
if the passed-in value isn't a function |
Static Public Methods
public static getServiceUrl(service: string): string source
Returns the foundational path for a given service
Params:
Name | Type | Attribute | Description |
service | string |
Throw:
if the passed-in service name is missing or invalid |
Test:
public static refreshExistingAccessToken(numRetries: number): Promise<AccessToken> source
See Authorization.refreshExistingAccessToken for description.
Params:
Name | Type | Attribute | Description |
numRetries | number |
|
The number of times this function has been tried. Will retry up to 3 times. |
Throw:
if an OAuth proxy is not configured or no access token is set |
Public Constructors
Public Methods
public createTemporaryUser(): Promise<User> source
See Identity#createTemporaryUser for description.
Throw:
if an OAuth proxy is not configured or no client ID is set |
public followShow(aggregationId: number | string): Promise<User> source
See Identity#followShow for description.
Throw:
if the passed-in aggregation (show) ID is not either a number or a numeric string |
Test:
public getDeviceCode(scopes: Array<string>): Promise<DeviceCode> source
See Authorization#getDeviceCode for description.
Throw:
if an OAuth proxy is not configured |
Test:
public getHistory(): Promise<Array<Recommendation>> source
See Listening#getHistory for description.
Test:
public getRecommendation(uid: string, channel: string): Promise<Recommendation> source
See Listening#getRecommendation for description.
Params:
Name | Type | Attribute | Description |
uid | string |
|
Optional; a UID for a specific recommendation to play. In 99% of use cases, this is not needed. |
channel | string |
|
Optional; a channel to pull the recommendation from; the main flow channel of |
public getRecommendationsFromChannel(channel: string): Promise<Array<Recommendation>> source
See Listening#getRecommendationsFromChannel for description.
Params:
Name | Type | Attribute | Description |
channel | string |
|
A non-flow (i.e. non- |
public getStationDetails(stationId: number | string): Promise<Station> source
See StationFinder#getStationDetails for description.
public getUpcomingFlowRecommendations(channel: string): Promise<Array<Recommendation>> source
See Listening#getUpcomingFlowRecommendations for description.
Params:
Name | Type | Attribute | Description |
channel | string |
|
A channel to pull the next recommendation from |
public logout(): Promise source
See Authorization#logout for description.
Throw:
if an OAuth proxy is not configured or no access token is currently set |
Test:
public pollDeviceCode(): Promise<AccessToken> source
See Authorization#pollDeviceCode for description.
Throw:
if an OAuth proxy is not configured or |
Test:
public queueRecommendationFromChannel(channel: string, uid: string): Recommendation source
See Listening#queueRecommendationFromChannel for description.
Throw:
If no valid channel or UID is passed in |
|
If no recommendations for this channel were previously cached, or if the UID was not found in that cached list |
public resumeFlowFromRecommendation(json: Object): Recommendation source
See Listening#resumeFlowFromRecommendation for description.
Params:
Name | Type | Attribute | Description |
json | Object | JSON object representation of a recommendation |
public searchStations(query: null | string): Promise<Array<Station>> source
See StationFinder#searchStations for description.
Test:
public searchStationsByCity(city: string): Promise<Array<Station>> source
See StationFinder#searchStationsByCity for description.
Params:
Name | Type | Attribute | Description |
city | string | A full city name (e.g. "New York", "San Francisco", "Phoenix") |
public searchStationsByCityAndState(city: string, state: string): Promise<Array<Station>> source
See StationFinder#searchStationsByCityAndState for description.
public searchStationsByLatLongCoordinates(lat: number, long: number): Promise<Array<Station>> source
See StationFinder#searchStationsByLatLongCoordinates for description.
public searchStationsByState(state: string): Promise<Array<Station>> source
See StationFinder#searchStationsByState for description.
Params:
Name | Type | Attribute | Description |
state | string | A state name (e.g. "Maryland") or abbreviation (e.g. "MD") |
public setUserStation(stationId: number | string): Promise<User> source
See Identity#setUserStation for description.