Skip to content

Commit

Permalink
Merge pull request #8 from Travelport-Ukraine/changes-to-constructor
Browse files Browse the repository at this point in the history
Changed constructor to object-based. Refactored tests. Added docs.
  • Loading branch information
shmuga authored Aug 1, 2016
2 parents cddbe3f + 2e8966f commit fc5c321
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 35 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Description
Best Travelport Universal API wrapper ever :airplane: :mountain_railway: :hotel:
Best Travelport Universal API wrapper ever :airplane: :mountain_railway: :hotel:

Travelport Universal API offers an array of travel content for air, hotel, car, and rail, including ancillaries (optional services). It also provides functionality to build complete traveler, agency, branch, and account profiles.

Expand All @@ -13,10 +13,19 @@ First install package with `npm install --save uapi-json`.
After that you can use one of functions to create service that you need:

* **uAPI**
* .**createAirService**(auth, [debug, [production]]) ⇒ <code>[AirService](docs/Air.md)</code>
* .**createHotelService**(auth, [debug, [production]]) ⇒ <code>[HotelService](docs/Hotels.md)</code>
* .**createUtilsService**(auth, [debug, [production]]) ⇒ <code>[UtilsService](docs/Utils.md)</code>
* .**createAirService**(settings) ⇒ <code>[AirService](docs/Air.md)</code>
* .**createHotelService**(settings) ⇒ <code>[HotelService](docs/Hotels.md)</code>
* .**createUtilsService**(settings) ⇒ <code>[UtilsService](docs/Utils.md)</code>

### Settings object

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| auth | <code>Object\<username, password, targetBranch\></code> | - | See `auth` description [below](#auth). |
| debug | <code>Number</code> | 0 | Can be 0, 1, or 2. |
| production | <code>Boolean</code> | true | Production variable is connected with production and pre-production environment. Can be true for production and false for pre-production. For more information read docs. . |

<a name="auth"></a>
`username`, `password` and `targetBranch` should be set in `auth` object and provided by Travelport.

There are 3 types of `debug` mode:
Expand All @@ -25,6 +34,10 @@ There are 3 types of `debug` mode:
* `debug=1` - logging only request params, request xml and error if it's occurred.
* `debug=2` - same as 1 but also logging all response xml (due to lot of text to log).

`production` variable is connected with production and pre-production environment.
Can be `true` for production and `false` for pre-production. For more information read [docs](https://support.travelport.com/webhelp/uapi/uAPI.htm#New_Customer_Path/NewCustomer_PreProd.htm%3FTocPath%3DGetting%2520Started%7CGetting%2520Connected%7CGetting%2520Credentials%7C_____2).







5 changes: 4 additions & 1 deletion lib/Air/AirService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var AirServiceInternal = require('./AirServiceInternal');

module.exports = function(auth, debug, production) {
module.exports = function(settings) {
var auth = settings.auth;
var debug = settings.debug;
var production = settings.production;
return {
shop: function(options) {
var AirService = AirServiceInternal(auth, debug, production);
Expand Down
5 changes: 4 additions & 1 deletion lib/Hotels/HotelsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ var HotelsValidator = require('./HotelsValidator');
var HotelsErrors = require('./HotelsErrors');
var config = require('../config');

module.exports = function(auth, debug, production) {
module.exports = function(settings) {
var auth = settings.auth;
var debug = settings.debug;
var production = settings.production;
return {
search: uApiRequest(
config(auth.region, production).HotelsService.url,
Expand Down
5 changes: 4 additions & 1 deletion lib/Utils/UtilsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ var UtilsParser = require('./UtilsParser');
var UtilsValidator = require('./UtilsValidator');
var UtilsErrors = require('./UtilsErrors');

module.exports = function(auth, debug, production) {
module.exports = function(settings) {
var auth = settings.auth;
var debug = settings.debug;
var production = settings.production;
return {
currencyConvert: uApiRequest(
config(auth.region, production).CurrencyConversion.url,
Expand Down
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ var AirService = require('./Air/AirService');
var UtilsService = require('./Utils/UtilsService');

var uAPI = {
createUtilsService: function(auth, debug, production) {
return UtilsService(auth, debug, production);
createUtilsService: function(settings) {
return UtilsService(settings);
},

createHotelService: function(auth, debug, production) {
return HotelsService(auth, debug, production);
createHotelService: function(settings) {
return HotelsService(settings);
},

createAirService: function(auth, debug, production) {
return AirService(auth, debug, production);
createAirService: function(settings) {
return AirService(settings);
},

createUniversalService: function(auth, debug) {
return AirService(auth, debug); //TODO: move
createUniversalService: function(settings) {
return AirService(settings); //TODO: move
}
};

Expand Down
11 changes: 6 additions & 5 deletions test/Air/AirSearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ var proxy = require('proxyquire'),
var uAPI = require('../../index');
var config = require('../testconfig.js');
var AirService = uAPI.createAirService_by_auth(
config.username,
config.password,
config.targetBranch,
config.pcc
{
auth: config,
debug: true,
production: false
}
);


Expand Down Expand Up @@ -99,4 +100,4 @@ describe('#Air', function () {
});
});
});
});
});
11 changes: 6 additions & 5 deletions test/Air/GdsQueuePlace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ var config = require('../testconfig.smart.js')['36d5'];


var AirService = uAPI_lib.createAirService_by_auth(
config.username,
config.password,
config.targetBranch,
'7e53',
true //debug
{
auth: config,
debug: true,
production: false,
},

);

var params = {
Expand Down
9 changes: 5 additions & 4 deletions test/Hotels/HotelsService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ var proxy = require('proxyquire'),
var uAPI = require('../../index');
var config = require('../testconfig.js');
var HotelService = uAPI.createHotelService(
config.username,
config.password,
config.targetBranch,
true
{
auth: config,
debug: true,
production: false
}
);

var hotelSearchParams = {
Expand Down
9 changes: 5 additions & 4 deletions test/Utils/UtilsService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ var proxy = require('proxyquire'),
var uAPI = require('../../index');
var config = require('../testconfig.js');
var UtilsService = uAPI.createUtilsService(
config.username,
config.password,
config.targetBranch,
2
{
auth: config,
debug: 2,
production: false,
}
);


Expand Down

0 comments on commit fc5c321

Please sign in to comment.