Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import WhiteKnightSDK from '../';
- import * as validateContactParams from '../app/middleware/contact/validateParams';
- import _ from 'underscore';
- (async () => {
- const config = {
- rest: {
- base: 'https://scoot-wkgk-dev.matchbyte.net/wkapi/v1.0/'
- // base: 'https://scoot-wkgk-uat.matchbyte.net/wkapi/v1.0/'
- },
- service: {
- meal: {
- pattern : /^(M[A-Z][0-9][0-9]|ML..|..ML)$/
- },
- baggage: {
- pattern : /^B(G|L|X)[0-9][0-9]$/,
- mode : 'passenger-journey'
- }
- },
- logic: {
- fareMapping: fare => fare[0] === 'G' ? 'Economy' : 'Scootbiz'
- },
- ajax: {
- maxRetry: 1
- },
- configure: router => {
- router
- .getRoute({ path: '/ping', method: 'GET' })
- .getMiddleware()
- .add(async (ctx, prev, next) => {
- prev.msg = prev.msg.toUpperCase();
- return next(prev);
- });
- }
- };
- const client = await WhiteKnightSDK.createClient(config);
- const examples = [
- //example 0 - simple middleware
- async () => {
- await client.get('/ping', { msg: 'Hello, World!' });
- },
- //example 1 - create booking
- async () => {
- await client.post('/session', { credentials: { username: 'ASG1500043', password: 'Z7w28*xr' }, domain: 'WWW' });
- await client.post('/booking');
- await client.post('/passenger', { passenger: { type: 'adult' } });
- const available = await client.get('/journey/available', {
- journeys: [{
- origin : { code: 'DMK', date: '2017-04-21' },
- destination : { code: 'SIN' }
- }]
- });
- const journey = await client.put('/journey', { journey: available[0][1] });
- await client.get('/summary/journey', { journey });
- await client.put('/passenger', { passenger: {
- id: 0,
- name: {
- title : 'Mr',
- first : 'John',
- last : 'Smith'
- },
- gender: 'male',
- birthdate: '1986-06-08T07:00:00+00:00'
- }});
- await client.put('/contact', { contact: {
- name: { title: 'Mr', first: 'John', last: 'Smith' },
- contact: {
- email: 'john@gmail.com',
- phone: { home: '09993333444' }
- },
- address: {
- lines : ['Mine street'],
- city : 'NYC',
- state : 'NY',
- postalCode : '123456',
- country : 'US'
- }
- }});
- await client.post('/payment/card', {
- card: {
- name : { onCard: 'John Smith' },
- account : '4444333322221111',
- cvv : '123',
- expiry : { month: 5, year: 2017 }
- }
- });
- },
- //example 2 - retrieve booking
- async () => {
- await client.post('/session', { credentials: { username: 'ASG1500043', password: 'Z7w28*xr' }, domain: 'WWW' });
- await client.get('/booking', { booking: { pnr: 'KY5VHA' } });
- await client.get('/passenger');
- await client.get('/journey');
- },
- //example 3 - manage my booking
- async () => {
- await client.post('/session', { credentials: { username: 'ASG1500043', password: 'Z7w28*xr' }, domain: 'WWW' });
- await client.get('/booking', { booking: { pnr: 'KY5VHA' } });
- const passengers = await client.get('/passenger');
- const journeys = await client.get('/journey');
- const baggage = await client.get('/service/baggage/available', {
- journey : journeys[0],
- passenger : passengers[0]
- });
- await client.post('/service/baggage', {
- journey : journeys[0],
- passenger : passengers[0],
- service : baggage[3]
- });
- await client.get('/summary');
- await client.get('/summary/service', { passenger: passengers[0], journey: journeys[0] });
- }
- ];
- await examples[0]();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement