Skip to content

Commit

Permalink
Merge a739878 into f4de53a
Browse files Browse the repository at this point in the history
  • Loading branch information
rmomii committed Aug 6, 2018
2 parents f4de53a + a739878 commit 6c9448b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
8 changes: 8 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.3.9 - 2018/08/01

* Added support for Music/findBroadcastsByStationId route

# v1.3.8 - 2018/07/06

* Handled exception gracefully when a url doesn't resolve for the player

# v1.3.7 - 2018/03/28

* Added command to check if original asset exists in the Asset API
Expand Down
30 changes: 30 additions & 0 deletions lib/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,36 @@ module.exports = function (musicOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

self.findBroadcastsByStationId = (stationId, options, callback) => {
// handle any non-specified input params
if (typeof options === 'function') {
callback = options;
options = undefined;
}

if (typeof stationId === 'function') {
callback = stationId;
stationId = undefined;
options = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(stationId)) {
return yield Promise.reject(new Error('stationId is required'));
}

let headers = yield ensureAuthHeaders(options);

return yield req.get({
headers : headers,
pathname : `/v2/stations/${stationId}/broadcasts`,
query : options
});
});

return validation.promiseOrCallback(exec, callback);
};

self.getBroadcast = (stationId, broadcastId, options, callback) => {
// handle any non-specified input params
if (typeof options === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playnetwork-sdk",
"version": "1.3.8",
"version": "1.3.9",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down
59 changes: 59 additions & 0 deletions test/lib/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('music', () => {
should.exist(proxy.allBroadcasts);
should.exist(proxy.allCollections);
should.exist(proxy.allStations);
should.exist(proxy.findBroadcastsByStationId);
should.exist(proxy.getBroadcast);
should.exist(proxy.getCollection);
should.exist(proxy.getStation);
Expand Down Expand Up @@ -1224,6 +1225,64 @@ describe('music', () => {
});
});

describe('#findBroadcastsByStationId', () => {
it('should require stationId (promise)', (done) => {
music.findBroadcastsByStationId()
.then(() => {
return done(new Error('should require stationId'));
})
.catch((err) => {
should.exist(err);
should.exist(err.message);
err.message.should.contain('stationId is required');

return done();
})
});

it('should require stationId (callback)', (done) => {
music.findBroadcastsByStationId(function (err, result) {
should.exist(err);
should.exist(err.message);
err.message.should.contain('stationId is required');
should.not.exist(result);

return done();
});
});

it('should properly retrieve broadcast (promise)', (done) => {
// intercept outbound request
nock('https://curio-music-api.apps.playnetwork.com')
.get('/v2/stations/test/broadcasts')
.reply(200, { total : 0 });

music.findBroadcastsByStationId('test')
.then((result) => {
should.exist(result);
should.exist(requestInfo);

return done();
})
.catch((err) => (done(err)));
});

it('should properly retrieve broadcast (callback)', (done) => {
// intercept outbound request
nock('https://curio-music-api.apps.playnetwork.com')
.get('/v2/stations/test/broadcasts')
.reply(200, { total : 0 });

music.findBroadcastsByStationId('test', function (err, result) {
should.not.exist(err);
should.exist(result);
should.exist(requestInfo);

return done();
});
});
});

describe('#getBroadcast', () => {
it('should require stationId (promise)', (done) => {
music.getBroadcast()
Expand Down

0 comments on commit 6c9448b

Please sign in to comment.