Skip to content

Commit 7c59662

Browse files
authored
Add technology_type index function (#49)
1 parent fe35490 commit 7c59662

File tree

10 files changed

+141
-16
lines changed

10 files changed

+141
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.15.0] - 2021-10-04
9+
10+
### Added
11+
12+
- Added the ability to fetch project technology types via `patch.technologytypes.retrieveTechnologyTypes()`
13+
814
## [1.14.0] - 2021-09-27
915

1016
### Added

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.14.0",
3+
"version": "1.15.0",
44
"description": "Node.js wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {

src/ApiClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiClient {
1616
};
1717

1818
this.defaultHeaders = {
19-
'User-Agent': 'patch-node/1.14.0'
19+
'User-Agent': 'patch-node/1.15.0'
2020
};
2121

2222
/**

src/api/TechnologyTypesApi.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
import TechnologyTypeListResponse from '../model/TechnologyTypeListResponse';
10+
11+
export default class TechnologyTypesApi {
12+
constructor(apiClient) {
13+
this.apiClient = apiClient || ApiClient.instance;
14+
}
15+
16+
retrieveTechnologyTypesWithHttpInfo() {
17+
let postBody = null;
18+
19+
let pathParams = {};
20+
let queryParams = {};
21+
let headerParams = {};
22+
let formParams = {};
23+
24+
let authNames = ['bearer_auth'];
25+
let contentTypes = [];
26+
let accepts = ['application/json'];
27+
let returnType = TechnologyTypeListResponse;
28+
29+
return this.apiClient.callApi(
30+
'/v1/projects/technology_types',
31+
'GET',
32+
pathParams,
33+
queryParams,
34+
headerParams,
35+
formParams,
36+
postBody,
37+
authNames,
38+
contentTypes,
39+
accepts,
40+
returnType
41+
);
42+
}
43+
44+
retrieveTechnologyTypes() {
45+
return this.retrieveTechnologyTypesWithHttpInfo();
46+
}
47+
}

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import EstimatesApi from './api/EstimatesApi';
1010
import OrdersApi from './api/OrdersApi';
1111
import PreferencesApi from './api/PreferencesApi';
1212
import ProjectsApi from './api/ProjectsApi';
13+
import TechnologyTypesApi from './api/TechnologyTypesApi';
1314

1415
export default function Patch(accessToken) {
1516
if (!(this instanceof Patch)) return new Patch(accessToken);
@@ -24,4 +25,6 @@ export default function Patch(accessToken) {
2425
this.preferences = new PreferencesApi(this.client);
2526

2627
this.projects = new ProjectsApi(this.client);
28+
29+
this.technologytypes = new TechnologyTypesApi(this.client);
2730
}

src/model/Project.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Project {
2020
country,
2121
developer,
2222
averagePricePerTonneCentsUsd,
23-
remainingMassG
23+
remainingMassG,
24+
technologyType
2425
) {
2526
Project.initialize(
2627
this,
@@ -31,7 +32,8 @@ class Project {
3132
country,
3233
developer,
3334
averagePricePerTonneCentsUsd,
34-
remainingMassG
35+
remainingMassG,
36+
technologyType
3537
);
3638
}
3739

@@ -44,7 +46,8 @@ class Project {
4446
country,
4547
developer,
4648
averagePricePerTonneCentsUsd,
47-
remainingMassG
49+
remainingMassG,
50+
technologyType
4851
) {
4952
obj['id'] = id;
5053
obj['production'] = production;
@@ -54,6 +57,7 @@ class Project {
5457
obj['developer'] = developer;
5558
obj['average_price_per_tonne_cents_usd'] = averagePricePerTonneCentsUsd;
5659
obj['remaining_mass_g'] = remainingMassG;
60+
obj['technology_type'] = technologyType;
5761
}
5862

5963
static constructFromObject(data, obj) {
@@ -136,15 +140,15 @@ class Project {
136140
obj['sdgs'] = ApiClient.convertToType(data['sdgs'], [Sdg]);
137141
}
138142

143+
if (data.hasOwnProperty('tagline')) {
144+
obj['tagline'] = ApiClient.convertToType(data['tagline'], 'String');
145+
}
146+
139147
if (data.hasOwnProperty('technology_type')) {
140148
obj['technology_type'] = TechnologyType.constructFromObject(
141149
data['technology_type']
142150
);
143151
}
144-
145-
if (data.hasOwnProperty('tagline')) {
146-
obj['tagline'] = ApiClient.convertToType(data['tagline'], 'String');
147-
}
148152
}
149153
return obj;
150154
}
@@ -182,8 +186,8 @@ Project.prototype['standard'] = undefined;
182186

183187
Project.prototype['sdgs'] = undefined;
184188

185-
Project.prototype['technology_type'] = undefined;
186-
187189
Project.prototype['tagline'] = undefined;
188190

191+
Project.prototype['technology_type'] = undefined;
192+
189193
export default Project;

src/model/TechnologyType.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import ApiClient from '../ApiClient';
99
import ParentTechnologyType from './ParentTechnologyType';
1010

1111
class TechnologyType {
12-
constructor() {
13-
TechnologyType.initialize(this);
12+
constructor(slug, name) {
13+
TechnologyType.initialize(this, slug, name);
1414
}
1515

16-
static initialize(obj) {}
16+
static initialize(obj, slug, name) {
17+
obj['slug'] = slug;
18+
obj['name'] = name;
19+
}
1720

1821
static constructFromObject(data, obj) {
1922
if (data) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
import TechnologyType from './TechnologyType';
10+
11+
class TechnologyTypeListResponse {
12+
constructor(success, error, data) {
13+
TechnologyTypeListResponse.initialize(this, success, error, data);
14+
}
15+
16+
static initialize(obj, success, error, data) {
17+
obj['success'] = success;
18+
obj['error'] = error;
19+
obj['data'] = data;
20+
}
21+
22+
static constructFromObject(data, obj) {
23+
if (data) {
24+
obj = obj || new TechnologyTypeListResponse();
25+
26+
if (data.hasOwnProperty('success')) {
27+
obj['success'] = ApiClient.convertToType(data['success'], 'Boolean');
28+
}
29+
30+
if (data.hasOwnProperty('error')) {
31+
obj['error'] = ApiClient.convertToType(data['error'], Object);
32+
}
33+
34+
if (data.hasOwnProperty('data')) {
35+
obj['data'] = ApiClient.convertToType(data['data'], [TechnologyType]);
36+
}
37+
}
38+
return obj;
39+
}
40+
}
41+
42+
TechnologyTypeListResponse.prototype['success'] = undefined;
43+
44+
TechnologyTypeListResponse.prototype['error'] = undefined;
45+
46+
TechnologyTypeListResponse.prototype['data'] = undefined;
47+
48+
export default TechnologyTypeListResponse;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect } from 'chai';
2+
import Patch from '../../../dist/index';
3+
const patch = Patch(process.env.SANDBOX_API_KEY);
4+
5+
describe('Projects TechnologyTypes Integration', function () {
6+
it.only('supports fetching the available technology_types', async function () {
7+
const { data } = await patch.technologytypes.retrieveTechnologyTypes();
8+
expect(data.length).to.be.above(0);
9+
expect(data[0].name).to.be.a('string');
10+
expect(data[0].slug).to.be.a('string');
11+
expect(data[0].parent_technology_type.slug).to.be.a('string');
12+
expect(data[0].parent_technology_type.name).to.be.a('string');
13+
});
14+
});

0 commit comments

Comments
 (0)