Skip to content

Commit

Permalink
Merge pull request #360 from webkod3r/define-UA
Browse files Browse the repository at this point in the history
Setting custom User-Agent for requests
  • Loading branch information
webkod3r authored Jul 22, 2024
2 parents 89ebba4 + c6028ba commit 6a50182
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ var exports = function (apiKey = '') {
'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}
];{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}

this.requestConfig = {
headers: {
'User-Agent': 'Transactional-JS/{{{projectVersion}}}',
},
};

// API Routes{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#-first}}
this.{{#tags}}{{{name}}}{{/tags}} = new {{baseName}}(this);{{/-first}}{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
};
Expand Down Expand Up @@ -51,7 +57,7 @@ exports.prototype.post = function post(path, body = {}) {
}

return axiosInstance
.post(url, body)
.post(url, body, _this.requestConfig)
.then(function (response) {
return response.data;
})
Expand All @@ -72,6 +78,14 @@ exports.prototype.setDefaultTimeoutMs = function (timeoutMs) {
axiosInstance.defaults.timeout = timeoutMs;
}

/**
* @param {Object} headers Add header to request. Example: { 'User-Agent': 'custom-value' }
*/
exports.prototype.setRequestHeaders = function (headers) {
var _this = this;
_this.requestConfig.headers = Object.assign(_this.requestConfig.headers, headers);
};

// The default API client implementation.
exports.instance = function (apiKey) {
return new exports(apiKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"fs": false
},
"dependencies": {
"axios": "^1.6.7"
"axios": "^1.7.0"
},
"homepage": "https://github.com/mailchimp/mailchimp-transactional-node",
"repository": {
Expand Down

0 comments on commit 6a50182

Please sign in to comment.