Skip to content

Commit

Permalink
add more API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
delabiejochen committed May 2, 2021
1 parent 7c91c3e commit 40cf4fc
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ module.exports = {
"lines-around-directive": "error",
"max-depth": "error",
"max-len": "off",
"max-lines": "error",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "error",
"multiline-ternary": [
Expand Down Expand Up @@ -200,7 +200,7 @@ module.exports = {
"no-warning-comments": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": "error",
"object-curly-newline": "off",
"object-curly-spacing": [
"error",
"always"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
package-lock.json
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) TestingBot.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
91 changes: 65 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[![npm version](https://img.shields.io/npm/v/testingbot-api.svg?style=flat-square)](https://www.npmjs.com/package/testingbot-api)
[![npm downloads](https://img.shields.io/npm/dm/testingbot-api.svg?style=flat-square)](https://www.npmjs.com/package/testingbot-api)
[![Build Status](https://travis-ci.org/testingbot/testingbot-api.svg?branch=master)](https://travis-ci.org/testingbot/testingbot-api)
[![dependencies Status](https://david-dm.org/testingbot/testingbot-api/status.svg)](https://david-dm.org/testingbot/testingbot-api)
[![devDependencies Status](https://david-dm.org/testingbot/testingbot-api/dev-status.svg)](https://david-dm.org/testingbot/testingbot-api?type=dev)
[![dependencies Status](https://status.david-dm.org/gh/testingbot/testingbot-api.svg)](https://david-dm.org/testingbot/testingbot-api)
[![devDependencies Status](https://status.david-dm.org/gh/testingbot/testingbot-api.svg?type=dev)](https://david-dm.org/testingbot/testingbot-api?type=dev)

# testingbot-api

Wrapper around the TestingBot REST API for [Node.js](http://nodejs.org/).
Wrapper around the TestingBot REST API for [Node.js](https://nodejs.org/).

## Install

Expand All @@ -16,7 +16,7 @@ npm install testingbot-api

## Credentials
You can use environment variables `TESTINGBOT_KEY` and `TESTINGBOT_SECRET` to pass your TestingBot key and secret to the API client.
The key and secret can be obtained from [TestingBot](https://testingbot.com/members/user/edit) .
The key and secret can be obtained from [TestingBot](https://testingbot.com/members/user/edit)

## Using the wrapper

Expand All @@ -36,6 +36,27 @@ Gets a list of browsers you can test on
api.getBrowsers(function(error, browsers) {});
```

### getDevices
Gets a list of physical mobile devices you can test on

```javascript
api.getDevices(function(error, devices) {});
```

### getAvailableDevices
Gets a list of available physical mobile devices for your account

```javascript
api.getAvailableDevices(function(error, availableDevices) {});
```

### getDevice
Gets details for a specific physical device

```javascript
api.getDevice(deviceId, function(error, deviceDetails) {});
```


### getUserInfo
Gets your user information
Expand Down Expand Up @@ -129,6 +150,27 @@ Uploads a remote file to TestingBot Storage
api.uploadFile(remoteFileUrl, function(error, appUrl) {});
```

### getStorageFile
Retrieve data from a previously uploaded file

```javascript
api.getStorageFile(remoteFileUrl, function(error, fileDetails) {});
```

### getStorageFiles
Retrieve list of previously uploaded files

```javascript
api.getStorageFiles(function(error, fileDetails) {}, offset, limit);
```

### deleteStorageFile
Delete a previously uploaded file

```javascript
api.deleteStorageFile(appId, function(error, success) {});
```

### getAuthenticationHashForSharing
Calculates the authentication hash for sharing, pass the WebDriver's SessionID.
This is used to [share a test's detail page on TestingBot](https://testingbot.com/support/other/sharing)
Expand All @@ -137,34 +179,31 @@ This is used to [share a test's detail page on TestingBot](https://testingbot.co
api.getAuthenticationHashForSharing(sessionId);
```

## Tests
### takeScreenshot
Takes screenshots for the specific browsers

``npm test``
```javascript
api.getUserInfo(function(error, screenshots) {}, url, browsers, waitTime, resolution, fullPage, callbackURL);
```

## More documentation
### retrieveScreenshots
Retrieves screenshots for a specific `takeScreenshot` call

Check out the [TestingBot REST API](https://testingbot.com/support/api) for more information.
```javascript
api.getUserInfo(screenshotId, function(error, screenshots) {});
```

## License
### getScreenshotList
Retrieves all screenshots previously generate with your account

The MIT License (MIT)
```javascript
api.getScreenshotList(function(error, screenshots) {}, offset, limit);
```

Copyright (c) TestingBot.com
## Tests

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
``npm test``

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
## More documentation

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Check out the [TestingBot REST API](https://testingbot.com/support/api) for more information.
112 changes: 112 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,89 @@ function TestingBot(options) {
}
}

TestingBot.prototype.getDevices = function(callback) {
var data = {};
this.request({
method: 'GET',
url: '/devices',
data: data
}, callback);
};

TestingBot.prototype.getAvailableDevices = function(callback) {
var data = {};
this.request({
method: 'GET',
url: '/devices/available',
data: data
}, callback);
};

TestingBot.prototype.getDevice = function(deviceId, callback) {
var data = {};
if (deviceId) {
data.deviceId = deviceId;
}
this.request({
method: 'GET',
url: '/devices/',
data: data
}, callback);
};

TestingBot.prototype.takeScreenshot = function(callback, url, browsers, waitTime, resolution, fullPage, callbackURL) {
var data = {};
if (url) {
data.url = url;
}
if (browsers) {
data.browsers = browsers;
}
if (waitTime) {
data.waitTime = waitTime;
}
if (resolution) {
data.resolution = resolution;
}
if (fullPage) {
data.fullPage = fullPage;
}
if (callbackURL) {
data.callbackURL = callbackURL;
}
this.request({
method: 'POST',
url: '/screenshots',
data: data
}, callback);
};

TestingBot.prototype.retrieveScreenshots = function(screenshotId, callback) {
var data = {};
if (screenshotId) {
data.screenshotId = screenshotId;
}
this.request({
method: 'GET',
url: '/screenshots',
data: data
}, callback);
};

TestingBot.prototype.getScreenshotList = function(callback, offset, limit) {
if (!offset) {
offset = 0;
}
if (!limit) {
limit = 10;
}
this.request({
method: 'GET',
url: '/screenshots',
data: { offset: offset, limit: limit }
}, callback);
};

TestingBot.prototype.getBrowsers = function(callback, type) {
var data = {};
if (type) {
Expand Down Expand Up @@ -209,6 +292,35 @@ TestingBot.prototype.uploadFile = function(localFilePath, callback) {
});
};

TestingBot.prototype.getStorageFile = function(appUrl, callback) {
this.request({
method: 'GET',
url: '/storage/' + appUrl
}, callback);
};

TestingBot.prototype.getStorageFiles = function(callback, offset, limit) {
if (!offset) {
offset = 0;
}
if (!limit) {
limit = 10;
}

this.request({
method: 'GET',
url: '/storage',
data: { offset: offset, limit: limit }
}, callback);
};

TestingBot.prototype.deleteStorageFile = function(appUrl, callback) {
this.request({
method: 'DELETE',
url: '/storage/' + appUrl
}, callback);
};

TestingBot.prototype.uploadRemoteFile = function(remoteUrl, callback) {
this.request({
method: 'POST',
Expand Down
28 changes: 18 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "TestingBot <[email protected]> (testingbot.com)",
"name": "testingbot-api",
"description": "A wrapper around TestingBot's REST API",
"version": "1.0.7",
"version": "1.0.8",
"scripts": {
"lint": "eslint lib/",
"test": "make test"
Expand All @@ -12,20 +12,28 @@
"type": "git",
"url": "git://github.com/testingbot/testingbot-api.git"
},
"bugs": {
"url" : "https://github.com/testingbot/testingbot-api/issues",
},
"keywords": [
"testingbot-api",
"testingbot-nodejs",
"nodejs api"
],
"devDependencies": {
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"mocha": "^5.2.0"
"eslint": "^7.25.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"mocha": "^8.3.2"
},
"engines": {
"node": "*"
},
"dependencies": {
"qs": "^6.7.0",
"request": "^2.88.0"
"qs": "^6.10.1",
"request": "^2.88.2"
}
}
7 changes: 7 additions & 0 deletions test/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ describe('Api Tests', function() {
});
});

it('should list devices', function(done) {
this.api.getDevices(function(err, response) {
assert.equal(response && response.length > 0, true);
done();
});
});

it('should error when not test is found', function(done) {
this.api.getTestDetails(324234234324, function(err, response) {
assert.equal(null, response);
Expand Down

0 comments on commit 40cf4fc

Please sign in to comment.