Skip to content

Latest commit

 

History

History
339 lines (275 loc) · 7 KB

README.md

File metadata and controls

339 lines (275 loc) · 7 KB

Wego SDK

Wego SDK for JavaScript


Version

Downloads Total downloads Packagephobia Bundlephobia

Build Status

The official Wego SDK for JavaScript, available for browsers and mobile devices (if you are using JavaScript), or Node.js backends

Installation

Bower

$ bower install wego-sdk

NPM

$ npm install wego-sdk

Usage

Flight Search Client

/** Create `FlighSearchClient` */
const client = new WegoSdk.FlightSearchClient({
  onTotalTripsChanged: function(trips) {
    // Do something with trips
  },
  onTripsChanged: function(trips) {
    // Do something with trips
  },
  onDisplayedFilterChanged: function(filter) {
    // Do something with filter
  },
  onProgressChanged: function(progress) {
    // Do something with progress
  },
  onCheapestTripChanged: function(trip) {
   // Do something with trip
  },
  onFastestTripChanged: function(trip) {
    // Do something with trip
  },
  onBestExperienceTripChanged: function(trip) {
    // Do something with trip
  },
  onSearchCreated: function(newSearch) {
    // Do something with newSearch
  }
});

/** Make a new search for trips */
client.searchTrips(search);

List of Flight Filters

  1. Stops

    stopCodes: [
      'DIRECT',
      'ONE_STOP',
      'MORE_THAN_ONE_STOP',
    ],
  2. Price

    priceRange: {
      'legIndex': undefined,
      'min': 1397,
      'max': 10924,
    },
  3. Fare Types

    conditions: [
      'refundable',
      'non_refundable',
      'scheduled',
      'chartered',
    ],
  4. Flight Times

    departureTimeMinutesRanges: [
      {
        'min': 171,
        'max': 1241,
        'legIndex': 0,
      },
      {
        'min': 360,
        'max': 1296,
        'legIndex': 1,
      }
    ];
    arrivalTimeMinutesRanges: [
      {
        'min': 171,
        'max': 1241,
        'legIndex': 0,
      },
      {
        'min': 360,
        'max': 1296,
        'legIndex': 1,
      }
    ];
  5. Airlines/Alliances

    airlineCodes: [
      'AF',
      'NH',
    ],
    allianceCodes: [
      'sky_team',
      'star_alliance',
      'oneworld',
      'lcc',
    ],
    /** Complete trip on the same airline */
    tripOptions: ['SAME_AIRLINE'],
  6. Booking Options

    providerTypes: [
      'instant',
      'airline',
    ],
  7. Origin/Destination

    originAirportCodes: ['SIN'],
    destinationAirportCodes: ['IAD'],
  8. Stopover Airports

    stopoverAirportCodes: ['BRU', 'PEK'],
  9. Duration

    durationMinutesRanges: [
      {
        'min': 1553,
        'max': 3113,
        'legIndex': 0,
      },
      {
        'min': 1564,
        'max': 3379,
        'legIndex': 1,
      },
    ],
    stopoverDurationMinutesRanges: [
      {
        'min': 190,
        'max': 2275,
        'legIndex': undefined,
      },
    ],
  10. Flight Experience

    itineraryOptions: [
      'NOT_OVERNIGHT',
      'SHORT_STOPOVER',
    ],

Hotel SDK Client

/** Create `HotelSearchClient` */
const client = new WegoSdk.HotelSearchClient({
  onTotalHotelsChanged: function(hotels) {
    // Do something with hotels
  },
  onHotelsChanged: function(hotels) {
    // Do something with hotels
  },
  onDisplayedFilterChanged: function(filter) {
    // Do something with filter
  },
  onProgressChanged: function(progress) {
    // Do something with progress
  },
  onSearchCreated: function(newSearch) {
    // Do something with newSearch
  }
});

/**
 * Make a new search by calling `searchHotels`.
 * 
 * For more info about the `searchParams`, please visit 
 * https://github.com/wego/wego-api-docs#create-new-hotels-search.
 */
const searchParams = {
  "search": {
    "id": "2d8805fd14337580",
    "siteCode": "SG",
    "locale": "en",
    "currencyCode": "SGD",
    "cityCode": "SIN",
    "countryCode": "SG",
    "roomsCount": 1,
    "guestsCount": 2,
    "checkIn": "2017-12-11",
    "checkOut": "2017-12-16",
    "deviceType": "DESKTOP",
    "appType": "WEB_APP",
    "userLoggedIn": true
    "hotelId": "12345", /** Optional */
    "districtId": "12345" /** Optional */
  },
  "offset": 500,
  "selectedHotelIds": ['258101'], /** Optional */

  similarHotels: { limit: 10 }, /** New, optional */
  nearbyHotels: { limit: 10, radiusInKm: 2 }, /** New, optional */
}

client.searchHotels(searchParams);

Hotel Details Rates SDK Client

/** Create `HotelDetailsClient` */
const client = new WegoSdk.HotelDetailsClient({
  onHotelRatesChanged: function(rates) {
    // Do something with rates
  },
  onProgressChanged: function(progress) {
    // Do something with progress
  },
  onSearchCreated: function(newSearch) {
    // Do something with newSearch
  }
});

/** Create new search */
client.searchHotelRates(hotelSearch, mainSearchId);

Test

$ npm run test

Commit

The final bundle will be output at dist directory named WegoSdk.js.

$ npm run build

References

Wego API documentation

License

ISC