Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for apache bench code gen #221

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions ADDITIONAL_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
### ruby
1. [ruby](https://www.ruby-lang.org/en/downloads)

### shell-apache-bench
1. [apache-bench](https://httpd.apache.org/docs/2.4/programs/ab.html)

### shell-httpie
1. [httpie](https://httpie.org/#installation)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ List of supported code generators:
| PowerShell | RestMethod |
| Ruby | Net:HTTP |
| Shell | Httpie |
| Shell | Apache Bench |
| Shell | wget |
| Swift | URLSession |
## Table of contents
Expand Down
66 changes: 66 additions & 0 deletions codegens/shell-apache-bench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.DS_Store
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Prevent IDE stuff
.idea
.vscode
*.sublime-*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
.coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

out/
34 changes: 34 additions & 0 deletions codegens/shell-apache-bench/.jsdoc-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc", "closure"]
},
"source": {
"include": [ ],
"includePattern": ".+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
},

"plugins": [
"plugins/markdown"
],

"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"highlightTutorialCode" : true
},

"opts": {
"template": "./node_modules/postman-jsdoc-theme",
"encoding": "utf8",
"destination": "./out/docs",
"recurse": true,
"readme": "README.md"
},

"markdown": {
"parser": "gfm",
"hardwrap": false
}
}
74 changes: 74 additions & 0 deletions codegens/shell-apache-bench/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
### NPM Specific: Disregard recursive project files
### ===============================================
/.editorconfig
/.gitmodules
/test

### Borrowed from .gitignore
### ========================

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Prevent IDE stuff
.idea
.vscode
*.sublime-*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
.coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

out/
65 changes: 65 additions & 0 deletions codegens/shell-apache-bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Code-Gen: Postman SDK Request -> Shell-Apache-Bench Snippet Converter

This module is used to convert Postman SDK-Request object in Shell-Apache-Bench variant snippet

#### Prerequisites
To run this repository, ensure that you have NodeJS >= v4. A copy of the NodeJS installable can be downloaded from https://nodejs.org/en/download/package-manager.

## Using the Module
This module exposes two function `convert()` and `getOptions()`

### Convert

Convert function sanitizes the inputs, overrides options with the default ones if not provided and return the code snippet in the desired format.

It requires 3 mandatory parameters `request`, `callback` and `options`

* `request` - postman SDK-request object

* `options` is an object with the following properties

* `indentType` : can be `Tab` or `Space` (default: 'Space')
* `indentCount` : Integer denoting the number of tabs/spaces required for indentation, range 0-8 (default : for indentType Tab : 2, for indentType Space : 4)
* `requestTimeout` : Integer denoting time after which the request will bail out in milli-seconds (default: 0 -> never bail out)
* `trimRequestBody` : Trim request body fields (default: false)

These plugin options will be used if no options are passed to the convert function.

* `callback` : callback function with `error` and `snippet` parameters where snippet is the desired output

#### Example
```javascript
sdk = require('postman-collection');

var request = sdk.Request('http://www.google.com'),
options = {indentType: 'Tab', indentCount: 4, trimRequestBody: true};

convert(request, options, function (err, snippet) {
if (err) {
// perform desired action of logging the error
}
// perform action with the snippet
});
```

### getOptions function

This function returns a list of options supported by this codegen.

#### Example
```js
var options = getOptions();

console.log(options);
// output
// [
// {
// name: 'Set indentation count',
// id: 'indentCount',
// type: 'positiveInteger',
// default: 2,
// description: 'Set the number of indentation characters to add per code level'
// },
// ...
// ]
```
1 change: 1 addition & 0 deletions codegens/shell-apache-bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib');
4 changes: 4 additions & 0 deletions codegens/shell-apache-bench/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
convert: require('./shell-apache-bench').convert,
getOptions: require('./shell-apache-bench').getOptions
};