@@ -117,7 +117,7 @@ gtmetrix.test.create (test, console.log);
117117
118118
119119### test.get
120- ** ( testId, [ resource] , callback )**
120+ ** ( testId, [ resource] , [ polling ] , callback )**
121121
122122Get details about a test or one of its resources.
123123
@@ -126,9 +126,10 @@ the callback `data` will be a _Buffer_ instance, so you can
126126post-process the binary data however you like. See example below.
127127
128128argument | type | required | description
129- :--------|:---------|:---------|:------------------------
129+ :--------|:---------|:---------|:-----------------------------
130130testId | string | yes | Test ` id ` to look up
131131resource | string | no | Retrieve a test resource
132+ polling | number | no | Retry until completion, in ms
132133callback | function | yes | Callback function
133134
134135[ API documentation] ( https://gtmetrix.com/api/#api-test-state )
@@ -137,20 +138,26 @@ callback | function | yes | Callback function
137138##### Test details
138139
139140``` js
141+ // Just get test result
140142gtmetrix .test .get (' Ao0AYQbz' , console .log );
143+
144+ // Get test result when it is complete, retry every 5 seconds (5000 ms)
145+ gtmetrix .test .get (' Ao0AYQbz' , 5000 , console .log );
141146```
142147
143148
144149##### Retrieve screenshot
145150
151+ And retry every 5000 ms until it's ready.
152+
146153``` js
147154var fs = require (' fs' );
148155
149- gtmetrix .test .get (' Ao0AYQbz' , ' screenshot' , function (err , data ) {
156+ gtmetrix .test .get (' Ao0AYQbz' , ' screenshot' , 5000 , function (err , data ) {
150157 if (err) { return console .log (err); }
151158
152159 // Store on disk
153- fs .writeFile (__dirname + ' /screenshot.jpg' , data, console .log );
160+ fs .writeFile (__dirname + ' /screenshot.jpg' , { encoding : ' binary ' }, data, console .log );
154161});
155162```
156163
0 commit comments