Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. import WhiteKnightSDK from '../';
  2. import * as validateContactParams from '../app/middleware/contact/validateParams';
  3. import _ from 'underscore';
  4.  
  5. (async () => {
  6.  
  7. const config = {
  8.  
  9. rest: {
  10. base: 'https://scoot-wkgk-dev.matchbyte.net/wkapi/v1.0/'
  11. // base: 'https://scoot-wkgk-uat.matchbyte.net/wkapi/v1.0/'
  12. },
  13.  
  14. service: {
  15.  
  16. meal: {
  17. pattern : /^(M[A-Z][0-9][0-9]|ML..|..ML)$/
  18. },
  19.  
  20. baggage: {
  21. pattern : /^B(G|L|X)[0-9][0-9]$/,
  22. mode : 'passenger-journey'
  23. }
  24.  
  25. },
  26.  
  27. logic: {
  28. fareMapping: fare => fare[0] === 'G' ? 'Economy' : 'Scootbiz'
  29. },
  30.  
  31. ajax: {
  32. maxRetry: 1
  33. },
  34.  
  35. configure: router => {
  36.  
  37. router
  38. .getRoute({ path: '/ping', method: 'GET' })
  39. .getMiddleware()
  40. .add(async (ctx, prev, next) => {
  41.  
  42. prev.msg = prev.msg.toUpperCase();
  43.  
  44. return next(prev);
  45.  
  46. });
  47.  
  48. }
  49.  
  50. };
  51.  
  52. const client = await WhiteKnightSDK.createClient(config);
  53.  
  54. const examples = [
  55.  
  56. //example 0 - simple middleware
  57. async () => {
  58. await client.get('/ping', { msg: 'Hello, World!' });
  59. },
  60.  
  61. //example 1 - create booking
  62. async () => {
  63.  
  64. await client.post('/session', { credentials: { username: 'ASG1500043', password: 'Z7w28*xr' }, domain: 'WWW' });
  65.  
  66. await client.post('/booking');
  67. await client.post('/passenger', { passenger: { type: 'adult' } });
  68.  
  69. const available = await client.get('/journey/available', {
  70. journeys: [{
  71. origin : { code: 'DMK', date: '2017-04-21' },
  72. destination : { code: 'SIN' }
  73. }]
  74. });
  75.  
  76. const journey = await client.put('/journey', { journey: available[0][1] });
  77.  
  78. await client.get('/summary/journey', { journey });
  79.  
  80. await client.put('/passenger', { passenger: {
  81.  
  82. id: 0,
  83. name: {
  84. title : 'Mr',
  85. first : 'John',
  86. last : 'Smith'
  87. },
  88. gender: 'male',
  89. birthdate: '1986-06-08T07:00:00+00:00'
  90.  
  91. }});
  92.  
  93.  
  94. await client.put('/contact', { contact: {
  95.  
  96. name: { title: 'Mr', first: 'John', last: 'Smith' },
  97. contact: {
  98. email: 'john@gmail.com',
  99. phone: { home: '09993333444' }
  100. },
  101.  
  102. address: {
  103. lines : ['Mine street'],
  104. city : 'NYC',
  105. state : 'NY',
  106. postalCode : '123456',
  107. country : 'US'
  108. }
  109.  
  110. }});
  111.  
  112. await client.post('/payment/card', {
  113.  
  114. card: {
  115. name : { onCard: 'John Smith' },
  116. account : '4444333322221111',
  117. cvv : '123',
  118. expiry : { month: 5, year: 2017 }
  119. }
  120.  
  121. });
  122.  
  123. },
  124.  
  125. //example 2 - retrieve booking
  126. async () => {
  127. await client.post('/session', { credentials: { username: 'ASG1500043', password: 'Z7w28*xr' }, domain: 'WWW' });
  128.  
  129. await client.get('/booking', { booking: { pnr: 'KY5VHA' } });
  130.  
  131. await client.get('/passenger');
  132. await client.get('/journey');
  133.  
  134. },
  135.  
  136. //example 3 - manage my booking
  137. async () => {
  138. await client.post('/session', { credentials: { username: 'ASG1500043', password: 'Z7w28*xr' }, domain: 'WWW' });
  139.  
  140. await client.get('/booking', { booking: { pnr: 'KY5VHA' } });
  141.  
  142. const passengers = await client.get('/passenger');
  143. const journeys = await client.get('/journey');
  144.  
  145. const baggage = await client.get('/service/baggage/available', {
  146. journey : journeys[0],
  147. passenger : passengers[0]
  148. });
  149.  
  150. await client.post('/service/baggage', {
  151. journey : journeys[0],
  152. passenger : passengers[0],
  153. service : baggage[3]
  154. });
  155.  
  156. await client.get('/summary');
  157. await client.get('/summary/service', { passenger: passengers[0], journey: journeys[0] });
  158.  
  159. }
  160.  
  161. ];
  162.  
  163.  
  164. await examples[0]();
  165.  
  166.  
  167. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement