Skip to content

Commit

Permalink
Add technology_type index function (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinjm authored Oct 4, 2021
1 parent fe35490 commit 7c59662
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ApiClient {
};

this.defaultHeaders = {
'User-Agent': 'patch-node/1.14.0'
'User-Agent': 'patch-node/1.15.0'
};

/**
Expand Down
47 changes: 47 additions & 0 deletions src/api/TechnologyTypesApi.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
22 changes: 13 additions & 9 deletions src/model/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Project {
country,
developer,
averagePricePerTonneCentsUsd,
remainingMassG
remainingMassG,
technologyType
) {
Project.initialize(
this,
Expand All @@ -31,7 +32,8 @@ class Project {
country,
developer,
averagePricePerTonneCentsUsd,
remainingMassG
remainingMassG,
technologyType
);
}

Expand All @@ -44,7 +46,8 @@ class Project {
country,
developer,
averagePricePerTonneCentsUsd,
remainingMassG
remainingMassG,
technologyType
) {
obj['id'] = id;
obj['production'] = production;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
9 changes: 6 additions & 3 deletions src/model/TechnologyType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
48 changes: 48 additions & 0 deletions src/model/TechnologyTypeListResponse.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions test/integration/projects/technology_types.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 7c59662

Please sign in to comment.