Advertisement
Guest User

MMX Client

a guest
Jan 29th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @fileOverview Client for the MMX endpoint.
  3.  */
  4. 'use strict';
  5.  
  6. var assert = require('assert');
  7. var SERVICE = 'MMX';
  8. var VERSION = 1.0;
  9.  
  10. /**
  11.  * Creates a new MMX client instance.
  12.  * @param endpoint The MMX endpoint.
  13.  * @param ctx  The context where the function is called.
  14.  * @returns A MMX service instance.
  15.  */
  16. function createMmx(endpoint, ctx) {
  17.  
  18.     assert(endpoint !== undefined, 'The endpoint parameter must be specified.');
  19.     assert(endpoint !== null, 'The endpoint parameter cannot be null.');
  20.  
  21.     assert(ctx !== undefined, 'The ctx parameter must be specified.');
  22.     assert(ctx !== null, 'The ctx parameter cannot be null.');
  23.  
  24.     function getMarketsInfoForEvent(eventId, mopId, requireRunners, requirePreSettlementInfo) {
  25.  
  26.         assert(eventId !== undefined, 'The endpoint parameter must be specified.');
  27.         assert(eventId !== null, 'The endpoint parameter cannot be null.');
  28.  
  29.         assert(mopId !== undefined, 'The endpoint parameter must be specified.');
  30.         assert(mopId !== null, 'The endpoint parameter cannot be null.');
  31.  
  32.  
  33.         assert(typeof requireRunners === "boolean", 'The requireRunners parameter must be a boolean.');
  34.  
  35.         assert(typeof requirePreSettlementInfo === "boolean", 'The requireRunners parameter must be a boolean.');
  36.  
  37.  
  38.         var params = {
  39.             eventId: eventId,
  40.             mopId: mopId,
  41.             requireRunners: requireRunners,
  42.             requirePreSettlementInfo: requirePreSettlementInfo
  43.         };
  44.  
  45.         return endpoint.call(ctx, SERVICE, VERSION, 'getMarketsInfoForEvent', params);
  46.     }
  47.  
  48.     return {
  49.         /**
  50.          * To get markets information from MMX services we need to make two services calls,
  51.          * marketsforEvent and marketInfo
  52.          *
  53.          * @method getMarketsInfoForEvent
  54.          * @memberOf MMX
  55.          *
  56.          * @param  {String}  eventId The event id
  57.          * @param {String} mopId The mop id
  58.          * @param {Boolean} requireRunners A flag stating if should retrieve markets with runners
  59.          * @param {Boolean} requirePreSettlementInfo A flag stating if should retrieve the markets
  60.          * pre-settlement info
  61.          * @return {Promise} The return Promise
  62.          */
  63.         getMarketsInfoForEvent: getMarketsInfoForEvent
  64.     };
  65. }
  66.  
  67. module.exports = createMmx;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement