Skip to content

Commit 7be9af9

Browse files
authored
Merge pull request #190 from catchpoint/bin_fix
Added missing key to webpagetest constructor
2 parents 292da74 + 2d4c879 commit 7be9af9

File tree

5 files changed

+36
-75
lines changed

5 files changed

+36
-75
lines changed

README.md

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# WebPageTest API Wrapper for NodeJS
55

6-
[![Build Status](https://travis-ci.com/WebPageTest/webpagetest-api.svg?branch=master)](https://travis-ci.com/WebPageTest/webpagetest-api)
6+
<!-- [![Build Status](https://travis-ci.com/WebPageTest/webpagetest-api.svg?branch=master)](https://travis-ci.com/WebPageTest/webpagetest-api) -->
77
[![NPM Version](https://img.shields.io/npm/v/webpagetest.svg?style=flat)](https://www.npmjs.org/package/webpagetest)
88
[![NPM Downloads](https://img.shields.io/npm/dm/webpagetest.svg?style=flat)](https://www.npmjs.org/package/webpagetest)
99

@@ -22,7 +22,7 @@ npm install webpagetest -g
2222
### Command line
2323

2424
```bash
25-
webpagetest test https://docs.webpagetest.org/api/integrations/
25+
webpagetest test https://docs.webpagetest.org/api/integrations/ -k YOURAPIKEY
2626
```
2727

2828
### Docker
@@ -239,10 +239,10 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
239239

240240
### Examples
241241

242-
#### 1. Get all available locations
242+
#### 1. Get API available locations
243243

244244
```bash
245-
$ webpagetest locations
245+
$ webpagetest locations -k YOURAPIKEY
246246
```
247247

248248
```javascript
@@ -270,41 +270,10 @@ $ webpagetest locations
270270
}
271271
```
272272

273-
#### 2. Get API available locations
273+
#### 2. Run test on https://docs.webpagetest.org/api/integrations/ from San Jose on IE9
274274

275275
```bash
276-
webpagetest locations --key 1F2A3K4E5
277-
```
278-
279-
```javascript
280-
{
281-
"response": {
282-
"statusCode": 200, "statusText": "Ok",
283-
"data": {
284-
"location": [
285-
...
286-
{
287-
"id": "SanJose_IE9",
288-
"Label": "San Jose, CA USA (IE 9,Chrome,Firefox)",
289-
"location": "SanJose_IE9",
290-
"Browser": "IE 9",
291-
"PendingTests": {
292-
"p1": 0, "p2": 0, "p3": 0, "p4": 0, "p5": 2, "p6": 2, "p7": 0,
293-
"p8": 0, "p9": 0, "Total": 7, "HighPriority": 2, "LowPriority": 4,
294-
"Testing": 1, "Idle": 0
295-
}
296-
},
297-
...
298-
]
299-
}
300-
}
301-
}
302-
```
303-
304-
#### 3. Run test on https://docs.webpagetest.org/api/integrations/ from San Jose on IE9
305-
306-
```bash
307-
webpagetest test https://docs.webpagetest.org/api/integrations/ --key 1F2A3K4E5 --location SanJose_IE9
276+
webpagetest test https://docs.webpagetest.org/api/integrations/ -k YOURAPIKEY --location SanJose_IE9
308277
```
309278

310279
```javascript
@@ -323,10 +292,10 @@ webpagetest test https://docs.webpagetest.org/api/integrations/ --key 1F2A3K4E5
323292
}
324293
```
325294

326-
#### 4. Check current test status
295+
#### 3. Check current test status
327296

328297
```bash
329-
webpagetest status 121025_PT_N8K
298+
webpagetest status 121025_PT_N8K -k YOURAPIKEY
330299
```
331300

332301
```javascript
@@ -344,10 +313,10 @@ webpagetest status 121025_PT_N8K
344313
}
345314
```
346315

347-
#### 5. Get test results
316+
#### 4. Get test results
348317

349318
```bash
350-
webpagetest results 121025_PT_N8K
319+
webpagetest results 121025_PT_N8K -k YOURAPIKEY
351320
```
352321

353322
```javascript
@@ -379,23 +348,12 @@ webpagetest results 121025_PT_N8K
379348
}
380349
```
381350

382-
#### 6. Get test waterfall thumbnail from repeat view as data URI
383-
384-
```bash
385-
webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri
386-
```
387351

388-
```javascript
389-
{
390-
"type": "image/png",
391-
"data": "iVBORw0KGgoAAAANSUhEUgA...RK5CYII="
392-
}
393-
```
394352

395-
#### 7. Get remaining tests count for the account
353+
#### 5. Get remaining tests count for the account
396354

397355
```bash
398-
webpagetest testBalance --key 1F2A3K4E5
356+
webpagetest testBalance -k YOURAPIKEY
399357
```
400358

401359
```javascript

bin/webpagetest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function cleanupProgram() {
272272
}
273273

274274
function execCommand() {
275-
var wpt = new WebPageTest(program.server || defaultServer);
275+
var wpt = new WebPageTest(program.server || defaultServer, options.key);
276276

277277
// options
278278
if (options) {

lib/mapping.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ var commands = {
13271327
},
13281328
testers: {
13291329
name: "getTesters",
1330-
options: [options.request],
1330+
options: [options.request, options.apikey],
13311331
info: "list testers status and details",
13321332
},
13331333
test: {
@@ -1364,101 +1364,105 @@ var commands = {
13641364
har: {
13651365
name: "getHARData",
13661366
param: "id",
1367+
options: [options.apikey],
13671368
info: "get the HTTP Archive (HAR) from test",
13681369
},
13691370
pagespeed: {
13701371
name: "getPageSpeedData",
13711372
param: "id",
1372-
options: [options.run],
1373+
options: [options.run, options.apikey],
13731374
info: "get the Google Page Speed results (if available) from test",
13741375
},
13751376
utilization: {
13761377
name: "getUtilizationData",
13771378
param: "id",
1378-
options: [options.run],
1379+
options: [options.run, options.apikey],
13791380
info: "get the CPU, bandwidth and memory utilization data from test",
13801381
},
13811382
request: {
13821383
name: "getRequestData",
13831384
param: "id",
1384-
options: [options.run],
1385+
options: [options.run, options.apikey],
13851386
info: "get the request data from test",
13861387
},
13871388
timeline: {
13881389
name: "getTimelineData",
13891390
param: "id",
1390-
options: [options.run],
1391+
options: [options.run, options.apikey],
13911392
info: "get the Chrome Developer Tools Timeline data (if available) from test",
13921393
},
13931394
netlog: {
13941395
name: "getNetLogData",
13951396
param: "id",
1396-
options: [options.run],
1397+
options: [options.run, options.apikey],
13971398
info: "get the Chrome Developer Tools Net log data (if available) from test",
13981399
},
13991400
chrometrace: {
14001401
name: "getChromeTraceData",
14011402
param: "id",
1402-
options: [options.run],
1403+
options: [options.run, options.apikey],
14031404
info: "get the Chrome Trace data (if available) from test",
14041405
},
14051406
console: {
14061407
name: "getConsoleLogData",
14071408
param: "id",
1408-
options: [options.run],
1409+
options: [options.run, options.apikey],
14091410
info: "get the browser console log data (if available) from test",
14101411
},
14111412
testinfo: {
14121413
name: "getTestInfo",
14131414
param: "id",
1415+
options: [options.apikey],
14141416
info: "get test request info/details",
14151417
},
14161418
history: {
14171419
name: "getHistory",
14181420
param: "days",
14191421
optional: true,
1422+
options: [options.apikey],
14201423
info: "get history of previously run tests",
14211424
},
14221425
googlecsi: {
14231426
name: "getGoogleCsiData",
14241427
param: "id",
1425-
options: [options.run],
1428+
options: [options.run, options.apikey],
14261429
info: "get Google CSI data (Client Side Instrumentation)",
14271430
},
14281431
response: {
14291432
name: "getResponseBody",
14301433
param: "id",
1431-
options: [options.run, options.response],
1434+
options: [options.run, options.response, options.apikey],
14321435
info: "get response body for text resources",
14331436
},
14341437
waterfall: {
14351438
name: "getWaterfallImage",
14361439
param: "id",
1437-
options: [options.run, options.image, options.waterfall],
1440+
options: [options.run, options.image, options.waterfall, options.apikey],
14381441
info: "get the waterfall PNG image",
14391442
},
14401443
screenshot: {
14411444
name: "getScreenshotImage",
14421445
param: "id",
1443-
options: [options.run, options.image, options.screenshot],
1446+
options: [options.run, options.image, options.screenshot, options.apikey],
14441447
info: "get the fully loaded page screenshot in JPG format (PNG if in full resolution)",
14451448
},
14461449
video: {
14471450
name: "createVideo",
14481451
param: "tests",
1449-
options: [options.video],
1452+
options: [options.video, options.apikey],
14501453
info: "create a video from <tests> (comma separated test ids)",
14511454
},
14521455
player: {
14531456
name: "getEmbedVideoPlayer",
14541457
param: "id",
1458+
options: [options.apikey],
14551459
info: "get a html5 player for a video <id>",
14561460
},
14571461
listen: {
14581462
name: "listen",
14591463
param: "hostname:port",
14601464
optional: true,
1461-
options: [options.listen],
1465+
options: [options.listen,options.apikey],
14621466
info: "start webpagetest-api proxy server on <hostname>:<port> [hostname:%s]",
14631467
},
14641468
};

lib/webpagetest.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ function get(config, pathname, proxy, agent, callback, encoding) {
9191
};
9292
}
9393

94-
if (encoding !== "binary") {
95-
options.headers["X-WPT-API-KEY"] = this.config.key;
96-
options.headers["accept-encoding"] = "gzip,deflate";
97-
options.headers["User-Agent"] = "WebpagetestNodeWrapper/v0.6.0";
98-
}
94+
// api key always required
95+
options.headers["X-WPT-API-KEY"] = this.config.key;
96+
options.headers["accept-encoding"] = "gzip,deflate";
97+
options.headers["User-Agent"] = "WebpagetestNodeWrapper/v0.7.4";
9998

10099
if (agent) {
101100
options.agent = agent;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpagetest",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "WebPageTest API wrapper for NodeJS",
55
"author": "WebPageTest <[email protected]> (http://github.com/WebPageTest)",
66
"homepage": "http://github.com/WebPageTest/webpagetest-api",

0 commit comments

Comments
 (0)