@@ -4,6 +4,7 @@ var querystring = require('qs');
44var fs = require ( 'fs' ) ;
55var path = require ( 'path' ) ;
66var request = require ( 'request' ) ;
7+ var crypto = require ( 'crypto' ) ;
78
89function TestingBot ( options ) {
910 this . options = options || { } ;
@@ -27,13 +28,6 @@ function TestingBot(options) {
2728 }
2829}
2930
30- TestingBot . prototype . getTestDetails = function ( testID , callback ) {
31- this . request ( {
32- method : 'GET' ,
33- url : '/tests/' + testID
34- } , callback ) ;
35- } ;
36-
3731TestingBot . prototype . getBrowsers = function ( callback , type ) {
3832 var data = { } ;
3933 if ( type ) {
@@ -46,24 +40,18 @@ TestingBot.prototype.getBrowsers = function(callback, type) {
4640 } , callback ) ;
4741} ;
4842
49- TestingBot . prototype . getLabTestDetails = function ( testID , callback ) {
50- this . request ( {
51- method : 'GET' ,
52- url : '/lab/' + testID
53- } , callback ) ;
54- } ;
55-
56- TestingBot . prototype . getTunnel = function ( callback ) {
43+ TestingBot . prototype . getUserInfo = function ( callback ) {
5744 this . request ( {
5845 method : 'GET' ,
59- url : '/tunnel '
46+ url : '/user '
6047 } , callback ) ;
6148} ;
6249
63- TestingBot . prototype . getUserInfo = function ( callback ) {
50+ TestingBot . prototype . updateUserInfo = function ( data , callback ) {
6451 this . request ( {
65- method : 'GET' ,
66- url : '/user'
52+ method : 'PUT' ,
53+ url : '/user' ,
54+ data : data
6755 } , callback ) ;
6856} ;
6957
@@ -81,6 +69,56 @@ TestingBot.prototype.getTests = function(callback, offset, limit) {
8169 } , callback ) ;
8270} ;
8371
72+ TestingBot . prototype . getTestDetails = function ( testID , callback ) {
73+ this . request ( {
74+ method : 'GET' ,
75+ url : '/tests/' + testID
76+ } , callback ) ;
77+ } ;
78+
79+ TestingBot . prototype . updateTest = function ( data , testID , callback ) {
80+ this . request ( {
81+ method : 'PUT' ,
82+ url : '/tests/' + testID ,
83+ data : data
84+ } , callback ) ;
85+ } ;
86+
87+ TestingBot . prototype . deleteTest = function ( testID , callback ) {
88+ this . request ( {
89+ method : 'DELETE' ,
90+ url : '/tests/' + testID
91+ } , callback ) ;
92+ } ;
93+
94+ TestingBot . prototype . stopTest = function ( testID , callback ) {
95+ this . request ( {
96+ method : 'PUT' ,
97+ url : '/tests/' + testID + '/stop'
98+ } , callback ) ;
99+ } ;
100+
101+ TestingBot . prototype . getTunnel = function ( callback ) {
102+ this . request ( {
103+ method : 'GET' ,
104+ url : '/tunnel'
105+ } , callback ) ;
106+ } ;
107+
108+ TestingBot . prototype . getTunnelList = function ( callback ) {
109+ this . request ( {
110+ method : 'GET' ,
111+ url : '/tunnel/list'
112+ } , callback ) ;
113+ } ;
114+
115+ TestingBot . prototype . deleteTunnel = function ( tunnelId , callback ) {
116+ this . request ( {
117+ method : 'DELETE' ,
118+ url : '/tunnel/' + tunnelId
119+ } , callback ) ;
120+ } ;
121+
84122TestingBot . prototype . getLabTests = function ( callback , offset , limit ) {
85123 if ( ! offset ) {
86124 offset = 0 ;
@@ -95,34 +133,39 @@ TestingBot.prototype.getLabTests = function(callback, offset, limit) {
95133 } , callback ) ;
96134} ;
97135
98- TestingBot . prototype . updateUserInfo = function ( data , callback ) {
136+ TestingBot . prototype . updateLabTest = function ( data , testID , callback ) {
99137 this . request ( {
100138 method : 'PUT' ,
101- url : '/user' ,
139+ url : '/lab/' + testID ,
102140 data : data
103141 } , callback ) ;
104142} ;
105143
106- TestingBot . prototype . updateTest = function ( data , testID , callback ) {
144+ TestingBot . prototype . getBuilds = function ( callback , offset , limit ) {
145+ if ( ! offset ) {
146+ offset = 0 ;
147+ }
148+ if ( ! limit ) {
149+ limit = 10 ;
150+ }
151+
107152 this . request ( {
108- method : 'PUT' ,
109- url : '/tests/' + testID ,
110- data : data
153+ method : 'GET' ,
154+ url : '/builds?offset=' + offset + '&limit=' + limit
111155 } , callback ) ;
112156} ;
113157
114- TestingBot . prototype . updateLabTest = function ( data , testID , callback ) {
158+ TestingBot . prototype . getTestsForBuild = function ( buildId , callback ) {
115159 this . request ( {
116- method : 'PUT' ,
117- url : '/lab/' + testID ,
118- data : data
160+ method : 'GET' ,
161+ url : '/builds/' + buildId
119162 } , callback ) ;
120163} ;
121164
122- TestingBot . prototype . deleteTest = function ( testID , callback ) {
165+ TestingBot . prototype . deleteBuild = function ( buildId , callback ) {
123166 this . request ( {
124167 method : 'DELETE' ,
125- url : '/tests /' + testID
168+ url : '/builds /' + buildId
126169 } , callback ) ;
127170} ;
128171
@@ -133,6 +176,10 @@ TestingBot.prototype.deleteLabTest = function(testID, callback) {
133176 } , callback ) ;
134177} ;
135178
179+ TestingBot . prototype . getAuthenticationHashForSharing = function ( sessionId ) {
180+ return crypto . createHash ( 'md5' ) . update ( this . options . api_key + ':' + this . options . api_secret + ':' + sessionId ) . digest ( 'hex' ) ;
181+ } ;
182+
136183TestingBot . prototype . request = function ( req_data , callback ) {
137184 var requestPath = '/v1' + req_data . url ;
138185 if ( req_data . method === 'GET' && req_data . data ) {
@@ -154,7 +201,7 @@ TestingBot.prototype.request = function(req_data, callback) {
154201
155202 request ( requestOptions , function ( error , response ) {
156203 var responseBody = null ;
157- if ( typeof ( response . body ) === 'string' ) {
204+ if ( response . body && typeof ( response . body ) === 'string' ) {
158205 response . body = JSON . parse ( response . body ) ;
159206 }
160207 if ( response . statusCode . toString ( ) . substring ( 0 , 1 ) === '2' ) {
0 commit comments