diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a930c7..d0410c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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). +## [1.15.0] - 2021-10-04 + +### Added + +- Added the ability to fetch project technology types via `patch.technologytypes.retrieveTechnologyTypes()` + ## [1.14.0] - 2021-09-27 ### Added diff --git a/package-lock.json b/package-lock.json index 1db5958..8e5b771 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.14.0", + "version": "1.15.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.14.0", + "version": "1.15.0", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index 80094c4..b03f390 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.14.0", + "version": "1.15.0", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index 28a157a..3e83020 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.14.0' + 'User-Agent': 'patch-node/1.15.0' }; /** diff --git a/src/api/TechnologyTypesApi.js b/src/api/TechnologyTypesApi.js new file mode 100644 index 0000000..09713d6 --- /dev/null +++ b/src/api/TechnologyTypesApi.js @@ -0,0 +1,47 @@ +/** + * Patch API V1 + * The core API used to integrate with Patch's service + * + * Contact: developers@usepatch.com + */ + +import ApiClient from '../ApiClient'; +import TechnologyTypeListResponse from '../model/TechnologyTypeListResponse'; + +export default class TechnologyTypesApi { + constructor(apiClient) { + this.apiClient = apiClient || ApiClient.instance; + } + + retrieveTechnologyTypesWithHttpInfo() { + let postBody = null; + + let pathParams = {}; + let queryParams = {}; + let headerParams = {}; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = []; + let accepts = ['application/json']; + let returnType = TechnologyTypeListResponse; + + return this.apiClient.callApi( + '/v1/projects/technology_types', + 'GET', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + retrieveTechnologyTypes() { + return this.retrieveTechnologyTypesWithHttpInfo(); + } +} diff --git a/src/index.js b/src/index.js index b910f9a..217ca90 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import EstimatesApi from './api/EstimatesApi'; import OrdersApi from './api/OrdersApi'; import PreferencesApi from './api/PreferencesApi'; import ProjectsApi from './api/ProjectsApi'; +import TechnologyTypesApi from './api/TechnologyTypesApi'; export default function Patch(accessToken) { if (!(this instanceof Patch)) return new Patch(accessToken); @@ -24,4 +25,6 @@ export default function Patch(accessToken) { this.preferences = new PreferencesApi(this.client); this.projects = new ProjectsApi(this.client); + + this.technologytypes = new TechnologyTypesApi(this.client); } diff --git a/src/model/Project.js b/src/model/Project.js index 450f6fe..213ea87 100644 --- a/src/model/Project.js +++ b/src/model/Project.js @@ -20,7 +20,8 @@ class Project { country, developer, averagePricePerTonneCentsUsd, - remainingMassG + remainingMassG, + technologyType ) { Project.initialize( this, @@ -31,7 +32,8 @@ class Project { country, developer, averagePricePerTonneCentsUsd, - remainingMassG + remainingMassG, + technologyType ); } @@ -44,7 +46,8 @@ class Project { country, developer, averagePricePerTonneCentsUsd, - remainingMassG + remainingMassG, + technologyType ) { obj['id'] = id; obj['production'] = production; @@ -54,6 +57,7 @@ class Project { obj['developer'] = developer; obj['average_price_per_tonne_cents_usd'] = averagePricePerTonneCentsUsd; obj['remaining_mass_g'] = remainingMassG; + obj['technology_type'] = technologyType; } static constructFromObject(data, obj) { @@ -136,15 +140,15 @@ class Project { obj['sdgs'] = ApiClient.convertToType(data['sdgs'], [Sdg]); } + if (data.hasOwnProperty('tagline')) { + obj['tagline'] = ApiClient.convertToType(data['tagline'], 'String'); + } + if (data.hasOwnProperty('technology_type')) { obj['technology_type'] = TechnologyType.constructFromObject( data['technology_type'] ); } - - if (data.hasOwnProperty('tagline')) { - obj['tagline'] = ApiClient.convertToType(data['tagline'], 'String'); - } } return obj; } @@ -182,8 +186,8 @@ Project.prototype['standard'] = undefined; Project.prototype['sdgs'] = undefined; -Project.prototype['technology_type'] = undefined; - Project.prototype['tagline'] = undefined; +Project.prototype['technology_type'] = undefined; + export default Project; diff --git a/src/model/TechnologyType.js b/src/model/TechnologyType.js index 1dc9421..f16ea74 100644 --- a/src/model/TechnologyType.js +++ b/src/model/TechnologyType.js @@ -9,11 +9,14 @@ import ApiClient from '../ApiClient'; import ParentTechnologyType from './ParentTechnologyType'; class TechnologyType { - constructor() { - TechnologyType.initialize(this); + constructor(slug, name) { + TechnologyType.initialize(this, slug, name); } - static initialize(obj) {} + static initialize(obj, slug, name) { + obj['slug'] = slug; + obj['name'] = name; + } static constructFromObject(data, obj) { if (data) { diff --git a/src/model/TechnologyTypeListResponse.js b/src/model/TechnologyTypeListResponse.js new file mode 100644 index 0000000..7938084 --- /dev/null +++ b/src/model/TechnologyTypeListResponse.js @@ -0,0 +1,48 @@ +/** + * Patch API V1 + * The core API used to integrate with Patch's service + * + * Contact: developers@usepatch.com + */ + +import ApiClient from '../ApiClient'; +import TechnologyType from './TechnologyType'; + +class TechnologyTypeListResponse { + constructor(success, error, data) { + TechnologyTypeListResponse.initialize(this, success, error, data); + } + + static initialize(obj, success, error, data) { + obj['success'] = success; + obj['error'] = error; + obj['data'] = data; + } + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new TechnologyTypeListResponse(); + + if (data.hasOwnProperty('success')) { + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + } + + if (data.hasOwnProperty('error')) { + obj['error'] = ApiClient.convertToType(data['error'], Object); + } + + if (data.hasOwnProperty('data')) { + obj['data'] = ApiClient.convertToType(data['data'], [TechnologyType]); + } + } + return obj; + } +} + +TechnologyTypeListResponse.prototype['success'] = undefined; + +TechnologyTypeListResponse.prototype['error'] = undefined; + +TechnologyTypeListResponse.prototype['data'] = undefined; + +export default TechnologyTypeListResponse; diff --git a/test/integration/projects/technology_types.test.js b/test/integration/projects/technology_types.test.js new file mode 100644 index 0000000..94a4560 --- /dev/null +++ b/test/integration/projects/technology_types.test.js @@ -0,0 +1,14 @@ +import { expect } from 'chai'; +import Patch from '../../../dist/index'; +const patch = Patch(process.env.SANDBOX_API_KEY); + +describe('Projects TechnologyTypes Integration', function () { + it.only('supports fetching the available technology_types', async function () { + const { data } = await patch.technologytypes.retrieveTechnologyTypes(); + expect(data.length).to.be.above(0); + expect(data[0].name).to.be.a('string'); + expect(data[0].slug).to.be.a('string'); + expect(data[0].parent_technology_type.slug).to.be.a('string'); + expect(data[0].parent_technology_type.name).to.be.a('string'); + }); +});