From 30456e9ca18e90c09093c6a4cd74bd8a540f3a8d Mon Sep 17 00:00:00 2001 From: Aliana Melendez Date: Mon, 15 Nov 2021 13:56:19 -0500 Subject: [PATCH] Adds highlights to projects response (#51) * Adds highlights to projects response * update a to an * Use docker for build stage * Tweak * Reran make build after merging in pc/docker branch * Add icon_url Co-authored-by: Paul Cothenet --- CHANGELOG.md | 6 ++++ package-lock.json | 4 +-- package.json | 2 +- src/ApiClient.js | 2 +- src/model/Highlight.js | 47 +++++++++++++++++++++++++++++++ src/model/Project.js | 19 +++++++++++-- test/integration/projects.test.js | 1 + 7 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 src/model/Highlight.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6ee03..6ba4d1d 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.2] - 2021-11-08 + +### Added + +- Adds highlights to project responses + ## [1.15.1] - 2021-11-04 ### Added diff --git a/package-lock.json b/package-lock.json index 18ee96e..9c144a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.15.1", + "version": "1.15.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.15.1", + "version": "1.15.2", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index e8d8ee6..e9a17ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.15.1", + "version": "1.15.2", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index 4bc88de..964959f 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.15.1' + 'User-Agent': 'patch-node/1.15.2' }; /** diff --git a/src/model/Highlight.js b/src/model/Highlight.js new file mode 100644 index 0000000..a046201 --- /dev/null +++ b/src/model/Highlight.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'; + +class Highlight { + constructor(slug, title, iconUrl) { + Highlight.initialize(this, slug, title, iconUrl); + } + + static initialize(obj, slug, title, iconUrl) { + obj['slug'] = slug; + obj['title'] = title; + obj['icon_url'] = iconUrl; + } + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new Highlight(); + + if (data.hasOwnProperty('slug')) { + obj['slug'] = ApiClient.convertToType(data['slug'], 'String'); + } + + if (data.hasOwnProperty('title')) { + obj['title'] = ApiClient.convertToType(data['title'], 'String'); + } + + if (data.hasOwnProperty('icon_url')) { + obj['icon_url'] = ApiClient.convertToType(data['icon_url'], 'String'); + } + } + return obj; + } +} + +Highlight.prototype['slug'] = undefined; + +Highlight.prototype['title'] = undefined; + +Highlight.prototype['icon_url'] = undefined; + +export default Highlight; diff --git a/src/model/Project.js b/src/model/Project.js index 09f009c..57056d8 100644 --- a/src/model/Project.js +++ b/src/model/Project.js @@ -6,6 +6,7 @@ */ import ApiClient from '../ApiClient'; +import Highlight from './Highlight'; import Photo from './Photo'; import Sdg from './Sdg'; import Standard from './Standard'; @@ -21,7 +22,8 @@ class Project { developer, averagePricePerTonneCentsUsd, remainingMassG, - technologyType + technologyType, + highlights ) { Project.initialize( this, @@ -33,7 +35,8 @@ class Project { developer, averagePricePerTonneCentsUsd, remainingMassG, - technologyType + technologyType, + highlights ); } @@ -47,7 +50,8 @@ class Project { developer, averagePricePerTonneCentsUsd, remainingMassG, - technologyType + technologyType, + highlights ) { obj['id'] = id; obj['production'] = production; @@ -58,6 +62,7 @@ class Project { obj['average_price_per_tonne_cents_usd'] = averagePricePerTonneCentsUsd; obj['remaining_mass_g'] = remainingMassG; obj['technology_type'] = technologyType; + obj['highlights'] = highlights; } static constructFromObject(data, obj) { @@ -153,6 +158,12 @@ class Project { data['technology_type'] ); } + + if (data.hasOwnProperty('highlights')) { + obj['highlights'] = ApiClient.convertToType(data['highlights'], [ + Highlight + ]); + } } return obj; } @@ -196,4 +207,6 @@ Project.prototype['tagline'] = undefined; Project.prototype['technology_type'] = undefined; +Project.prototype['highlights'] = undefined; + export default Project; diff --git a/test/integration/projects.test.js b/test/integration/projects.test.js index 67e01cf..1a0122b 100644 --- a/test/integration/projects.test.js +++ b/test/integration/projects.test.js @@ -20,6 +20,7 @@ describe('Project Integration', function () { expect(projectResponse.data.mechanism).to.be.a('string'); expect(projectResponse.data.latitude).to.be.a('number'); expect(projectResponse.data.longitude).to.be.a('number'); + expect(projectResponse.data.highlights).to.be.an('array'); const technology_type = projectResponse.data.technology_type; expect(technology_type.slug).to.be.a('string');