From 40cf4fc50ef2e19a622390911430fbc87361e913 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 2 May 2021 17:18:28 +0200 Subject: [PATCH] add more API calls --- .eslintrc.js | 6 +-- .gitignore | 1 + LICENSE.md | 21 +++++++++ README.md | 91 +++++++++++++++++++++++++++----------- lib/api.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 28 +++++++----- test/api_test.js | 7 +++ 7 files changed, 227 insertions(+), 39 deletions(-) create mode 100644 LICENSE.md diff --git a/.eslintrc.js b/.eslintrc.js index f381343..a7ea9b9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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": [ @@ -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" diff --git a/.gitignore b/.gitignore index c2658d7..504afef 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +package-lock.json diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..39da8d6 --- /dev/null +++ b/LICENSE.md @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index 2067123..4a56504 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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) @@ -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. diff --git a/lib/api.js b/lib/api.js index 99bf44f..d953c21 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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) { @@ -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', diff --git a/package.json b/package.json index 003b0f5..54475a6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "TestingBot (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" @@ -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" } } diff --git a/test/api_test.js b/test/api_test.js index 3bd943a..9f168ca 100644 --- a/test/api_test.js +++ b/test/api_test.js @@ -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);