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 Google App Script (UrlFetchApp) #449

Open
wants to merge 12 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,41 @@ This module converts a [Postman SDK](https://github.com/postmanlabs/postman-coll

Every code generator has two identifiers: `language` and `variant`.
* `language` of a code generator is the programming language in which the code snippet is generated.
* `variant` of a code generator is the methodology or the underlying library used by the language to send requests.
List of supported code generators:
* `variant` of a code generator is the methodology or the underlying library used by the language to send requests.

List of supported code generators:

| Language | Variant |
|-----------|---------------|
| C | libcurl |
| C# | RestSharp |
| cURL | cURL |
| Dart | http |
| Go | Native |
| HTTP | HTTP |
| C# | RestSharp |
| cURL | cURL |
| Dart | http |
| Go | Native |
| HTTP | HTTP |
| Java | OkHttp |
| Java | Unirest |
| JavaScript | Fetch |
| JavaScript | jQuery |
| JavaScript | Fetch |
| JavaScript | jQuery |
| JavaScript | UrlFetchApp |
| JavaScript | XHR |
| NodeJs | Axios |
| NodeJs | Axios |
| NodeJs | Native |
| NodeJs | Request |
| NodeJs | Unirest |
| Objective-C| NSURLSession|
| OCaml | Cohttp |
| OCaml | Cohttp |
|PHP | cURL |
|PHP | pecl_http |
|PHP | HTTP_Request2 |
| PowerShell | RestMethod |
| PowerShell | RestMethod |
| Python | http.client |
| Python | Requests |
| Ruby | Net:HTTP |
| Shell | Httpie |
| Shell | wget |
| Swift | URLSession |
## Table of contents
| Swift | URLSession |
## Table of contents

1. [Getting Started](#getting-started)
2. [Prerequisite](#prerequisite)
Expand Down Expand Up @@ -72,11 +73,11 @@ To run any of the postman-code-generators, ensure that you have NodeJS >= v8. A

## Usage

### Using postman-code-generators as a Library
### Using postman-code-generators as a Library
There are three functions that are exposed in postman-code-generators: getLanguageList, getOptions, and convert.

#### getLanguageList
This function returns a list of supported code generators.
This function returns a list of supported code generators.

##### Example:
```js
Expand Down Expand Up @@ -105,7 +106,7 @@ var codegen = require('postman-code-generators'), // require postman-code-genera
// ]
```

#### getOptions
#### getOptions

This function takes in three parameters and returns a callback with error and supported options of that code generator.

Expand All @@ -132,7 +133,7 @@ var codegen = require('postman-code-generators'), // require postman-code-genera
}
console.log(options);
});
// output:
// output:
// [
// {
// name: 'Set indentation count',
Expand All @@ -153,7 +154,7 @@ var codegen = require('postman-code-generators'), // require postman-code-genera
// ];
```

#### convert
#### convert
This function takes in five parameters and returns a callback with error and generated code snippet
* `language` - lang key from the language list returned from getLanguageList function
* `variant` - variant key provided by getLanguageList function
Expand All @@ -165,7 +166,7 @@ This function takes in five parameters and returns a callback with error and gen
```js
var codegen = require('postman-code-generators'), // require postman-code-generators in your project
sdk = require('postman-collection'), // require postman-collection in your project
request = new sdk.Request('https://www.google.com'), //using postman sdk to create request
request = new sdk.Request('https://www.google.com'), //using postman sdk to create request
language = 'nodejs',
variant = 'request',
options = {
Expand All @@ -189,21 +190,21 @@ This command will install all the dependencies in production mode.
```bash
$ npm install;
```
To install dev dependencies also for all codegens run:
To install dev dependencies also for all codegens run:
```bash
$ npm run deepinstall dev;
$ npm run deepinstall dev;
```
### Testing
### Testing
To run common repo test as well as tests (common structure test + individual codegen tests) for all the codegens
```bash
$ npm test;
$ npm test;
```
To run structure and individual tests on a single codegen
```bash
$ npm test <codegen-name>;
# Here "codege-name" is the folder name of the codegen inside codegens folder
```
### Packaging
### Packaging
To create zipped package of all codegens
```bash
$ npm run package;
Expand Down
41 changes: 41 additions & 0 deletions codegens/js-urlfetchapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.DS_Store
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Coverage directory used by tools like istanbul
.coverage

# node-waf configuration
.lock-wscript


# 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/
76 changes: 76 additions & 0 deletions codegens/js-urlfetchapp/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### 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

snippet.swift

out/
44 changes: 44 additions & 0 deletions codegens/js-urlfetchapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

> Converts Postman-SDK Request into code snippet for Google Apps Script (UrlFetchApp).

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

## Using the Module
The module will expose an object which will have property `convert` which is the function for converting the Postman-SDK request to swift code snippet.

### convert function
Convert function takes three parameters

* `request` - Postman-SDK Request Object

* `options` - options is an object which hsa following properties
* `indentType` - String denoting type of indentation for code snippet. eg: 'Space', 'Tab'
* `indentCount` - The number of indentation characters to add per code level
* `trimRequestBody` - Whether or not request body fields should be trimmed

* `callback` - callback function with first parameter as error and second parameter as string for code snippet

##### Example:
```js
var request = new sdk.Request('www.google.com'), //using postman sdk to create request
options = {
indentCount: 3,
indentType: 'Space',
requestTimeout: 200,
trimRequestBody: true
};
convert(request, options, function(error, snippet) {
if (error) {
// handle error
}
// handle snippet
});
```
### Guidelines for using generated snippet

* Since Postman-SDK Request object doesn't provide complete path of the file, it needs to be manually inserted in case of uploading a file.

* This module doesn't support cookies.

* This module doesn't support requestTimeout option.
1 change: 1 addition & 0 deletions codegens/js-urlfetchapp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib');
Loading