Skip to content

Commit b3f2964

Browse files
authored
Merge pull request #25 from TourCMS/release/1.3.0
release/1.3.0
2 parents 23eb818 + 9e3ab5f commit b3f2964

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

node-tourcms.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ function TourCMS(options) {
1717
apiKey: '',
1818
marketplaceId: 0,
1919
channelId: 0,
20-
channels: []
20+
channels: [],
21+
userAgent: '',
22+
prependCallerToUserAgent: true
2123
};
2224

2325
if(typeof options !== 'undefined') {
@@ -30,6 +32,9 @@ function TourCMS(options) {
3032

3133
if(typeof options.channelId !== 'undefined')
3234
this.options.channelId = options.channelId;
35+
36+
if(typeof options.userAgent !== 'undefined')
37+
this.options.userAgent = options.userAgent;
3338
}
3439

3540
}
@@ -60,16 +65,20 @@ TourCMS.prototype.makeRequest = function(a) {
6065
// Generate the signature
6166
var signature = this.generateSignature(a.path, a.channelId, a.verb, outboundTime, this.options.apiKey);
6267

68+
var headers = {
69+
'x-tourcms-date': outboundTime,
70+
'Authorization': 'TourCMS ' + a.channelId + ':' + this.options.marketplaceId + ':' + signature,
71+
'Content-type': 'text/xml;charset="utf-8"',
72+
'Content-length': Buffer.byteLength(apiParams, 'utf8')
73+
};
74+
75+
headers = this.addUserAgent(headers, a);
76+
6377
var options = {
6478
method: a.verb,
6579
hostname: this.options.hostname,
6680
path: a.path,
67-
headers: {
68-
'x-tourcms-date': outboundTime,
69-
'Authorization': 'TourCMS ' + a.channelId + ':' + this.options.marketplaceId + ':' + signature,
70-
'Content-type': 'text/xml;charset="utf-8"',
71-
'Content-length': Buffer.byteLength(apiParams, 'utf8')
72-
}
81+
headers: headers
7382
};
7483

7584
var req = https.request(options, function(response) {
@@ -1296,6 +1305,22 @@ TourCMS.prototype.generateSignature = function(path, channelId, verb, outboundTi
12961305
return signature;
12971306
};
12981307

1308+
TourCMS.prototype.addUserAgent = function(headers, a) {
1309+
1310+
let userAgent = this.options.userAgent;
1311+
1312+
if(userAgent == '')
1313+
return headers;
1314+
1315+
if(this.options.prependCallerToUserAgent)
1316+
userAgent = userAgent + ' (' + this.options.marketplaceId + "_" + a.channelId + ')';
1317+
1318+
headers['User-Agent'] = userAgent;
1319+
1320+
return headers;
1321+
1322+
}
1323+
12991324
// Generate the current Unix Timestamp (PHP style)
13001325
TourCMS.prototype.generateTime = function() {
13011326
return Math.floor(new Date().getTime() / 1000);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"api"
77
],
88
"homepage": "https://github.com/tourcms/node-tourcms",
9-
"version": "1.2.1",
9+
"version": "1.3.0",
1010
"author": "TourCMS <[email protected]> (http://www.tourcms.com)",
1111
"contributors": [
1212
"Paul Slugocki <[email protected]> (https://github.com/paulslugocki)"

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ Create a new `tourcms` API object, passing in your API credentials
7474
var TourCMS = new TourCMSApi({
7575
channelId: YOUR_CHANNEL_ID,
7676
apiKey: 'YOUR_API_KEY',
77-
marketplaceId: YOUR_MARKETPLACE_ID
77+
marketplaceId: YOUR_MARKETPLACE_ID,
78+
userAgent: 'Your app name'
7879
});
7980
```
8081
Then call one of the API methods below.

0 commit comments

Comments
 (0)