define('application/models/production/recordings/episodes', [
'rofl/models/api/abstract',
'rofl/lib/utils',
'application/models/configuration',
'application/models/epg/item',
'application/managers/channel',
'application/models/production/recordings/record',
'application/models/production/series'
], function (
Abstract,
Utils,
KPNConfig,
EPGItem,
ChannelManager,
Record,
Series
) {
'use strict';
var channelManager = ChannelManager.getInstance(),
channels = channelManager.getChannelMap();
return Abstract.extend({
/**
* Resolves the endpoint.
*
* @returns {string} - Endpoint.
*/
resolveEndpoint: function () {
return '101/1.2.0/A/nld/smarttv/kpn/TRAY/USER/RECORDING/EVENT'
+ '?sortOrder=desc&orderBy=StartTime&maxResults=9999&from=0&to=9999'
+ '&filter_channelIds=' + channelManager.getChannelMap();
},
/**
* Transforms the response.
*
* @param {Object} response - The response.
* @returns {Object} Result.
*/
transformFrom: function (response) {
var data = Utils.getNested(response, 'resultObj', 'containers'),
result = {
items: {},
ids: [],
series: {}
};
Utils.each(data, function (item) {
var channelId = item.metadata.channelId || item.channel.channelId,
record;
if (channels.indexOf(channelId) >= 0) {
record = new Record(item);
result.items[item.metadata.liveContentId] = record;
result.ids.push(item.metadata.liveContentId);
if (!result.series[record.getSeriesId()]) {
result.series[record.getSeriesId()] = new Series(record);
} else {
result.series[record.getSeriesId()].addItem(record);
}
}
});
return result;
},
/**
* Validates the response.
*
* @param {Object} response - The response.
* @returns {boolean} - True if valid.
*/
validateResponse: function (response) {
return Utils.getNested(response, 'resultCode') === KPNConfig.RESPONSE_CODES.OK;
}
});
});