Identity
Encapsulates all of the logic for communication with the Identity Service in the NPR One API.
Note that consumers should not be accessing this class directly but should instead use the provided pass-through functions in the main NprOneSDK class.
Example:
const nprOneSDK = new NprOneSDK();
nprOneSDK.config = { ... };
nprOneSDK.getUser() // optional; verifies that you have a logged-in user
.then(() => {
return nprOneSDK.searchStations('wnyc');
})
.then((stations) => {
const stationId = stations[0].id; // in reality, you'd probably have the user select a station, see the StationFinder for detail
nprOneSDK.setUserStation(stationId);
});
Test:
Method Summary
Public Methods | ||
public |
Creates a temporary user from the NPR One API and use that user's access token for subsequent API requests. Caution: most clients are not authorized to use temporary users. |
|
public |
followShow(aggregationId: number | string): Promise<User> Indicates that the user wishes to follow, or subscribe to, the show, program, or podcast with the given numeric ID. |
|
public |
Gets user metadata, such as first and last name, programs they have shown an affinity for, and preferred NPR One station. |
|
public |
setUserStation(stationId: number | string): Promise<User> Sets a user's favorite NPR station. Note that this function will first validate whether the station with the given ID actually exists, and will return a promise that rejects if not. |
|
public |
unfollowShow(aggregationId: number | string): Promise<User> Indicates that the user wishes to unfollow, or unsubscribe from, the show, program, or podcast with the given numeric ID. |
Public Methods
public createTemporaryUser(): Promise<User> source
Creates a temporary user from the NPR One API and use that user's access token for subsequent API requests.
Caution: most clients are not authorized to use temporary users.
Throw:
if an OAuth proxy is not configured or no client ID is set |
public followShow(aggregationId: number | string): Promise<User> source
Indicates that the user wishes to follow, or subscribe to, the show, program, or podcast with the given numeric ID. Followed shows will appear more frequently in a user's list of recommendations.
Note that at this time, because we have not yet implemented search in this SDK, there is no way to retrieve a list
of aggregation (show) IDs through this SDK. You can either add functionality to your own app that makes an API call
to GET https://api.npr.org/listening/v2/search/recommendations
with a program name or other search parameters, or
wait until we implement search in this SDK (hopefully later this year).
Throw:
if the passed-in aggregation (show) ID is not either a number or a numeric string |
Test:
public getUser(): Promise<User> source
Gets user metadata, such as first and last name, programs they have shown an affinity for, and preferred NPR One station.
Test:
public setUserStation(stationId: number | string): Promise<User> source
Sets a user's favorite NPR station. Note that this function will first validate whether the station with the given ID actually exists, and will return a promise that rejects if not.
Test:
public unfollowShow(aggregationId: number | string): Promise<User> source
Indicates that the user wishes to unfollow, or unsubscribe from, the show, program, or podcast with the given numeric ID. See followShow for more information.
Throw:
if the passed-in aggregation (show) ID is not either a number or a numeric string |