diff --git a/.gitignore b/.gitignore index a41c358..e5cb287 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ # OpenAPI Code gen artifacts .openapi-generator .openapi-generator-ignore +/node_modules +yarn.lock \ No newline at end of file diff --git a/.prettierignore b/.prettierignore index 1521c8b..53c37a1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1 @@ -dist +dist \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json index 32ebab4..81c51f9 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,4 +1,5 @@ { "singleQuote": true, - "trailingComma": "none" + "trailingComma": "none", + "semi": false } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3813895 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,44 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [1.1.0] - 2020-08-19 + +### Added + +- `project_id` optional field to `order` creation +- `metadata` optional field to `order` creation +- `project_id` optional field to `estimate` creation +- changelog file + +## [1.0.0] - 2020-07-31 + +### Added + +- This is the first official release of Patch's Node library. + +## [1.0.0-rc.2] - 2020-07-30 + +### Added + +- Pre-commit styling with Prettier + +### Changed + +- Corrects readme usage instructions +- Upgrades old version of superagent + +### Removed + +- Removes @babel/cli as a dependency + +## [1.0.0-rc.1] - 2020-07-29 + +### Added + +- Patch's first pre-release of our core javascript client library. diff --git a/README.md b/README.md index bca4be2..2ab80e9 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ After installing the package, you'll have to configure it with your API key whic ```javascript // ES6+ -import Patch from '@patch-technology/patch'; -const patch = Patch('key_test_1234'); +import Patch from '@patch-technology/patch' +const patch = Patch('key_test_1234') // ES5 -var patch = require('@patch-technology/patch').default('key_test_1234'); +var patch = require('@patch-technology/patch').default('key_test_1234') ``` ### Orders @@ -56,8 +56,16 @@ In Patch, orders represent a purchase of carbon offsets or negative emissions by const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne) patch.orders.createOrder({ mass_g: mass }) +// You can also specify a project-id field (optional) to be used instead of the preferred one +const projectId = 'pro_test_1234' // Pass in the project's ID +patch.orders.createOrder({ mass_g: mass, project_id: projectId }) + +// Orders also accept a metadata field (optional) +const metadata = { user: 'john doe' } +patch.orders.createOrder({ mass_g: mass, metadata: metadata }) + // Retrieve an order -orderId = 'ord_test_1234' // Pass in the order's id +const orderId = 'ord_test_1234' // Pass in the order's id patch.orders.retrieveOrder(orderId) // Place an order @@ -83,16 +91,20 @@ Estimates allow API users to get a quote for the cost of compensating a certain ```javascript // Create an estimate -const mass = 1000000; // Pass in the mass in grams (i.e. 1 metric tonne) -patch.estimates.createMassEstimate({ mass_g: mass }); +const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne) +patch.estimates.createMassEstimate({ mass_g: mass }) + +// You can also specify a project-id field (optional) to be used instead of the preferred one +const projectId = 'pro_test_1234' // Pass in the project's ID +patch.estimates.createMassEstimate({ mass_g: mass, project_id: projectId }) // Retrieve an estimate -const estimateId = 'est_test_1234'; -patch.estimates.retrieveEstimate(estimate_id); +const estimateId = 'est_test_1234' +patch.estimates.retrieveEstimate(estimate_id) // Retrieve a list of estimates -const page = 1; // Pass in which page of estimates you'd like -patch.estimates.retrieveEstimates({ page }); +const page = 1 // Pass in which page of estimates you'd like +patch.estimates.retrieveEstimates({ page }) ``` ### Projects @@ -105,12 +117,12 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores ```javascript // Retrieve a project -const projectId = 'pro_test_1234'; // Pass in the project's ID -patch.projects.retrieveProject(projectId); +const projectId = 'pro_test_1234' // Pass in the project's ID +patch.projects.retrieveProject(projectId) // Retrieve a list of projects -const page = 1; // Pass in which page of projects you'd like -patch.projects.retrieveProjects({ page }); +const page = 1 // Pass in which page of projects you'd like +patch.projects.retrieveProjects({ page }) ``` ### Preferences @@ -123,18 +135,44 @@ Preferences are how you route your orders in Patch. If you don't have a preferen ```javascript // Create a preference -const projectId = 'pro_test_1234'; // Pass in the project_id for your preference -patch.preferences.createPreference((project_id: projectId)); +const projectId = 'pro_test_1234' // Pass in the project_id for your preference +patch.preferences.createPreference({ project_id: projectId }) // Retrieve a preference -const preferenceId = 'pre_test_1234'; // Pass in the preferences's id -patch.preferences.retrievePreference(preferenceId); +const preferenceId = 'pre_test_1234' // Pass in the preferences's id +patch.preferences.retrievePreference(preferenceId) // Delete a preference -const preferenceId = 'pre_test_1234'; // Pass in the preferences's id -patch.preferences.deletePreference(preferenceId); +const preferenceId = 'pre_test_1234' // Pass in the preferences's id +patch.preferences.deletePreference(preferenceId) // Retrieve a list of preferences -const page = 1; // Pass in which page of preferences you'd like -patch.preferences.retrievePreferences({ page }); +const page = 1 // Pass in which page of preferences you'd like +patch.preferences.retrievePreferences({ page }) +``` + +## Development + +Install node modules + +``` +$ npm install +``` + +Set required environment variables: + +``` +$ export SANDBOX_API_KEY= +``` + +Build: + +``` +$ npm run build +``` + +Run tests: + +``` +$ npm test ``` diff --git a/dist/ApiClient.js b/dist/ApiClient.js index ef559bf..542e6f1 100644 --- a/dist/ApiClient.js +++ b/dist/ApiClient.js @@ -427,7 +427,7 @@ class ApiClient { hostSettings() { return [{ - url: 'https://api.usepatch.com', + url: 'https://{defaultHost}', description: 'No description provided', variables: { defaultHost: { diff --git a/dist/model/Allocation.js b/dist/model/Allocation.js index fea4642..5b4bd4e 100644 --- a/dist/model/Allocation.js +++ b/dist/model/Allocation.js @@ -16,11 +16,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Contact: developers@usepatch.com */ class Allocation { - constructor() { - Allocation.initialize(this); + constructor(id, production, massG) { + Allocation.initialize(this, id, production, massG); } - static initialize(obj) {} + static initialize(obj, id, production, massG) { + obj['id'] = id; + obj['production'] = production; + obj['mass_g'] = massG; + } static constructFromObject(data, obj) { if (data) { diff --git a/dist/model/CreateMassEstimateRequest.js b/dist/model/CreateMassEstimateRequest.js index 39acbb9..709125d 100644 --- a/dist/model/CreateMassEstimateRequest.js +++ b/dist/model/CreateMassEstimateRequest.js @@ -31,6 +31,10 @@ class CreateMassEstimateRequest { if (data.hasOwnProperty('mass_g')) { obj['mass_g'] = _ApiClient.default.convertToType(data['mass_g'], 'Number'); } + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = _ApiClient.default.convertToType(data['project_id'], 'String'); + } } return obj; @@ -39,5 +43,6 @@ class CreateMassEstimateRequest { } CreateMassEstimateRequest.prototype['mass_g'] = undefined; +CreateMassEstimateRequest.prototype['project_id'] = undefined; var _default = CreateMassEstimateRequest; exports.default = _default; \ No newline at end of file diff --git a/dist/model/CreateOrderRequest.js b/dist/model/CreateOrderRequest.js index af45f22..7ce6f2e 100644 --- a/dist/model/CreateOrderRequest.js +++ b/dist/model/CreateOrderRequest.js @@ -31,6 +31,14 @@ class CreateOrderRequest { if (data.hasOwnProperty('mass_g')) { obj['mass_g'] = _ApiClient.default.convertToType(data['mass_g'], 'Number'); } + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = _ApiClient.default.convertToType(data['project_id'], 'String'); + } + + if (data.hasOwnProperty('metadata')) { + obj['metadata'] = _ApiClient.default.convertToType(data['metadata'], Object); + } } return obj; @@ -39,5 +47,7 @@ class CreateOrderRequest { } CreateOrderRequest.prototype['mass_g'] = undefined; +CreateOrderRequest.prototype['project_id'] = undefined; +CreateOrderRequest.prototype['metadata'] = undefined; var _default = CreateOrderRequest; exports.default = _default; \ No newline at end of file diff --git a/dist/model/Estimate.js b/dist/model/Estimate.js index 765b918..bb28cf0 100644 --- a/dist/model/Estimate.js +++ b/dist/model/Estimate.js @@ -18,11 +18,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Contact: developers@usepatch.com */ class Estimate { - constructor() { - Estimate.initialize(this); + constructor(id, production, type) { + Estimate.initialize(this, id, production, type); } - static initialize(obj) {} + static initialize(obj, id, production, type) { + obj['id'] = id; + obj['production'] = production; + obj['type'] = type; + } static constructFromObject(data, obj) { if (data) { diff --git a/dist/model/Order.js b/dist/model/Order.js index 9b8495f..454a357 100644 --- a/dist/model/Order.js +++ b/dist/model/Order.js @@ -18,11 +18,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Contact: developers@usepatch.com */ class Order { - constructor() { - Order.initialize(this); + constructor(id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata) { + Order.initialize(this, id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata); } - static initialize(obj) {} + static initialize(obj, id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata) { + obj['id'] = id; + obj['mass_g'] = massG; + obj['production'] = production; + obj['state'] = state; + obj['allocation_state'] = allocationState; + obj['price_cents_usd'] = priceCentsUsd; + obj['allocations'] = allocations; + obj['metadata'] = metadata; + } static constructFromObject(data, obj) { if (data) { @@ -55,6 +64,10 @@ class Order { if (data.hasOwnProperty('allocations')) { obj['allocations'] = _ApiClient.default.convertToType(data['allocations'], [_Allocation.default]); } + + if (data.hasOwnProperty('metadata')) { + obj['metadata'] = _ApiClient.default.convertToType(data['metadata'], Object); + } } return obj; @@ -69,5 +82,6 @@ Order.prototype['state'] = undefined; Order.prototype['allocation_state'] = undefined; Order.prototype['price_cents_usd'] = undefined; Order.prototype['allocations'] = undefined; +Order.prototype['metadata'] = undefined; var _default = Order; exports.default = _default; \ No newline at end of file diff --git a/dist/model/Preference.js b/dist/model/Preference.js index 0ea5883..4eedf03 100644 --- a/dist/model/Preference.js +++ b/dist/model/Preference.js @@ -18,11 +18,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Contact: developers@usepatch.com */ class Preference { - constructor() { - Preference.initialize(this); + constructor(id, allocationPercentage, project) { + Preference.initialize(this, id, allocationPercentage, project); } - static initialize(obj) {} + static initialize(obj, id, allocationPercentage, project) { + obj['id'] = id; + obj['allocation_percentage'] = allocationPercentage; + obj['project'] = project; + } static constructFromObject(data, obj) { if (data) { diff --git a/dist/model/Project.js b/dist/model/Project.js index 490edae..b20ddb3 100644 --- a/dist/model/Project.js +++ b/dist/model/Project.js @@ -16,11 +16,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Contact: developers@usepatch.com */ class Project { - constructor() { - Project.initialize(this); + constructor(id, production, name, description, country, developer) { + Project.initialize(this, id, production, name, description, country, developer); } - static initialize(obj) {} + static initialize(obj, id, production, name, description, country, developer) { + obj['id'] = id; + obj['production'] = production; + obj['name'] = name; + obj['description'] = description; + obj['country'] = country; + obj['developer'] = developer; + } static constructFromObject(data, obj) { if (data) { @@ -42,20 +49,12 @@ class Project { obj['description'] = _ApiClient.default.convertToType(data['description'], 'String'); } - if (data.hasOwnProperty('country')) { - obj['country'] = _ApiClient.default.convertToType(data['country'], 'String'); - } - - if (data.hasOwnProperty('longitude')) { - obj['longitude'] = _ApiClient.default.convertToType(data['longitude'], 'Number'); + if (data.hasOwnProperty('type')) { + obj['type'] = _ApiClient.default.convertToType(data['type'], 'String'); } - if (data.hasOwnProperty('latitude')) { - obj['latitude'] = _ApiClient.default.convertToType(data['latitude'], 'Number'); - } - - if (data.hasOwnProperty('verifier')) { - obj['verifier'] = _ApiClient.default.convertToType(data['verifier'], 'String'); + if (data.hasOwnProperty('country')) { + obj['country'] = _ApiClient.default.convertToType(data['country'], 'String'); } if (data.hasOwnProperty('developer')) { @@ -72,10 +71,8 @@ Project.prototype['id'] = undefined; Project.prototype['production'] = undefined; Project.prototype['name'] = undefined; Project.prototype['description'] = undefined; +Project.prototype['type'] = undefined; Project.prototype['country'] = undefined; -Project.prototype['longitude'] = undefined; -Project.prototype['latitude'] = undefined; -Project.prototype['verifier'] = undefined; Project.prototype['developer'] = undefined; var _default = Project; exports.default = _default; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3dee2e1..594a305 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.0.0-rc.2", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6e73c31..633dbb3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.0.0", + "version": "1.1.0", "description": "Javascript wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index 3e3fd9d..814b2ed 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -5,24 +5,24 @@ * Contact: developers@usepatch.com */ -import superagent from 'superagent'; -import querystring from 'querystring'; +import superagent from 'superagent' +import querystring from 'querystring' class ApiClient { constructor() { - this.basePath = 'https://api.usepatch.com'.replace(/\/+$/, ''); + this.basePath = 'https://api.usepatch.com'.replace(/\/+$/, '') this.authentications = { bearer_auth: { type: 'bearer' } - }; + } - this.defaultHeaders = {}; + this.defaultHeaders = {} /** * The default HTTP timeout for all API calls. * @type {Number} * @default 60000 */ - this.timeout = 60000; + this.timeout = 60000 /** * If set to false an additional timestamp parameter is added to all API GET calls to @@ -30,201 +30,201 @@ class ApiClient { * @type {Boolean} * @default true */ - this.cache = true; + this.cache = true - this.enableCookies = false; + this.enableCookies = false /* * Used to save and return cookies in a node.js (non-browser) setting, * if this.enableCookies is set to true. */ if (typeof window === 'undefined') { - this.agent = new superagent.agent(); + this.agent = new superagent.agent() } /* * Allow user to override superagent agent */ - this.requestAgent = null; + this.requestAgent = null /* * Allow user to add superagent plugins */ - this.plugins = null; + this.plugins = null } paramToString(param) { if (param == undefined || param == null) { - return ''; + return '' } if (param instanceof Date) { - return param.toJSON(); + return param.toJSON() } - return param.toString(); + return param.toString() } buildUrl(path, pathParams) { if (!path.match(/^\//)) { - path = '/' + path; + path = '/' + path } - var url = this.basePath + path; + var url = this.basePath + path url = url.replace(/\{([\w-]+)\}/g, (fullMatch, key) => { - var value; + var value if (pathParams.hasOwnProperty(key)) { - value = this.paramToString(pathParams[key]); + value = this.paramToString(pathParams[key]) } else { - value = fullMatch; + value = fullMatch } - return encodeURIComponent(value); - }); + return encodeURIComponent(value) + }) - return url; + return url } isJsonMime(contentType) { return Boolean( contentType != null && contentType.match(/^application\/json(;.*)?$/i) - ); + ) } jsonPreferredMime(contentTypes) { for (var i = 0; i < contentTypes.length; i++) { if (this.isJsonMime(contentTypes[i])) { - return contentTypes[i]; + return contentTypes[i] } } - return contentTypes[0]; + return contentTypes[0] } isFileParam(param) { // fs.ReadStream in Node.js and Electron (but not in runtime like browserify) if (typeof require === 'function') { - let fs; + let fs try { - fs = require('fs'); + fs = require('fs') } catch (err) {} if (fs && fs.ReadStream && param instanceof fs.ReadStream) { - return true; + return true } } // Buffer in Node.js if (typeof Buffer === 'function' && param instanceof Buffer) { - return true; + return true } // Blob in browser if (typeof Blob === 'function' && param instanceof Blob) { - return true; + return true } // File in browser (it seems File object is also instance of Blob, but keep this for safe) if (typeof File === 'function' && param instanceof File) { - return true; + return true } - return false; + return false } normalizeParams(params) { - var newParams = {}; + var newParams = {} for (var key in params) { if ( params.hasOwnProperty(key) && params[key] != undefined && params[key] != null ) { - var value = params[key]; + var value = params[key] if (this.isFileParam(value) || Array.isArray(value)) { - newParams[key] = value; + newParams[key] = value } else { - newParams[key] = this.paramToString(value); + newParams[key] = this.paramToString(value) } } } - return newParams; + return newParams } buildCollectionParam(param, collectionFormat) { if (param == null) { - return null; + return null } switch (collectionFormat) { case 'csv': - return param.map(this.paramToString).join(','); + return param.map(this.paramToString).join(',') case 'ssv': - return param.map(this.paramToString).join(' '); + return param.map(this.paramToString).join(' ') case 'tsv': - return param.map(this.paramToString).join('\t'); + return param.map(this.paramToString).join('\t') case 'pipes': - return param.map(this.paramToString).join('|'); + return param.map(this.paramToString).join('|') case 'multi': //return the array directly as SuperAgent will handle it as expected - return param.map(this.paramToString); + return param.map(this.paramToString) default: - throw new Error('Unknown collection format: ' + collectionFormat); + throw new Error('Unknown collection format: ' + collectionFormat) } } applyAuthToRequest(request, authNames) { authNames.forEach((authName) => { - var auth = this.authentications[authName]; + var auth = this.authentications[authName] switch (auth.type) { case 'basic': if (auth.username || auth.password) { - request.auth(auth.username || '', auth.password || ''); + request.auth(auth.username || '', auth.password || '') } - break; + break case 'bearer': if (auth.accessToken) { - request.set({ Authorization: 'Bearer ' + auth.accessToken }); + request.set({ Authorization: 'Bearer ' + auth.accessToken }) } - break; + break case 'apiKey': if (auth.apiKey) { - var data = {}; + var data = {} if (auth.apiKeyPrefix) { - data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey; + data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey } else { - data[auth.name] = auth.apiKey; + data[auth.name] = auth.apiKey } if (auth['in'] === 'header') { - request.set(data); + request.set(data) } else { - request.query(data); + request.query(data) } } - break; + break case 'oauth2': if (auth.accessToken) { - request.set({ Authorization: 'Bearer ' + auth.accessToken }); + request.set({ Authorization: 'Bearer ' + auth.accessToken }) } - break; + break default: - throw new Error('Unknown authentication type: ' + auth.type); + throw new Error('Unknown authentication type: ' + auth.type) } - }); + }) } deserialize(response, returnType) { if (response == null || returnType == null || response.status == 204) { - return null; + return null } // Rely on SuperAgent for parsing response body. // See http://visionmedia.github.io/superagent/#parsing-response-bodies - var data = response.body; + var data = response.body if ( data == null || (typeof data === 'object' && @@ -232,10 +232,10 @@ class ApiClient { !Object.keys(data).length) ) { // SuperAgent does not always produce a body; use the unparsed response as a fallback - data = response.text; + data = response.text } - return ApiClient.convertToType(data, returnType); + return ApiClient.convertToType(data, returnType) } callApi( @@ -251,159 +251,159 @@ class ApiClient { accepts, returnType ) { - var url = this.buildUrl(path, pathParams); - var request = superagent(httpMethod, url); + var url = this.buildUrl(path, pathParams) + var request = superagent(httpMethod, url) if (this.plugins !== null) { for (var index in this.plugins) { if (this.plugins.hasOwnProperty(index)) { - request.use(this.plugins[index]); + request.use(this.plugins[index]) } } } // apply authentications - this.applyAuthToRequest(request, authNames); + this.applyAuthToRequest(request, authNames) // set query parameters if (httpMethod.toUpperCase() === 'GET' && this.cache === false) { - queryParams['_'] = new Date().getTime(); + queryParams['_'] = new Date().getTime() } - request.query(this.normalizeParams(queryParams)); + request.query(this.normalizeParams(queryParams)) // set header parameters - request.set(this.defaultHeaders).set(this.normalizeParams(headerParams)); + request.set(this.defaultHeaders).set(this.normalizeParams(headerParams)) // set requestAgent if it is set by user if (this.requestAgent) { - request.agent(this.requestAgent); + request.agent(this.requestAgent) } // set request timeout - request.timeout(this.timeout); + request.timeout(this.timeout) - var contentType = this.jsonPreferredMime(contentTypes); + var contentType = this.jsonPreferredMime(contentTypes) if (contentType) { // Issue with superagent and multipart/form-data (https://github.com/visionmedia/superagent/issues/746) if (contentType != 'multipart/form-data') { - request.type(contentType); + request.type(contentType) } } else if (!request.header['Content-Type']) { - request.type('application/json'); + request.type('application/json') } if (contentType === 'application/x-www-form-urlencoded') { - request.send(querystring.stringify(this.normalizeParams(formParams))); + request.send(querystring.stringify(this.normalizeParams(formParams))) } else if (contentType == 'multipart/form-data') { - var _formParams = this.normalizeParams(formParams); + var _formParams = this.normalizeParams(formParams) for (var key in _formParams) { if (_formParams.hasOwnProperty(key)) { if (this.isFileParam(_formParams[key])) { // file field - request.attach(key, _formParams[key]); + request.attach(key, _formParams[key]) } else { - request.field(key, _formParams[key]); + request.field(key, _formParams[key]) } } } } else if (bodyParam !== null && bodyParam !== undefined) { - request.send(bodyParam); + request.send(bodyParam) } - var accept = this.jsonPreferredMime(accepts); + var accept = this.jsonPreferredMime(accepts) if (accept) { - request.accept(accept); + request.accept(accept) } if (returnType === 'Blob') { - request.responseType('blob'); + request.responseType('blob') } else if (returnType === 'String') { - request.responseType('string'); + request.responseType('string') } // Attach previously saved cookies, if enabled if (this.enableCookies) { if (typeof window === 'undefined') { - this.agent._attachCookies(request); + this.agent._attachCookies(request) } else { - request.withCredentials(); + request.withCredentials() } } return new Promise((resolve, reject) => { request.end((error, response) => { - var data = this.deserialize(response, returnType); + var data = this.deserialize(response, returnType) if (error) { - reject(data); + reject(data) } else { if (this.enableCookies && typeof window === 'undefined') { - this.agent._saveCookies(response); + this.agent._saveCookies(response) } - resolve(data); + resolve(data) } - }); - }); + }) + }) } static parseDate(str) { - return new Date(str); + return new Date(str) } static convertToType(data, type) { - if (data === null || data === undefined) return data; + if (data === null || data === undefined) return data switch (type) { case 'Boolean': - return Boolean(data); + return Boolean(data) case 'Integer': - return parseInt(data, 10); + return parseInt(data, 10) case 'Number': - return parseFloat(data); + return parseFloat(data) case 'String': - return String(data); + return String(data) case 'Date': - return ApiClient.parseDate(String(data)); + return ApiClient.parseDate(String(data)) case 'Blob': - return data; + return data default: if (type === Object) { // generic object, return directly - return data; + return data } else if (typeof type.constructFromObject === 'function') { // for model type like User and enum class - return type.constructFromObject(data); + return type.constructFromObject(data) } else if (Array.isArray(type)) { // for array type like: ['String'] - var itemType = type[0]; + var itemType = type[0] return data.map((item) => { - return ApiClient.convertToType(item, itemType); - }); + return ApiClient.convertToType(item, itemType) + }) } else if (typeof type === 'object') { // for plain object type like: {'String': 'Integer'} - var keyType, valueType; + var keyType, valueType for (var k in type) { if (type.hasOwnProperty(k)) { - keyType = k; - valueType = type[k]; - break; + keyType = k + valueType = type[k] + break } } - var result = {}; + var result = {} for (var k in data) { if (data.hasOwnProperty(k)) { - var key = ApiClient.convertToType(k, keyType); - var value = ApiClient.convertToType(data[k], valueType); - result[key] = value; + var key = ApiClient.convertToType(k, keyType) + var value = ApiClient.convertToType(data[k], valueType) + result[key] = value } } - return result; + return result } else { // for unknown type, return the data directly - return data; + return data } } } @@ -411,7 +411,7 @@ class ApiClient { hostSettings() { return [ { - url: 'https://api.usepatch.com', + url: 'https://{defaultHost}', description: 'No description provided', variables: { @@ -422,11 +422,11 @@ class ApiClient { } } } - ]; + ] } getBasePathFromSettings(index, variables = {}) { - var servers = this.hostSettings(); + var servers = this.hostSettings() // check array index out of bound if (index < 0 || index >= servers.length) { @@ -435,24 +435,21 @@ class ApiClient { index + ' when selecting the host settings. Must be less than ' + servers.length - ); + ) } - var server = servers[index]; - var url = server['url']; + var server = servers[index] + var url = server['url'] // go through variable and assign a value for (var variable_name in server['variables']) { if (variable_name in variables) { - let variable = server['variables'][variable_name]; + let variable = server['variables'][variable_name] if ( !('enum_values' in variable) || variable['enum_values'].includes(variables[variable_name]) ) { - url = url.replace( - '{' + variable_name + '}', - variables[variable_name] - ); + url = url.replace('{' + variable_name + '}', variables[variable_name]) } else { throw new Error( 'The variable `' + @@ -462,29 +459,29 @@ class ApiClient { '. Must be ' + server['variables'][variable_name]['enum_values'] + '.' - ); + ) } } else { // use default value url = url.replace( '{' + variable_name + '}', server['variables'][variable_name]['default_value'] - ); + ) } } - return url; + return url } static constructFromObject(data, obj, itemType) { if (Array.isArray(data)) { for (var i = 0; i < data.length; i++) { if (data.hasOwnProperty(i)) - obj[i] = ApiClient.convertToType(data[i], itemType); + obj[i] = ApiClient.convertToType(data[i], itemType) } } else { for (var k in data) { if (data.hasOwnProperty(k)) - obj[k] = ApiClient.convertToType(data[k], itemType); + obj[k] = ApiClient.convertToType(data[k], itemType) } } } @@ -496,7 +493,7 @@ ApiClient.CollectionFormatEnum = { TSV: '\t', PIPES: '|', MULTI: 'multi' -}; +} -ApiClient.instance = new ApiClient(); -export default ApiClient; +ApiClient.instance = new ApiClient() +export default ApiClient diff --git a/src/api/EstimatesApi.js b/src/api/EstimatesApi.js index e7f9254..d5e29e1 100644 --- a/src/api/EstimatesApi.js +++ b/src/api/EstimatesApi.js @@ -5,31 +5,31 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest'; -import ErrorResponse from '../model/ErrorResponse'; -import EstimateListResponse from '../model/EstimateListResponse'; -import EstimateResponse from '../model/EstimateResponse'; +import ApiClient from '../ApiClient' +import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest' +import ErrorResponse from '../model/ErrorResponse' +import EstimateListResponse from '../model/EstimateListResponse' +import EstimateResponse from '../model/EstimateResponse' export default class EstimatesApi { constructor(apiClient) { - this.apiClient = apiClient || ApiClient.instance; - this.createMassEstimate = this.createMassEstimate.bind(this); + this.apiClient = apiClient || ApiClient.instance + this.createMassEstimate = this.createMassEstimate.bind(this) this.createMassEstimateWithHttpInfo = this.createMassEstimateWithHttpInfo.bind( this - ); - this.retrieveEstimate = this.retrieveEstimate.bind(this); + ) + this.retrieveEstimate = this.retrieveEstimate.bind(this) this.retrieveEstimateWithHttpInfo = this.retrieveEstimateWithHttpInfo.bind( this - ); - this.retrieveEstimates = this.retrieveEstimates.bind(this); + ) + this.retrieveEstimates = this.retrieveEstimates.bind(this) this.retrieveEstimatesWithHttpInfo = this.retrieveEstimatesWithHttpInfo.bind( this - ); + ) } createMassEstimateWithHttpInfo(createMassEstimateRequest) { - let postBody = createMassEstimateRequest; + let postBody = createMassEstimateRequest // verify the required parameter 'createMassEstimateRequest' is set if ( @@ -38,18 +38,18 @@ export default class EstimatesApi { ) { throw new Error( "Missing the required parameter 'createMassEstimateRequest' when calling createMassEstimate" - ); + ) } - let pathParams = {}; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + let pathParams = {} + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = ['application/json']; - let accepts = ['application/json']; - let returnType = EstimateResponse; + let authNames = ['bearer_auth'] + let contentTypes = ['application/json'] + let accepts = ['application/json'] + let returnType = EstimateResponse return this.apiClient.callApi( '/v1/estimates/mass', @@ -63,34 +63,34 @@ export default class EstimatesApi { contentTypes, accepts, returnType - ); + ) } createMassEstimate(createMassEstimateRequest) { - return this.createMassEstimateWithHttpInfo(createMassEstimateRequest); + return this.createMassEstimateWithHttpInfo(createMassEstimateRequest) } retrieveEstimateWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling retrieveEstimate" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = EstimateResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = EstimateResponse return this.apiClient.callApi( '/v1/estimates/{id}', @@ -104,29 +104,29 @@ export default class EstimatesApi { contentTypes, accepts, returnType - ); + ) } retrieveEstimate(id) { - return this.retrieveEstimateWithHttpInfo(id); + return this.retrieveEstimateWithHttpInfo(id) } retrieveEstimatesWithHttpInfo(opts) { - opts = opts || {}; + opts = opts || {} - let postBody = null; + let postBody = null - let pathParams = {}; + let pathParams = {} let queryParams = { page: opts['page'] - }; - let headerParams = {}; - let formParams = {}; + } + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = EstimateListResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = EstimateListResponse return this.apiClient.callApi( '/v1/estimates', @@ -140,10 +140,10 @@ export default class EstimatesApi { contentTypes, accepts, returnType - ); + ) } retrieveEstimates(opts) { - return this.retrieveEstimatesWithHttpInfo(opts); + return this.retrieveEstimatesWithHttpInfo(opts) } } diff --git a/src/api/OrdersApi.js b/src/api/OrdersApi.js index 7b0fc6f..d6ea16d 100644 --- a/src/api/OrdersApi.js +++ b/src/api/OrdersApi.js @@ -5,50 +5,48 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import CreateOrderRequest from '../model/CreateOrderRequest'; -import ErrorResponse from '../model/ErrorResponse'; -import OrderListResponse from '../model/OrderListResponse'; -import OrderResponse from '../model/OrderResponse'; +import ApiClient from '../ApiClient' +import CreateOrderRequest from '../model/CreateOrderRequest' +import ErrorResponse from '../model/ErrorResponse' +import OrderListResponse from '../model/OrderListResponse' +import OrderResponse from '../model/OrderResponse' export default class OrdersApi { constructor(apiClient) { - this.apiClient = apiClient || ApiClient.instance; - this.cancelOrder = this.cancelOrder.bind(this); - this.cancelOrderWithHttpInfo = this.cancelOrderWithHttpInfo.bind(this); - this.createOrder = this.createOrder.bind(this); - this.createOrderWithHttpInfo = this.createOrderWithHttpInfo.bind(this); - this.placeOrder = this.placeOrder.bind(this); - this.placeOrderWithHttpInfo = this.placeOrderWithHttpInfo.bind(this); - this.retrieveOrder = this.retrieveOrder.bind(this); - this.retrieveOrderWithHttpInfo = this.retrieveOrderWithHttpInfo.bind(this); - this.retrieveOrders = this.retrieveOrders.bind(this); - this.retrieveOrdersWithHttpInfo = this.retrieveOrdersWithHttpInfo.bind( - this - ); + this.apiClient = apiClient || ApiClient.instance + this.cancelOrder = this.cancelOrder.bind(this) + this.cancelOrderWithHttpInfo = this.cancelOrderWithHttpInfo.bind(this) + this.createOrder = this.createOrder.bind(this) + this.createOrderWithHttpInfo = this.createOrderWithHttpInfo.bind(this) + this.placeOrder = this.placeOrder.bind(this) + this.placeOrderWithHttpInfo = this.placeOrderWithHttpInfo.bind(this) + this.retrieveOrder = this.retrieveOrder.bind(this) + this.retrieveOrderWithHttpInfo = this.retrieveOrderWithHttpInfo.bind(this) + this.retrieveOrders = this.retrieveOrders.bind(this) + this.retrieveOrdersWithHttpInfo = this.retrieveOrdersWithHttpInfo.bind(this) } cancelOrderWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling cancelOrder" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = OrderResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = OrderResponse return this.apiClient.callApi( '/v1/orders/{id}/cancel', @@ -62,32 +60,32 @@ export default class OrdersApi { contentTypes, accepts, returnType - ); + ) } cancelOrder(id) { - return this.cancelOrderWithHttpInfo(id); + return this.cancelOrderWithHttpInfo(id) } createOrderWithHttpInfo(createOrderRequest) { - let postBody = createOrderRequest; + let postBody = createOrderRequest // verify the required parameter 'createOrderRequest' is set if (createOrderRequest === undefined || createOrderRequest === null) { throw new Error( "Missing the required parameter 'createOrderRequest' when calling createOrder" - ); + ) } - let pathParams = {}; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + let pathParams = {} + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = ['application/json']; - let accepts = ['application/json']; - let returnType = OrderResponse; + let authNames = ['bearer_auth'] + let contentTypes = ['application/json'] + let accepts = ['application/json'] + let returnType = OrderResponse return this.apiClient.callApi( '/v1/orders', @@ -101,34 +99,34 @@ export default class OrdersApi { contentTypes, accepts, returnType - ); + ) } createOrder(createOrderRequest) { - return this.createOrderWithHttpInfo(createOrderRequest); + return this.createOrderWithHttpInfo(createOrderRequest) } placeOrderWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling placeOrder" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = OrderResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = OrderResponse return this.apiClient.callApi( '/v1/orders/{id}/place', @@ -142,34 +140,34 @@ export default class OrdersApi { contentTypes, accepts, returnType - ); + ) } placeOrder(id) { - return this.placeOrderWithHttpInfo(id); + return this.placeOrderWithHttpInfo(id) } retrieveOrderWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling retrieveOrder" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = OrderResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = OrderResponse return this.apiClient.callApi( '/v1/orders/{id}', @@ -183,29 +181,29 @@ export default class OrdersApi { contentTypes, accepts, returnType - ); + ) } retrieveOrder(id) { - return this.retrieveOrderWithHttpInfo(id); + return this.retrieveOrderWithHttpInfo(id) } retrieveOrdersWithHttpInfo(opts) { - opts = opts || {}; + opts = opts || {} - let postBody = null; + let postBody = null - let pathParams = {}; + let pathParams = {} let queryParams = { page: opts['page'] - }; - let headerParams = {}; - let formParams = {}; + } + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = OrderListResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = OrderListResponse return this.apiClient.callApi( '/v1/orders', @@ -219,10 +217,10 @@ export default class OrdersApi { contentTypes, accepts, returnType - ); + ) } retrieveOrders(opts) { - return this.retrieveOrdersWithHttpInfo(opts); + return this.retrieveOrdersWithHttpInfo(opts) } } diff --git a/src/api/PreferencesApi.js b/src/api/PreferencesApi.js index 5d2bc82..b6d56eb 100644 --- a/src/api/PreferencesApi.js +++ b/src/api/PreferencesApi.js @@ -5,35 +5,35 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import CreatePreferenceRequest from '../model/CreatePreferenceRequest'; -import ErrorResponse from '../model/ErrorResponse'; -import PreferenceListResponse from '../model/PreferenceListResponse'; -import PreferenceResponse from '../model/PreferenceResponse'; +import ApiClient from '../ApiClient' +import CreatePreferenceRequest from '../model/CreatePreferenceRequest' +import ErrorResponse from '../model/ErrorResponse' +import PreferenceListResponse from '../model/PreferenceListResponse' +import PreferenceResponse from '../model/PreferenceResponse' export default class PreferencesApi { constructor(apiClient) { - this.apiClient = apiClient || ApiClient.instance; - this.createPreference = this.createPreference.bind(this); + this.apiClient = apiClient || ApiClient.instance + this.createPreference = this.createPreference.bind(this) this.createPreferenceWithHttpInfo = this.createPreferenceWithHttpInfo.bind( this - ); - this.deletePreference = this.deletePreference.bind(this); + ) + this.deletePreference = this.deletePreference.bind(this) this.deletePreferenceWithHttpInfo = this.deletePreferenceWithHttpInfo.bind( this - ); - this.retrievePreference = this.retrievePreference.bind(this); + ) + this.retrievePreference = this.retrievePreference.bind(this) this.retrievePreferenceWithHttpInfo = this.retrievePreferenceWithHttpInfo.bind( this - ); - this.retrievePreferences = this.retrievePreferences.bind(this); + ) + this.retrievePreferences = this.retrievePreferences.bind(this) this.retrievePreferencesWithHttpInfo = this.retrievePreferencesWithHttpInfo.bind( this - ); + ) } createPreferenceWithHttpInfo(createPreferenceRequest) { - let postBody = createPreferenceRequest; + let postBody = createPreferenceRequest // verify the required parameter 'createPreferenceRequest' is set if ( @@ -42,18 +42,18 @@ export default class PreferencesApi { ) { throw new Error( "Missing the required parameter 'createPreferenceRequest' when calling createPreference" - ); + ) } - let pathParams = {}; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + let pathParams = {} + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = ['application/json']; - let accepts = ['application/json']; - let returnType = PreferenceResponse; + let authNames = ['bearer_auth'] + let contentTypes = ['application/json'] + let accepts = ['application/json'] + let returnType = PreferenceResponse return this.apiClient.callApi( '/v1/preferences', @@ -67,34 +67,34 @@ export default class PreferencesApi { contentTypes, accepts, returnType - ); + ) } createPreference(createPreferenceRequest) { - return this.createPreferenceWithHttpInfo(createPreferenceRequest); + return this.createPreferenceWithHttpInfo(createPreferenceRequest) } deletePreferenceWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling deletePreference" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = PreferenceResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = PreferenceResponse return this.apiClient.callApi( '/v1/preferences/{id}', @@ -108,34 +108,34 @@ export default class PreferencesApi { contentTypes, accepts, returnType - ); + ) } deletePreference(id) { - return this.deletePreferenceWithHttpInfo(id); + return this.deletePreferenceWithHttpInfo(id) } retrievePreferenceWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling retrievePreference" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = PreferenceResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = PreferenceResponse return this.apiClient.callApi( '/v1/preferences/{id}', @@ -149,29 +149,29 @@ export default class PreferencesApi { contentTypes, accepts, returnType - ); + ) } retrievePreference(id) { - return this.retrievePreferenceWithHttpInfo(id); + return this.retrievePreferenceWithHttpInfo(id) } retrievePreferencesWithHttpInfo(opts) { - opts = opts || {}; + opts = opts || {} - let postBody = null; + let postBody = null - let pathParams = {}; + let pathParams = {} let queryParams = { page: opts['page'] - }; - let headerParams = {}; - let formParams = {}; + } + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = PreferenceListResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = PreferenceListResponse return this.apiClient.callApi( '/v1/preferences', @@ -185,10 +185,10 @@ export default class PreferencesApi { contentTypes, accepts, returnType - ); + ) } retrievePreferences(opts) { - return this.retrievePreferencesWithHttpInfo(opts); + return this.retrievePreferencesWithHttpInfo(opts) } } diff --git a/src/api/ProjectsApi.js b/src/api/ProjectsApi.js index 9752160..1911fad 100644 --- a/src/api/ProjectsApi.js +++ b/src/api/ProjectsApi.js @@ -5,45 +5,45 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import ErrorResponse from '../model/ErrorResponse'; -import ProjectListResponse from '../model/ProjectListResponse'; -import ProjectResponse from '../model/ProjectResponse'; +import ApiClient from '../ApiClient' +import ErrorResponse from '../model/ErrorResponse' +import ProjectListResponse from '../model/ProjectListResponse' +import ProjectResponse from '../model/ProjectResponse' export default class ProjectsApi { constructor(apiClient) { - this.apiClient = apiClient || ApiClient.instance; - this.retrieveProject = this.retrieveProject.bind(this); + this.apiClient = apiClient || ApiClient.instance + this.retrieveProject = this.retrieveProject.bind(this) this.retrieveProjectWithHttpInfo = this.retrieveProjectWithHttpInfo.bind( this - ); - this.retrieveProjects = this.retrieveProjects.bind(this); + ) + this.retrieveProjects = this.retrieveProjects.bind(this) this.retrieveProjectsWithHttpInfo = this.retrieveProjectsWithHttpInfo.bind( this - ); + ) } retrieveProjectWithHttpInfo(id) { - let postBody = null; + let postBody = null // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( "Missing the required parameter 'id' when calling retrieveProject" - ); + ) } let pathParams = { id: id - }; - let queryParams = {}; - let headerParams = {}; - let formParams = {}; + } + let queryParams = {} + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = ProjectResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = ProjectResponse return this.apiClient.callApi( '/v1/projects/{id}', @@ -57,29 +57,29 @@ export default class ProjectsApi { contentTypes, accepts, returnType - ); + ) } retrieveProject(id) { - return this.retrieveProjectWithHttpInfo(id); + return this.retrieveProjectWithHttpInfo(id) } retrieveProjectsWithHttpInfo(opts) { - opts = opts || {}; + opts = opts || {} - let postBody = null; + let postBody = null - let pathParams = {}; + let pathParams = {} let queryParams = { page: opts['page'] - }; - let headerParams = {}; - let formParams = {}; + } + let headerParams = {} + let formParams = {} - let authNames = ['bearer_auth']; - let contentTypes = []; - let accepts = ['application/json']; - let returnType = ProjectListResponse; + let authNames = ['bearer_auth'] + let contentTypes = [] + let accepts = ['application/json'] + let returnType = ProjectListResponse return this.apiClient.callApi( '/v1/projects', @@ -93,10 +93,10 @@ export default class ProjectsApi { contentTypes, accepts, returnType - ); + ) } retrieveProjects(opts) { - return this.retrieveProjectsWithHttpInfo(opts); + return this.retrieveProjectsWithHttpInfo(opts) } } diff --git a/src/index.js b/src/index.js index b910f9a..e75b822 100644 --- a/src/index.js +++ b/src/index.js @@ -5,23 +5,23 @@ * Contact: developers@usepatch.com */ -import ApiClient from './ApiClient'; -import EstimatesApi from './api/EstimatesApi'; -import OrdersApi from './api/OrdersApi'; -import PreferencesApi from './api/PreferencesApi'; -import ProjectsApi from './api/ProjectsApi'; +import ApiClient from './ApiClient' +import EstimatesApi from './api/EstimatesApi' +import OrdersApi from './api/OrdersApi' +import PreferencesApi from './api/PreferencesApi' +import ProjectsApi from './api/ProjectsApi' export default function Patch(accessToken) { - if (!(this instanceof Patch)) return new Patch(accessToken); + if (!(this instanceof Patch)) return new Patch(accessToken) - this.client = ApiClient.instance; - this.client.authentications['bearer_auth'].accessToken = accessToken; + this.client = ApiClient.instance + this.client.authentications['bearer_auth'].accessToken = accessToken - this.estimates = new EstimatesApi(this.client); + this.estimates = new EstimatesApi(this.client) - this.orders = new OrdersApi(this.client); + this.orders = new OrdersApi(this.client) - this.preferences = new PreferencesApi(this.client); + this.preferences = new PreferencesApi(this.client) - this.projects = new ProjectsApi(this.client); + this.projects = new ProjectsApi(this.client) } diff --git a/src/model/Allocation.js b/src/model/Allocation.js index 98476c9..04c49a1 100644 --- a/src/model/Allocation.js +++ b/src/model/Allocation.js @@ -5,42 +5,46 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class Allocation { - constructor() { - Allocation.initialize(this); + constructor(id, production, massG) { + Allocation.initialize(this, id, production, massG) } - static initialize(obj) {} + static initialize(obj, id, production, massG) { + obj['id'] = id + obj['production'] = production + obj['mass_g'] = massG + } static constructFromObject(data, obj) { if (data) { - obj = obj || new Allocation(); + obj = obj || new Allocation() if (data.hasOwnProperty('id')) { - obj['id'] = ApiClient.convertToType(data['id'], 'String'); + obj['id'] = ApiClient.convertToType(data['id'], 'String') } if (data.hasOwnProperty('production')) { obj['production'] = ApiClient.convertToType( data['production'], 'Boolean' - ); + ) } if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); + obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number') } } - return obj; + return obj } } -Allocation.prototype['id'] = undefined; +Allocation.prototype['id'] = undefined -Allocation.prototype['production'] = undefined; +Allocation.prototype['production'] = undefined -Allocation.prototype['mass_g'] = undefined; +Allocation.prototype['mass_g'] = undefined -export default Allocation; +export default Allocation diff --git a/src/model/CreateMassEstimateRequest.js b/src/model/CreateMassEstimateRequest.js index 1382eca..5e966c8 100644 --- a/src/model/CreateMassEstimateRequest.js +++ b/src/model/CreateMassEstimateRequest.js @@ -5,29 +5,38 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class CreateMassEstimateRequest { constructor(massG) { - CreateMassEstimateRequest.initialize(this, massG); + CreateMassEstimateRequest.initialize(this, massG) } static initialize(obj, massG) { - obj['mass_g'] = massG; + obj['mass_g'] = massG } static constructFromObject(data, obj) { if (data) { - obj = obj || new CreateMassEstimateRequest(); + obj = obj || new CreateMassEstimateRequest() if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); + obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number') + } + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = ApiClient.convertToType( + data['project_id'], + 'String' + ) } } - return obj; + return obj } } -CreateMassEstimateRequest.prototype['mass_g'] = undefined; +CreateMassEstimateRequest.prototype['mass_g'] = undefined + +CreateMassEstimateRequest.prototype['project_id'] = undefined -export default CreateMassEstimateRequest; +export default CreateMassEstimateRequest diff --git a/src/model/CreateOrderRequest.js b/src/model/CreateOrderRequest.js index 49277f5..bb4a5a9 100644 --- a/src/model/CreateOrderRequest.js +++ b/src/model/CreateOrderRequest.js @@ -5,29 +5,44 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class CreateOrderRequest { constructor(massG) { - CreateOrderRequest.initialize(this, massG); + CreateOrderRequest.initialize(this, massG) } static initialize(obj, massG) { - obj['mass_g'] = massG; + obj['mass_g'] = massG } static constructFromObject(data, obj) { if (data) { - obj = obj || new CreateOrderRequest(); + obj = obj || new CreateOrderRequest() if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); + obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number') + } + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = ApiClient.convertToType( + data['project_id'], + 'String' + ) + } + + if (data.hasOwnProperty('metadata')) { + obj['metadata'] = ApiClient.convertToType(data['metadata'], Object) } } - return obj; + return obj } } -CreateOrderRequest.prototype['mass_g'] = undefined; +CreateOrderRequest.prototype['mass_g'] = undefined + +CreateOrderRequest.prototype['project_id'] = undefined + +CreateOrderRequest.prototype['metadata'] = undefined -export default CreateOrderRequest; +export default CreateOrderRequest diff --git a/src/model/CreatePreferenceRequest.js b/src/model/CreatePreferenceRequest.js index 5c0f2fc..c521d96 100644 --- a/src/model/CreatePreferenceRequest.js +++ b/src/model/CreatePreferenceRequest.js @@ -5,32 +5,32 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class CreatePreferenceRequest { constructor(projectId) { - CreatePreferenceRequest.initialize(this, projectId); + CreatePreferenceRequest.initialize(this, projectId) } static initialize(obj, projectId) { - obj['project_id'] = projectId; + obj['project_id'] = projectId } static constructFromObject(data, obj) { if (data) { - obj = obj || new CreatePreferenceRequest(); + obj = obj || new CreatePreferenceRequest() if (data.hasOwnProperty('project_id')) { obj['project_id'] = ApiClient.convertToType( data['project_id'], 'String' - ); + ) } } - return obj; + return obj } } -CreatePreferenceRequest.prototype['project_id'] = undefined; +CreatePreferenceRequest.prototype['project_id'] = undefined -export default CreatePreferenceRequest; +export default CreatePreferenceRequest diff --git a/src/model/ErrorResponse.js b/src/model/ErrorResponse.js index 57fa749..23be1ea 100644 --- a/src/model/ErrorResponse.js +++ b/src/model/ErrorResponse.js @@ -5,43 +5,43 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class ErrorResponse { constructor(success, error, data) { - ErrorResponse.initialize(this, success, error, data); + ErrorResponse.initialize(this, success, error, data) } static initialize(obj, success, error, data) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; + obj['success'] = success + obj['error'] = error + obj['data'] = data } static constructFromObject(data, obj) { if (data) { - obj = obj || new ErrorResponse(); + obj = obj || new ErrorResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = ApiClient.convertToType(data['data'], Object); + obj['data'] = ApiClient.convertToType(data['data'], Object) } } - return obj; + return obj } } -ErrorResponse.prototype['success'] = undefined; +ErrorResponse.prototype['success'] = undefined -ErrorResponse.prototype['error'] = undefined; +ErrorResponse.prototype['error'] = undefined -ErrorResponse.prototype['data'] = undefined; +ErrorResponse.prototype['data'] = undefined -export default ErrorResponse; +export default ErrorResponse diff --git a/src/model/Estimate.js b/src/model/Estimate.js index 9de3be0..2844021 100644 --- a/src/model/Estimate.js +++ b/src/model/Estimate.js @@ -5,49 +5,53 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Order from './Order'; +import ApiClient from '../ApiClient' +import Order from './Order' class Estimate { - constructor() { - Estimate.initialize(this); + constructor(id, production, type) { + Estimate.initialize(this, id, production, type) } - static initialize(obj) {} + static initialize(obj, id, production, type) { + obj['id'] = id + obj['production'] = production + obj['type'] = type + } static constructFromObject(data, obj) { if (data) { - obj = obj || new Estimate(); + obj = obj || new Estimate() if (data.hasOwnProperty('id')) { - obj['id'] = ApiClient.convertToType(data['id'], 'String'); + obj['id'] = ApiClient.convertToType(data['id'], 'String') } if (data.hasOwnProperty('production')) { obj['production'] = ApiClient.convertToType( data['production'], 'Boolean' - ); + ) } if (data.hasOwnProperty('type')) { - obj['type'] = ApiClient.convertToType(data['type'], 'String'); + obj['type'] = ApiClient.convertToType(data['type'], 'String') } if (data.hasOwnProperty('order')) { - obj['order'] = Order.constructFromObject(data['order']); + obj['order'] = Order.constructFromObject(data['order']) } } - return obj; + return obj } } -Estimate.prototype['id'] = undefined; +Estimate.prototype['id'] = undefined -Estimate.prototype['production'] = undefined; +Estimate.prototype['production'] = undefined -Estimate.prototype['type'] = undefined; +Estimate.prototype['type'] = undefined -Estimate.prototype['order'] = undefined; +Estimate.prototype['order'] = undefined -export default Estimate; +export default Estimate diff --git a/src/model/EstimateListResponse.js b/src/model/EstimateListResponse.js index 3e4e400..8c13949 100644 --- a/src/model/EstimateListResponse.js +++ b/src/model/EstimateListResponse.js @@ -5,52 +5,52 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Estimate from './Estimate'; -import MetaIndexObject from './MetaIndexObject'; +import ApiClient from '../ApiClient' +import Estimate from './Estimate' +import MetaIndexObject from './MetaIndexObject' class EstimateListResponse { constructor(success, error, data, meta) { - EstimateListResponse.initialize(this, success, error, data, meta); + EstimateListResponse.initialize(this, success, error, data, meta) } static initialize(obj, success, error, data, meta) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; - obj['meta'] = meta; + obj['success'] = success + obj['error'] = error + obj['data'] = data + obj['meta'] = meta } static constructFromObject(data, obj) { if (data) { - obj = obj || new EstimateListResponse(); + obj = obj || new EstimateListResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = ApiClient.convertToType(data['data'], [Estimate]); + obj['data'] = ApiClient.convertToType(data['data'], [Estimate]) } if (data.hasOwnProperty('meta')) { - obj['meta'] = MetaIndexObject.constructFromObject(data['meta']); + obj['meta'] = MetaIndexObject.constructFromObject(data['meta']) } } - return obj; + return obj } } -EstimateListResponse.prototype['success'] = undefined; +EstimateListResponse.prototype['success'] = undefined -EstimateListResponse.prototype['error'] = undefined; +EstimateListResponse.prototype['error'] = undefined -EstimateListResponse.prototype['data'] = undefined; +EstimateListResponse.prototype['data'] = undefined -EstimateListResponse.prototype['meta'] = undefined; +EstimateListResponse.prototype['meta'] = undefined -export default EstimateListResponse; +export default EstimateListResponse diff --git a/src/model/EstimateResponse.js b/src/model/EstimateResponse.js index e77ba7b..a0a8880 100644 --- a/src/model/EstimateResponse.js +++ b/src/model/EstimateResponse.js @@ -5,44 +5,44 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Estimate from './Estimate'; +import ApiClient from '../ApiClient' +import Estimate from './Estimate' class EstimateResponse { constructor(success, error, data) { - EstimateResponse.initialize(this, success, error, data); + EstimateResponse.initialize(this, success, error, data) } static initialize(obj, success, error, data) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; + obj['success'] = success + obj['error'] = error + obj['data'] = data } static constructFromObject(data, obj) { if (data) { - obj = obj || new EstimateResponse(); + obj = obj || new EstimateResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = Estimate.constructFromObject(data['data']); + obj['data'] = Estimate.constructFromObject(data['data']) } } - return obj; + return obj } } -EstimateResponse.prototype['success'] = undefined; +EstimateResponse.prototype['success'] = undefined -EstimateResponse.prototype['error'] = undefined; +EstimateResponse.prototype['error'] = undefined -EstimateResponse.prototype['data'] = undefined; +EstimateResponse.prototype['data'] = undefined -export default EstimateResponse; +export default EstimateResponse diff --git a/src/model/MetaIndexObject.js b/src/model/MetaIndexObject.js index ac3aff9..c4ddfa9 100644 --- a/src/model/MetaIndexObject.js +++ b/src/model/MetaIndexObject.js @@ -5,33 +5,33 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class MetaIndexObject { constructor() { - MetaIndexObject.initialize(this); + MetaIndexObject.initialize(this) } static initialize(obj) {} static constructFromObject(data, obj) { if (data) { - obj = obj || new MetaIndexObject(); + obj = obj || new MetaIndexObject() if (data.hasOwnProperty('prev_page')) { - obj['prev_page'] = ApiClient.convertToType(data['prev_page'], 'Number'); + obj['prev_page'] = ApiClient.convertToType(data['prev_page'], 'Number') } if (data.hasOwnProperty('next_page')) { - obj['next_page'] = ApiClient.convertToType(data['next_page'], 'Number'); + obj['next_page'] = ApiClient.convertToType(data['next_page'], 'Number') } } - return obj; + return obj } } -MetaIndexObject.prototype['prev_page'] = undefined; +MetaIndexObject.prototype['prev_page'] = undefined -MetaIndexObject.prototype['next_page'] = undefined; +MetaIndexObject.prototype['next_page'] = undefined -export default MetaIndexObject; +export default MetaIndexObject diff --git a/src/model/Order.js b/src/model/Order.js index a06bbb1..238c19d 100644 --- a/src/model/Order.js +++ b/src/model/Order.js @@ -5,75 +5,119 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Allocation from './Allocation'; +import ApiClient from '../ApiClient' +import Allocation from './Allocation' class Order { - constructor() { - Order.initialize(this); + constructor( + id, + massG, + production, + state, + allocationState, + priceCentsUsd, + allocations, + metadata + ) { + Order.initialize( + this, + id, + massG, + production, + state, + allocationState, + priceCentsUsd, + allocations, + metadata + ) } - static initialize(obj) {} + static initialize( + obj, + id, + massG, + production, + state, + allocationState, + priceCentsUsd, + allocations, + metadata + ) { + obj['id'] = id + obj['mass_g'] = massG + obj['production'] = production + obj['state'] = state + obj['allocation_state'] = allocationState + obj['price_cents_usd'] = priceCentsUsd + obj['allocations'] = allocations + obj['metadata'] = metadata + } static constructFromObject(data, obj) { if (data) { - obj = obj || new Order(); + obj = obj || new Order() if (data.hasOwnProperty('id')) { - obj['id'] = ApiClient.convertToType(data['id'], 'String'); + obj['id'] = ApiClient.convertToType(data['id'], 'String') } if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); + obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number') } if (data.hasOwnProperty('production')) { obj['production'] = ApiClient.convertToType( data['production'], 'Boolean' - ); + ) } if (data.hasOwnProperty('state')) { - obj['state'] = ApiClient.convertToType(data['state'], 'String'); + obj['state'] = ApiClient.convertToType(data['state'], 'String') } if (data.hasOwnProperty('allocation_state')) { obj['allocation_state'] = ApiClient.convertToType( data['allocation_state'], 'String' - ); + ) } if (data.hasOwnProperty('price_cents_usd')) { obj['price_cents_usd'] = ApiClient.convertToType( data['price_cents_usd'], 'String' - ); + ) } if (data.hasOwnProperty('allocations')) { obj['allocations'] = ApiClient.convertToType(data['allocations'], [ Allocation - ]); + ]) + } + + if (data.hasOwnProperty('metadata')) { + obj['metadata'] = ApiClient.convertToType(data['metadata'], Object) } } - return obj; + return obj } } -Order.prototype['id'] = undefined; +Order.prototype['id'] = undefined + +Order.prototype['mass_g'] = undefined -Order.prototype['mass_g'] = undefined; +Order.prototype['production'] = undefined -Order.prototype['production'] = undefined; +Order.prototype['state'] = undefined -Order.prototype['state'] = undefined; +Order.prototype['allocation_state'] = undefined -Order.prototype['allocation_state'] = undefined; +Order.prototype['price_cents_usd'] = undefined -Order.prototype['price_cents_usd'] = undefined; +Order.prototype['allocations'] = undefined -Order.prototype['allocations'] = undefined; +Order.prototype['metadata'] = undefined -export default Order; +export default Order diff --git a/src/model/OrderListResponse.js b/src/model/OrderListResponse.js index 05bd5aa..80770ed 100644 --- a/src/model/OrderListResponse.js +++ b/src/model/OrderListResponse.js @@ -5,52 +5,52 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import MetaIndexObject from './MetaIndexObject'; -import Order from './Order'; +import ApiClient from '../ApiClient' +import MetaIndexObject from './MetaIndexObject' +import Order from './Order' class OrderListResponse { constructor(success, error, data, meta) { - OrderListResponse.initialize(this, success, error, data, meta); + OrderListResponse.initialize(this, success, error, data, meta) } static initialize(obj, success, error, data, meta) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; - obj['meta'] = meta; + obj['success'] = success + obj['error'] = error + obj['data'] = data + obj['meta'] = meta } static constructFromObject(data, obj) { if (data) { - obj = obj || new OrderListResponse(); + obj = obj || new OrderListResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = ApiClient.convertToType(data['data'], [Order]); + obj['data'] = ApiClient.convertToType(data['data'], [Order]) } if (data.hasOwnProperty('meta')) { - obj['meta'] = MetaIndexObject.constructFromObject(data['meta']); + obj['meta'] = MetaIndexObject.constructFromObject(data['meta']) } } - return obj; + return obj } } -OrderListResponse.prototype['success'] = undefined; +OrderListResponse.prototype['success'] = undefined -OrderListResponse.prototype['error'] = undefined; +OrderListResponse.prototype['error'] = undefined -OrderListResponse.prototype['data'] = undefined; +OrderListResponse.prototype['data'] = undefined -OrderListResponse.prototype['meta'] = undefined; +OrderListResponse.prototype['meta'] = undefined -export default OrderListResponse; +export default OrderListResponse diff --git a/src/model/OrderResponse.js b/src/model/OrderResponse.js index fee9623..8bb5eab 100644 --- a/src/model/OrderResponse.js +++ b/src/model/OrderResponse.js @@ -5,44 +5,44 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Order from './Order'; +import ApiClient from '../ApiClient' +import Order from './Order' class OrderResponse { constructor(success, error, data) { - OrderResponse.initialize(this, success, error, data); + OrderResponse.initialize(this, success, error, data) } static initialize(obj, success, error, data) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; + obj['success'] = success + obj['error'] = error + obj['data'] = data } static constructFromObject(data, obj) { if (data) { - obj = obj || new OrderResponse(); + obj = obj || new OrderResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = Order.constructFromObject(data['data']); + obj['data'] = Order.constructFromObject(data['data']) } } - return obj; + return obj } } -OrderResponse.prototype['success'] = undefined; +OrderResponse.prototype['success'] = undefined -OrderResponse.prototype['error'] = undefined; +OrderResponse.prototype['error'] = undefined -OrderResponse.prototype['data'] = undefined; +OrderResponse.prototype['data'] = undefined -export default OrderResponse; +export default OrderResponse diff --git a/src/model/Preference.js b/src/model/Preference.js index 0a770ad..29861b4 100644 --- a/src/model/Preference.js +++ b/src/model/Preference.js @@ -5,43 +5,47 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Project from './Project'; +import ApiClient from '../ApiClient' +import Project from './Project' class Preference { - constructor() { - Preference.initialize(this); + constructor(id, allocationPercentage, project) { + Preference.initialize(this, id, allocationPercentage, project) } - static initialize(obj) {} + static initialize(obj, id, allocationPercentage, project) { + obj['id'] = id + obj['allocation_percentage'] = allocationPercentage + obj['project'] = project + } static constructFromObject(data, obj) { if (data) { - obj = obj || new Preference(); + obj = obj || new Preference() if (data.hasOwnProperty('id')) { - obj['id'] = ApiClient.convertToType(data['id'], 'String'); + obj['id'] = ApiClient.convertToType(data['id'], 'String') } if (data.hasOwnProperty('allocation_percentage')) { obj['allocation_percentage'] = ApiClient.convertToType( data['allocation_percentage'], 'Number' - ); + ) } if (data.hasOwnProperty('project')) { - obj['project'] = Project.constructFromObject(data['project']); + obj['project'] = Project.constructFromObject(data['project']) } } - return obj; + return obj } } -Preference.prototype['id'] = undefined; +Preference.prototype['id'] = undefined -Preference.prototype['allocation_percentage'] = undefined; +Preference.prototype['allocation_percentage'] = undefined -Preference.prototype['project'] = undefined; +Preference.prototype['project'] = undefined -export default Preference; +export default Preference diff --git a/src/model/PreferenceListResponse.js b/src/model/PreferenceListResponse.js index 48fc6d8..d03f87b 100644 --- a/src/model/PreferenceListResponse.js +++ b/src/model/PreferenceListResponse.js @@ -5,52 +5,52 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import MetaIndexObject from './MetaIndexObject'; -import Preference from './Preference'; +import ApiClient from '../ApiClient' +import MetaIndexObject from './MetaIndexObject' +import Preference from './Preference' class PreferenceListResponse { constructor(success, error, data, meta) { - PreferenceListResponse.initialize(this, success, error, data, meta); + PreferenceListResponse.initialize(this, success, error, data, meta) } static initialize(obj, success, error, data, meta) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; - obj['meta'] = meta; + obj['success'] = success + obj['error'] = error + obj['data'] = data + obj['meta'] = meta } static constructFromObject(data, obj) { if (data) { - obj = obj || new PreferenceListResponse(); + obj = obj || new PreferenceListResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = ApiClient.convertToType(data['data'], [Preference]); + obj['data'] = ApiClient.convertToType(data['data'], [Preference]) } if (data.hasOwnProperty('meta')) { - obj['meta'] = MetaIndexObject.constructFromObject(data['meta']); + obj['meta'] = MetaIndexObject.constructFromObject(data['meta']) } } - return obj; + return obj } } -PreferenceListResponse.prototype['success'] = undefined; +PreferenceListResponse.prototype['success'] = undefined -PreferenceListResponse.prototype['error'] = undefined; +PreferenceListResponse.prototype['error'] = undefined -PreferenceListResponse.prototype['data'] = undefined; +PreferenceListResponse.prototype['data'] = undefined -PreferenceListResponse.prototype['meta'] = undefined; +PreferenceListResponse.prototype['meta'] = undefined -export default PreferenceListResponse; +export default PreferenceListResponse diff --git a/src/model/PreferenceResponse.js b/src/model/PreferenceResponse.js index 1797e30..aa06764 100644 --- a/src/model/PreferenceResponse.js +++ b/src/model/PreferenceResponse.js @@ -5,44 +5,44 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Preference from './Preference'; +import ApiClient from '../ApiClient' +import Preference from './Preference' class PreferenceResponse { constructor(success, error, data) { - PreferenceResponse.initialize(this, success, error, data); + PreferenceResponse.initialize(this, success, error, data) } static initialize(obj, success, error, data) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; + obj['success'] = success + obj['error'] = error + obj['data'] = data } static constructFromObject(data, obj) { if (data) { - obj = obj || new PreferenceResponse(); + obj = obj || new PreferenceResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = Preference.constructFromObject(data['data']); + obj['data'] = Preference.constructFromObject(data['data']) } } - return obj; + return obj } } -PreferenceResponse.prototype['success'] = undefined; +PreferenceResponse.prototype['success'] = undefined -PreferenceResponse.prototype['error'] = undefined; +PreferenceResponse.prototype['error'] = undefined -PreferenceResponse.prototype['data'] = undefined; +PreferenceResponse.prototype['data'] = undefined -export default PreferenceResponse; +export default PreferenceResponse diff --git a/src/model/Project.js b/src/model/Project.js index fabd7e5..8428592 100644 --- a/src/model/Project.js +++ b/src/model/Project.js @@ -5,81 +5,92 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; +import ApiClient from '../ApiClient' class Project { - constructor() { - Project.initialize(this); + constructor(id, production, name, description, country, developer) { + Project.initialize( + this, + id, + production, + name, + description, + country, + developer + ) } - static initialize(obj) {} + static initialize( + obj, + id, + production, + name, + description, + country, + developer + ) { + obj['id'] = id + obj['production'] = production + obj['name'] = name + obj['description'] = description + obj['country'] = country + obj['developer'] = developer + } static constructFromObject(data, obj) { if (data) { - obj = obj || new Project(); + obj = obj || new Project() if (data.hasOwnProperty('id')) { - obj['id'] = ApiClient.convertToType(data['id'], 'String'); + obj['id'] = ApiClient.convertToType(data['id'], 'String') } if (data.hasOwnProperty('production')) { obj['production'] = ApiClient.convertToType( data['production'], 'Boolean' - ); + ) } if (data.hasOwnProperty('name')) { - obj['name'] = ApiClient.convertToType(data['name'], 'String'); + obj['name'] = ApiClient.convertToType(data['name'], 'String') } if (data.hasOwnProperty('description')) { obj['description'] = ApiClient.convertToType( data['description'], 'String' - ); + ) } - if (data.hasOwnProperty('country')) { - obj['country'] = ApiClient.convertToType(data['country'], 'String'); + if (data.hasOwnProperty('type')) { + obj['type'] = ApiClient.convertToType(data['type'], 'String') } - if (data.hasOwnProperty('longitude')) { - obj['longitude'] = ApiClient.convertToType(data['longitude'], 'Number'); - } - - if (data.hasOwnProperty('latitude')) { - obj['latitude'] = ApiClient.convertToType(data['latitude'], 'Number'); - } - - if (data.hasOwnProperty('verifier')) { - obj['verifier'] = ApiClient.convertToType(data['verifier'], 'String'); + if (data.hasOwnProperty('country')) { + obj['country'] = ApiClient.convertToType(data['country'], 'String') } if (data.hasOwnProperty('developer')) { - obj['developer'] = ApiClient.convertToType(data['developer'], 'String'); + obj['developer'] = ApiClient.convertToType(data['developer'], 'String') } } - return obj; + return obj } } -Project.prototype['id'] = undefined; - -Project.prototype['production'] = undefined; - -Project.prototype['name'] = undefined; +Project.prototype['id'] = undefined -Project.prototype['description'] = undefined; +Project.prototype['production'] = undefined -Project.prototype['country'] = undefined; +Project.prototype['name'] = undefined -Project.prototype['longitude'] = undefined; +Project.prototype['description'] = undefined -Project.prototype['latitude'] = undefined; +Project.prototype['type'] = undefined -Project.prototype['verifier'] = undefined; +Project.prototype['country'] = undefined -Project.prototype['developer'] = undefined; +Project.prototype['developer'] = undefined -export default Project; +export default Project diff --git a/src/model/ProjectListResponse.js b/src/model/ProjectListResponse.js index a33dde2..e32e39a 100644 --- a/src/model/ProjectListResponse.js +++ b/src/model/ProjectListResponse.js @@ -5,52 +5,52 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import MetaIndexObject from './MetaIndexObject'; -import Project from './Project'; +import ApiClient from '../ApiClient' +import MetaIndexObject from './MetaIndexObject' +import Project from './Project' class ProjectListResponse { constructor(success, error, data, meta) { - ProjectListResponse.initialize(this, success, error, data, meta); + ProjectListResponse.initialize(this, success, error, data, meta) } static initialize(obj, success, error, data, meta) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; - obj['meta'] = meta; + obj['success'] = success + obj['error'] = error + obj['data'] = data + obj['meta'] = meta } static constructFromObject(data, obj) { if (data) { - obj = obj || new ProjectListResponse(); + obj = obj || new ProjectListResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = ApiClient.convertToType(data['data'], [Project]); + obj['data'] = ApiClient.convertToType(data['data'], [Project]) } if (data.hasOwnProperty('meta')) { - obj['meta'] = MetaIndexObject.constructFromObject(data['meta']); + obj['meta'] = MetaIndexObject.constructFromObject(data['meta']) } } - return obj; + return obj } } -ProjectListResponse.prototype['success'] = undefined; +ProjectListResponse.prototype['success'] = undefined -ProjectListResponse.prototype['error'] = undefined; +ProjectListResponse.prototype['error'] = undefined -ProjectListResponse.prototype['data'] = undefined; +ProjectListResponse.prototype['data'] = undefined -ProjectListResponse.prototype['meta'] = undefined; +ProjectListResponse.prototype['meta'] = undefined -export default ProjectListResponse; +export default ProjectListResponse diff --git a/src/model/ProjectResponse.js b/src/model/ProjectResponse.js index 8b6e12e..3cc39f4 100644 --- a/src/model/ProjectResponse.js +++ b/src/model/ProjectResponse.js @@ -5,44 +5,44 @@ * Contact: developers@usepatch.com */ -import ApiClient from '../ApiClient'; -import Project from './Project'; +import ApiClient from '../ApiClient' +import Project from './Project' class ProjectResponse { constructor(success, error, data) { - ProjectResponse.initialize(this, success, error, data); + ProjectResponse.initialize(this, success, error, data) } static initialize(obj, success, error, data) { - obj['success'] = success; - obj['error'] = error; - obj['data'] = data; + obj['success'] = success + obj['error'] = error + obj['data'] = data } static constructFromObject(data, obj) { if (data) { - obj = obj || new ProjectResponse(); + obj = obj || new ProjectResponse() if (data.hasOwnProperty('success')) { - obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean') } if (data.hasOwnProperty('error')) { - obj['error'] = ApiClient.convertToType(data['error'], Object); + obj['error'] = ApiClient.convertToType(data['error'], Object) } if (data.hasOwnProperty('data')) { - obj['data'] = Project.constructFromObject(data['data']); + obj['data'] = Project.constructFromObject(data['data']) } } - return obj; + return obj } } -ProjectResponse.prototype['success'] = undefined; +ProjectResponse.prototype['success'] = undefined -ProjectResponse.prototype['error'] = undefined; +ProjectResponse.prototype['error'] = undefined -ProjectResponse.prototype['data'] = undefined; +ProjectResponse.prototype['data'] = undefined -export default ProjectResponse; +export default ProjectResponse diff --git a/test/integration/estimates.spec.js b/test/integration/estimates.spec.js index bcb379a..0da125a 100644 --- a/test/integration/estimates.spec.js +++ b/test/integration/estimates.spec.js @@ -1,22 +1,36 @@ -import { expect } from 'chai'; -import Patch from '../../dist/index'; -const patch = Patch(process.env.SANDBOX_API_KEY); +import { expect } from 'chai' +import Patch from '../../dist/index' +const patch = Patch(process.env.SANDBOX_API_KEY) describe('Estimates Integration', function () { it('supports create, retrieve and list', async function () { const createEstimateResponse = await patch.estimates.createMassEstimate({ mass_g: 100 - }); - const estimateId = createEstimateResponse.data.id; + }) + const estimateId = createEstimateResponse.data.id const retrieveEstimateResponse = await patch.estimates.retrieveEstimate( estimateId - ); - expect(retrieveEstimateResponse.data.id).to.equal(estimateId); + ) + expect(retrieveEstimateResponse.data.id).to.equal(estimateId) const retrieveEstimatesResponse = await patch.estimates.retrieveEstimates({ page: 1 - }); - expect(retrieveEstimatesResponse.data.length).to.be.above(0); - }); -}); + }) + expect(retrieveEstimatesResponse.data.length).to.be.above(0) + }) + + it('supports create with a specific project', async function () { + const { data } = await patch.projects.retrieveProjects() + const projectId = data[0].id + + const createEstimateResponse = await patch.estimates.createMassEstimate({ + mass_g: 100, + project_id: projectId + }) + + expect(createEstimateResponse.success).to.equal(true) + expect(createEstimateResponse.data.id).not.to.be.empty + expect(createEstimateResponse.data.order.mass_g).to.eq(100) + }) +}) diff --git a/test/integration/orders.test.js b/test/integration/orders.test.js index d2c7c30..80c4740 100644 --- a/test/integration/orders.test.js +++ b/test/integration/orders.test.js @@ -1,40 +1,66 @@ -import { expect } from 'chai'; -import Patch from '../../dist/index'; -const patch = Patch(process.env.SANDBOX_API_KEY); +import { expect } from 'chai' +import Patch from '../../dist/index' +const patch = Patch(process.env.SANDBOX_API_KEY) describe('Orders Integration', function () { it('supports create, place, cancel, retrieve and list', async function () { - const createOrderResponse = await patch.orders.createOrder({ mass_g: 100 }); - const orderId = createOrderResponse.data.id; + const createOrderResponse = await patch.orders.createOrder({ mass_g: 100 }) + const orderId = createOrderResponse.data.id - const retreiveOrderResponse = await patch.orders.retrieveOrder(orderId); - expect(retreiveOrderResponse.data.id).to.equal(orderId); + const retrieveOrderResponse = await patch.orders.retrieveOrder(orderId) + expect(retrieveOrderResponse.data.id).to.equal(orderId) const retrieveOrdersResponse = await patch.orders.retrieveOrders({ page: 1 - }); - expect(retrieveOrdersResponse.data.length).to.be.above(0); - }); + }) + expect(retrieveOrdersResponse.data.length).to.be.above(0) + }) + + it('supports create with a specific project', async function () { + const { data } = await patch.projects.retrieveProjects() + const projectId = data[0].id + + const createOrderResponse = await patch.orders.createOrder({ + mass_g: 100, + project_id: projectId + }) + + expect(createOrderResponse.success).to.equal(true) + expect(createOrderResponse.data.id).not.to.be.empty + }) + + it('supports create with metadata', async function () { + const metadata = { user: 'john doe' } + + const createOrderResponse = await patch.orders.createOrder({ + mass_g: 100, + metadata: metadata + }) + + expect(createOrderResponse.success).to.equal(true) + expect(createOrderResponse.data.id).not.to.be.empty + expect(createOrderResponse.data.metadata.user).to.eq('john doe') + }) it('supports placing orders in a `draft` state', async function () { const estimateResponse = await patch.estimates.createMassEstimate({ mass_g: 100 - }); - const orderId = estimateResponse.data.order.id; - expect(estimateResponse.data.order.state).to.equal('draft'); + }) + const orderId = estimateResponse.data.order.id + expect(estimateResponse.data.order.state).to.equal('draft') - const placeOrderResponse = await patch.orders.placeOrder(orderId); - expect(placeOrderResponse.data.state).to.equal('placed'); - }); + const placeOrderResponse = await patch.orders.placeOrder(orderId) + expect(placeOrderResponse.data.state).to.equal('placed') + }) it('supports cancelling orders in a `draft` state', async function () { const estimateResponse = await patch.estimates.createMassEstimate({ mass_g: 100 - }); - const orderId = estimateResponse.data.order.id; - expect(estimateResponse.data.order.state).to.equal('draft'); - - const placeOrderResponse = await patch.orders.cancelOrder(orderId); - expect(placeOrderResponse.data.state).to.equal('cancelled'); - }); -}); + }) + const orderId = estimateResponse.data.order.id + expect(estimateResponse.data.order.state).to.equal('draft') + + const placeOrderResponse = await patch.orders.cancelOrder(orderId) + expect(placeOrderResponse.data.state).to.equal('cancelled') + }) +}) diff --git a/test/integration/preferences.test.js b/test/integration/preferences.test.js index c0e5f38..00bf542 100644 --- a/test/integration/preferences.test.js +++ b/test/integration/preferences.test.js @@ -1,47 +1,47 @@ -import { expect } from 'chai'; -import Patch from '../../dist/index'; -const patch = Patch(process.env.SANDBOX_API_KEY); +import { expect } from 'chai' +import Patch from '../../dist/index' +const patch = Patch(process.env.SANDBOX_API_KEY) describe('Preferences Integration', function () { it('supports create, delete, retrieve and list', async function () { - const projectResponse = await patch.projects.retrieveProjects(); - expect(projectResponse.data.length).to.be.above(0); + const projectResponse = await patch.projects.retrieveProjects() + expect(projectResponse.data.length).to.be.above(0) - const projectId = projectResponse.data[0].id; - let createPreferenceResponse; + const projectId = projectResponse.data[0].id + let createPreferenceResponse try { createPreferenceResponse = await patch.preferences.createPreference({ project_id: projectId - }); + }) } catch ({ error }) { // If there's a preference that exists already if (error.code === 422) { // Delete the preference await patch.preferences.deletePreference( (await patch.preferences.retrievePreferences()).data[0].id - ); + ) createPreferenceResponse = await patch.preferences.createPreference({ project_id: projectId - }); + }) } } - const preferenceId = createPreferenceResponse.data.id; + const preferenceId = createPreferenceResponse.data.id const retrievePreferenceResponse = await patch.preferences.retrievePreference( preferenceId - ); - expect(retrievePreferenceResponse.data.id).to.equal(preferenceId); + ) + expect(retrievePreferenceResponse.data.id).to.equal(preferenceId) const retrievePreferencesResponse = await patch.preferences.retrievePreferences( { page: 1 } - ); - expect(retrievePreferencesResponse.data[0].id).to.equal(preferenceId); + ) + expect(retrievePreferencesResponse.data[0].id).to.equal(preferenceId) const deletePreferenceResponse = await patch.preferences.deletePreference( preferenceId - ); - expect(deletePreferenceResponse.data.id).to.equal(preferenceId); - }); -}); + ) + expect(deletePreferenceResponse.data.id).to.equal(preferenceId) + }) +}) diff --git a/test/integration/projects.test.js b/test/integration/projects.test.js index f905a79..b76ad8b 100644 --- a/test/integration/projects.test.js +++ b/test/integration/projects.test.js @@ -1,17 +1,17 @@ -import { expect } from 'chai'; -import Patch from '../../dist/index'; -const patch = Patch(process.env.SANDBOX_API_KEY); +import { expect } from 'chai' +import Patch from '../../dist/index' +const patch = Patch(process.env.SANDBOX_API_KEY) describe('Project Integration', function () { it('supports fetching the available projects', async function () { - const { data } = await patch.projects.retrieveProjects(); - expect(data.length).to.be.above(0); - }); + const { data } = await patch.projects.retrieveProjects() + expect(data.length).to.be.above(0) + }) it('supports fetching a single project', async function () { - const { data } = await patch.projects.retrieveProjects(); - const projectId = data[0].id; - const projectResponse = await patch.projects.retrieveProject(projectId); - expect(projectResponse.data.id).to.equal(projectId); - }); -}); + const { data } = await patch.projects.retrieveProjects() + const projectId = data[0].id + const projectResponse = await patch.projects.retrieveProject(projectId) + expect(projectResponse.data.id).to.equal(projectId) + }) +})