@@ -7,6 +7,7 @@ const axios = require('axios');
77const crypto = require ( 'crypto' ) ;
88const FormData = require ( 'form-data' ) ;
99const os = require ( 'os' ) ;
10+ const { version } = require ( '../package.json' ) ;
1011
1112class TestingBot {
1213 constructor ( options ) {
@@ -316,7 +317,10 @@ class TestingBot {
316317 password : this . options . api_secret
317318 } ,
318319 data : form ,
319- headers : form . getHeaders ( ) ,
320+ headers : {
321+ ...form . getHeaders ( ) ,
322+ 'User-Agent' : `testingbot-api-client v${ version } `
323+ } ,
320324 validateStatus : function ( status ) {
321325 return true ; // Accept any status code to handle errors ourselves
322326 }
@@ -384,7 +388,10 @@ class TestingBot {
384388 method : 'POST' ,
385389 url : 'https://cloud.testingbot.com/session' ,
386390 data : sessionPayload ,
387- headers : { 'Content-Type' : 'application/json' } ,
391+ headers : {
392+ 'Content-Type' : 'application/json' ,
393+ 'User-Agent' : `testingbot-api-client v${ version } `
394+ } ,
388395 validateStatus : function ( status ) {
389396 return true ;
390397 }
@@ -543,6 +550,9 @@ class TestingBot {
543550 username : this . options . api_key ,
544551 password : this . options . api_secret
545552 } ,
553+ headers : {
554+ 'User-Agent' : `testingbot-api-client v${ version } `
555+ } ,
546556 validateStatus : function ( status ) {
547557 return true ; // Accept any status code to handle errors ourselves
548558 }
@@ -552,10 +562,10 @@ class TestingBot {
552562 requestOptions . params = reqData . data ;
553563 } else if ( reqData . method !== 'GET' ) {
554564 if ( reqData . json ) {
555- requestOptions . headers = { 'Content-Type' : 'application/json' } ;
565+ requestOptions . headers [ 'Content-Type' ] = 'application/json' ;
556566 requestOptions . data = reqData . data ;
557567 } else {
558- requestOptions . headers = { 'Content-Type' : 'application/x-www-form-urlencoded' } ;
568+ requestOptions . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ;
559569 // Flatten nested objects for form-encoded data
560570 const flattenObject = ( obj , prefix = '' ) => {
561571 const flattened = { } ;
0 commit comments