Source: models/production/userdata.js

  1. define('application/models/production/userdata', [
  2. 'rofl/models/api/abstract',
  3. 'rofl/lib/utils',
  4. 'application/constants'
  5. ], function (
  6. Abstract,
  7. Utils,
  8. Constants
  9. ) {
  10. 'use strict';
  11. var baseUrl = '101/1.2.0/A/nld/smarttv/kpn/CONTENT/USERDATA',
  12. ENDPOINTS = {
  13. '_VOD': '/PROGRAM/{{contentId}}',
  14. 'PROGRAM': '/PROGRAM/{{contentId}}',
  15. 'VOD': '/VOD/{{contentId}}',
  16. 'VOD_MOVIE': '/VOD/{{contentId}}',
  17. 'LIVE': '/LIVE/{{contentId}}',
  18. 'RESTART': '/LIVE/{{contentId}}',
  19. 'RECORDING': '/RECORDING/{{contentId}}',
  20. 'MOVIE': '/VOD/{{contentId}}'
  21. };
  22. return Abstract.extend({
  23. /**
  24. * Resolves the endpoint.
  25. *
  26. * @param {Object} params - The parameters.
  27. * @returns {string} - The endpoint.
  28. */
  29. resolveEndpoint: function (params) {
  30. var endpoint = baseUrl,
  31. contentData = params && params.data,
  32. type = contentData && contentData.getContentType() || params.contentType,
  33. contentId = contentData && contentData.getId() || params.contentId;
  34. if (type === Constants.RECORDING_EPISODE_VIDEO_TYPE) {
  35. contentId = contentData && contentData.getRecordingId() || contentId;
  36. }
  37. if (!type || !contentId) {
  38. throw 'Missing userdata parameters';
  39. }
  40. endpoint += ENDPOINTS[type];
  41. return Utils.formatTemplate(endpoint, {
  42. contentId: contentId
  43. });
  44. },
  45. /**
  46. * Validates the response.
  47. *
  48. * @param {Object} response - The response.
  49. * @returns {boolean} - True if the response is valid.
  50. */
  51. validateResponse: function (response) {
  52. return !!response && response.resultCode === 'OK';
  53. }
  54. });
  55. });