Last active
August 26, 2020 02:21
-
-
Save someshkoli/b30a70d02ef105e02a754852542a1abf to your computer and use it in GitHub Desktop.
Sample SDK Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
const configVariables = {}; | |
/** | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
@param {object} config - Variables to used in SDK. | |
*/ | |
function SDK(config = {}) { | |
var self = this; | |
/** | |
The HTTP `POST` request method is meant to transfer data to a server | |
(and elicit a response). What data is returned depends on the implementation | |
of the server. | |
A `POST` request can pass parameters to the server using "Query String | |
Parameters", as well as the Request Body. For example, in the following request, | |
> POST /hi/there?hand=wave | |
> | |
> <request-body> | |
The parameter "hand" has the value "wave". The request body can be in multiple | |
formats. These formats are defined by the MIME type of the request. The MIME | |
Type can be set using the ``Content-Type`` HTTP header. The most commonly used | |
MIME types are: | |
* `multipart/form-data` | |
* `application/x-www-form-urlencoded` | |
* `application/json` | |
This endpoint echoes the HTTP headers, request parameters, the contents of | |
the request body and the complete URI requested. | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
@param {String} variables.var3 | |
@param {String} variables.var2 | |
*/ | |
this["POST_Raw_Text"] = function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var var3 = variables.var3 || self.variables.var3 || ''; | |
var var2 = variables.var2 || self.variables.var2 || ''; | |
var options = { | |
'method': 'POST', | |
'url': '' + url + '/post', | |
'headers': {}, | |
body: 'This is expected to be sent back as part of response body ' + var3 + ' ' + var2 + '' | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
}; | |
/** | |
The HTTP `POST` request method is meant to transfer data to a server | |
(and elicit a response). What data is returned depends on the implementation | |
of the server. | |
A `POST` request can pass parameters to the server using "Query String | |
Parameters", as well as the Request Body. For example, in the following request, | |
> POST /hi/there?hand=wave | |
> | |
> <request-body> | |
The parameter "hand" has the value "wave". The request body can be in multiple | |
formats. These formats are defined by the MIME type of the request. The MIME | |
Type can be set using the ``Content-Type`` HTTP header. The most commonly used | |
MIME types are: | |
* `multipart/form-data` | |
* `application/x-www-form-urlencoded` | |
* `application/json` | |
This endpoint echoes the HTTP headers, request parameters, the contents of | |
the request body and the complete URI requested. | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
*/ | |
this["POST_Raw_Text_Copy"] = function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var options = { | |
'method': 'POST', | |
'url': '' + url + '/post', | |
'headers': { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
query: '{\n body {\n graphql {\n \n }\n }\n}', | |
variables: {} | |
}) | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
}; | |
/** | |
The HTTP `GET` request method is meant to retrieve data from a server. The data | |
is identified by a unique URI (Uniform Resource Identifier). | |
A `GET` request can pass parameters to the server using "Query String | |
Parameters". For example, in the following request, | |
> http://example.com/hi/there?hand=wave | |
The parameter "hand" has the value "wave". | |
This endpoint echoes the HTTP headers, request parameters and the complete | |
URI requested. | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
@param {String} variables.var1 | |
@param {String} variables.var4 | |
@param {String} variables.var2 | |
@param {String} variables.var5 | |
*/ | |
this["GET_Request"] = function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var var1 = variables.var1 || self.variables.var1 || ''; | |
var var4 = variables.var4 || self.variables.var4 || ''; | |
var var2 = variables.var2 || self.variables.var2 || ''; | |
var var5 = variables.var5 || self.variables.var5 || ''; | |
var options = { | |
'method': 'GET', | |
'url': '' + url + '/get?foo1=' + var1 + '' + var4 + '&foo2=' + var2 + '' + var5 + '', | |
'headers': {} | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
}; | |
/** | |
HTTP has multiple request "verbs", such as `GET`, `PUT`, `POST`, `DELETE`, | |
`PATCH`, `HEAD`, etc. | |
An HTTP Method (verb) defines how a request should be interpreted by a server. | |
The endpoints in this section demonstrate various HTTP Verbs. Postman supports | |
all the HTTP Verbs, including some rarely used ones, such as `PROPFIND`, `UNLINK`, | |
etc. | |
For details about HTTP Verbs, refer to [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9) | |
*/ | |
this["Request_Methods"] = { | |
/** | |
The HTTP `POST` request method is meant to transfer data to a server | |
(and elicit a response). What data is returned depends on the implementation | |
of the server. | |
A `POST` request can pass parameters to the server using "Query String | |
Parameters", as well as the Request Body. For example, in the following request, | |
> POST /hi/there?hand=wave | |
> | |
> <request-body> | |
The parameter "hand" has the value "wave". The request body can be in multiple | |
formats. These formats are defined by the MIME type of the request. The MIME | |
Type can be set using the ``Content-Type`` HTTP header. The most commonly used | |
MIME types are: | |
* `multipart/form-data` | |
* `application/x-www-form-urlencoded` | |
* `application/json` | |
This endpoint echoes the HTTP headers, request parameters, the contents of | |
the request body and the complete URI requested when data is sent as a form parameter. | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
@param {String} variables.var4 | |
@param {String} variables.var5 | |
*/ | |
"POST_Form_Data": function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var var4 = variables.var4 || self.variables.var4 || ''; | |
var var5 = variables.var5 || self.variables.var5 || ''; | |
var options = { | |
'method': 'POST', | |
'url': '' + url + '/post', | |
'headers': {}, | |
form: { | |
'foo1': '' + var4 + '', | |
'foo2': '' + var5 + '' | |
} | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
}, | |
/** | |
The HTTP `DELETE` method is used to delete resources on a server. The exact | |
use of `DELETE` requests depends on the server implementation. In general, | |
`DELETE` requests support both, Query String parameters as well as a Request | |
Body. | |
This endpoint accepts an HTTP `DELETE` request and provides debug information | |
such as the HTTP headers, Query String arguments, and the Request Body. | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
@param {String} variables.var1 | |
*/ | |
"DELETE_Request": function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var var1 = variables.var1 || self.variables.var1 || ''; | |
var options = { | |
'method': 'DELETE', | |
'url': '' + url + '/delete', | |
'headers': {}, | |
body: 'This is expected to be sent back as part of response body.' + var1 + '' | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
}, | |
/** | |
A set of `/time/*` mounted requests to perform date-time manipulations, among other operations. | |
*/ | |
"Utilities_/_Date_and_Time": { | |
/** | |
A simple `GET` request to `/time/between` to check if the provided timestamp is between a range specified by the `start` and `end` query parameters. A resolution limit can also be specified by the `unit` query parameter. | |
For instance, for a resolution `unit` of `month`, | |
`2016-10-05` does lie between `2016-11-02` and `2016-09-01`. | |
This endpoint also accepts `timestamp`, `locale`, `format`, `strict`, and `target` query parameters to construct the date time instance to check against. | |
Responses are provided in JSON format, with a `between` key to indicate the result. The response code is `200` for valid query parameters, and `400` otherwise. | |
``` | |
{ | |
between: true/false | |
} | |
``` | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
*/ | |
"Between_timestamps": function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var options = { | |
'method': 'GET', | |
'url': '' + url + '/time/between?timestamp=2016-10-10&start=2017-10-10&end=2019-10-10', | |
'headers': {} | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
}, | |
/** | |
A simple `GET` request to `/time/leap` to check if the provided/current timestamp belongs to a leap year. | |
This endpoint also accepts `timestamp`, `locale`, `format`, `strict`, and `target` query parameters to construct the date time instance to check against. | |
Responses are provided in JSON format, with a `leap` key to indicate the result. The response code is `200` for valid query parameters, and `400` otherwise. | |
``` | |
{ | |
leap: true/false | |
} | |
``` | |
@param {object} variables - Variables used for this request | |
@param {String} variables.url | |
*/ | |
"Leap_year_check": function (variables = {}) { | |
return new Promise((resolve, reject) => { | |
var url = variables.url || self.variables.url || ''; | |
var options = { | |
'method': 'GET', | |
'url': '' + url + '/time/leap?timestamp=2016-10-10', | |
'headers': {} | |
}; | |
request(options, function (error, response) { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(response); | |
}); | |
}); | |
} | |
} | |
}; | |
this.variables = this.setVariables(config); | |
} | |
/** | |
Method to retrieve current variable. | |
@param {string} [variable] - Variable name | |
@returns {Object} object containing variables | |
*/ | |
SDK.prototype.getVariables = function (variable) { | |
return variable ? this.variables[variable] : this.variables; | |
}; | |
/** | |
Function to set variables for entire SDK. These variables will override existing/default values. | |
@param {Object} Object containing env variables | |
*/ | |
SDK.prototype.setVariables = function (vars) { | |
let variables = JSON.parse(JSON.stringify(this.variables || configVariables)); | |
Object.keys(vars).forEach(function (key) { | |
variables[key] = vars[key]; | |
}); | |
this.variables = variables; | |
return this.variables; | |
}; | |
module.exports = SDK; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment