From f3f05bd654b33f045b2419fe0490098432ad51f0 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Tue, 17 May 2022 08:21:35 -0700 Subject: [PATCH] Add support for `Accept-Language` (#66) * Add support for acceptLanguage header * Changelog --- CHANGELOG.md | 6 ++++++ README.md | 7 +++++++ package-lock.json | 30 ++++++++++++++++++------------ package.json | 2 +- src/ApiClient.js | 2 +- src/api/ProjectsApi.js | 16 +++++++++++----- test/integration/projects.test.js | 18 ++++++++++++++++++ 7 files changed, 62 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08a22ef..b1f610a 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.22.0] - 2022-05-16 + +### Added + +- Adds support for the `acceptLanguage` option on `projects`, to add support for the `Accept-Language` header. + ## [1.21.0] - 2022-05-03 ### Added diff --git a/README.md b/README.md index eff0bf2..bb7b8c7 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,8 @@ When fetching Projects, you can add filters to the query to narrow the result. C - `type` - `minimumAvailableMass` +You can also set the `acceptLanguage` option to retrieve projects in a different language. + [API Reference](https://docs.patch.io/#/?id=projects) #### Examples @@ -195,6 +197,11 @@ patch.projects.retrieveProjects({ type }); // Retrieve a filtered list of projects const minimumAvailableMass = 100; // Pass in the minimum available inventory the projects should have patch.projects.retrieveProjects({ minimumAvailableMass }); + +// Retrieve a project in another language +// See http://docs.patch.test:3000/#/internationalization for more information and support languages +const projectId = 'pro_test_1234'; +patch.projects.retrieveProject(projectId, { acceptLanguage: 'fr' }); ``` ## Contributing diff --git a/package-lock.json b/package-lock.json index 3c124c9..187b110 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.21.0", + "version": "1.22.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.21.0", + "version": "1.22.0", "license": "MIT", "dependencies": { "query-string": "^7.0.1", @@ -2178,14 +2178,20 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001279", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001279.tgz", - "integrity": "sha512-VfEHpzHEXj6/CxggTwSFoZBBYGQfQv9Cf42KPlO79sWXCD1QNKWKsKzFeWL7QpZHJQYAvocqV6Rty1yJMkqWLQ==", + "version": "1.0.30001341", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz", + "integrity": "sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==", "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + } + ] }, "node_modules/chai": { "version": "4.3.4", @@ -6602,9 +6608,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001279", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001279.tgz", - "integrity": "sha512-VfEHpzHEXj6/CxggTwSFoZBBYGQfQv9Cf42KPlO79sWXCD1QNKWKsKzFeWL7QpZHJQYAvocqV6Rty1yJMkqWLQ==", + "version": "1.0.30001341", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz", + "integrity": "sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==", "dev": true }, "chai": { diff --git a/package.json b/package.json index 0432280..b01a791 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.21.0", + "version": "1.22.0", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index e1fae62..7611fe9 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.21.0' + 'User-Agent': 'patch-node/1.22.0' }; /** diff --git a/src/api/ProjectsApi.js b/src/api/ProjectsApi.js index ab4748d..0c2a670 100644 --- a/src/api/ProjectsApi.js +++ b/src/api/ProjectsApi.js @@ -15,7 +15,9 @@ export default class ProjectsApi { this.apiClient = apiClient || ApiClient.instance; } - retrieveProjectWithHttpInfo(id) { + retrieveProjectWithHttpInfo(id, opts) { + opts = opts || {}; + let postBody = null; // verify the required parameter 'id' is set @@ -29,7 +31,9 @@ export default class ProjectsApi { id: id }; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Accept-Language': opts['acceptLanguage'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -52,8 +56,8 @@ export default class ProjectsApi { ); } - retrieveProject(id) { - return this.retrieveProjectWithHttpInfo(id); + retrieveProject(id, opts) { + return this.retrieveProjectWithHttpInfo(id, opts); } retrieveProjectsWithHttpInfo(opts) { @@ -71,7 +75,9 @@ export default class ProjectsApi { minimum_available_mass: opts['minimumAvailableMass'] }; - let headerParams = {}; + let headerParams = { + 'Accept-Language': opts['acceptLanguage'] + }; let formParams = {}; let authNames = ['bearer_auth']; diff --git a/test/integration/projects.test.js b/test/integration/projects.test.js index 4f308d1..154d44b 100644 --- a/test/integration/projects.test.js +++ b/test/integration/projects.test.js @@ -8,6 +8,14 @@ describe('Project Integration', function () { expect(data.length).to.be.above(0); }); + it('supports fetching the available projects in the given language', async function () { + const { data } = await patch.projects.retrieveProjects({ + acceptLanguage: 'fr' + }); + expect(data.length).to.be.above(0); + expect(data[0].name).to.include('Projet'); // French + }); + it('supports fetching a single project', async function () { const { data } = await patch.projects.retrieveProjects(); const projectId = data[0].id; @@ -39,6 +47,16 @@ describe('Project Integration', function () { expect(inventory[0].unit).to.be.a('string'); }); + it('supports fetching a single project in a different language', async function () { + const { data } = await patch.projects.retrieveProjects(); + const projectId = data[0].id; + const projectResponse = await patch.projects.retrieveProject(projectId, { + acceptLanguage: 'fr' + }); + + expect(projectResponse.data.name).to.include('Projet'); // French + }); + it('supports fetching all projects from the United States', async function () { const country = 'US'; const { data } = await patch.projects.retrieveProjects({ country });