Skip to content

Commit f3f05bd

Browse files
authored
Add support for Accept-Language (#66)
* Add support for acceptLanguage header * Changelog
1 parent 04165df commit f3f05bd

File tree

7 files changed

+62
-19
lines changed

7 files changed

+62
-19
lines changed

Diff for: CHANGELOG.md

+6
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.22.0] - 2022-05-16
9+
10+
### Added
11+
12+
- Adds support for the `acceptLanguage` option on `projects`, to add support for the `Accept-Language` header.
13+
814
## [1.21.0] - 2022-05-03
915

1016
### Added

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ When fetching Projects, you can add filters to the query to narrow the result. C
171171
- `type`
172172
- `minimumAvailableMass`
173173

174+
You can also set the `acceptLanguage` option to retrieve projects in a different language.
175+
174176
[API Reference](https://docs.patch.io/#/?id=projects)
175177

176178
#### Examples
@@ -195,6 +197,11 @@ patch.projects.retrieveProjects({ type });
195197
// Retrieve a filtered list of projects
196198
const minimumAvailableMass = 100; // Pass in the minimum available inventory the projects should have
197199
patch.projects.retrieveProjects({ minimumAvailableMass });
200+
201+
// Retrieve a project in another language
202+
// See http://docs.patch.test:3000/#/internationalization for more information and support languages
203+
const projectId = 'pro_test_1234';
204+
patch.projects.retrieveProject(projectId, { acceptLanguage: 'fr' });
198205
```
199206

200207
## Contributing

Diff for: package-lock.json

+18-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

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

Diff for: src/ApiClient.js

+1-1
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.21.0'
19+
'User-Agent': 'patch-node/1.22.0'
2020
};
2121

2222
/**

Diff for: src/api/ProjectsApi.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export default class ProjectsApi {
1515
this.apiClient = apiClient || ApiClient.instance;
1616
}
1717

18-
retrieveProjectWithHttpInfo(id) {
18+
retrieveProjectWithHttpInfo(id, opts) {
19+
opts = opts || {};
20+
1921
let postBody = null;
2022

2123
// verify the required parameter 'id' is set
@@ -29,7 +31,9 @@ export default class ProjectsApi {
2931
id: id
3032
};
3133
let queryParams = {};
32-
let headerParams = {};
34+
let headerParams = {
35+
'Accept-Language': opts['acceptLanguage']
36+
};
3337
let formParams = {};
3438

3539
let authNames = ['bearer_auth'];
@@ -52,8 +56,8 @@ export default class ProjectsApi {
5256
);
5357
}
5458

55-
retrieveProject(id) {
56-
return this.retrieveProjectWithHttpInfo(id);
59+
retrieveProject(id, opts) {
60+
return this.retrieveProjectWithHttpInfo(id, opts);
5761
}
5862

5963
retrieveProjectsWithHttpInfo(opts) {
@@ -71,7 +75,9 @@ export default class ProjectsApi {
7175

7276
minimum_available_mass: opts['minimumAvailableMass']
7377
};
74-
let headerParams = {};
78+
let headerParams = {
79+
'Accept-Language': opts['acceptLanguage']
80+
};
7581
let formParams = {};
7682

7783
let authNames = ['bearer_auth'];

Diff for: test/integration/projects.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ describe('Project Integration', function () {
88
expect(data.length).to.be.above(0);
99
});
1010

11+
it('supports fetching the available projects in the given language', async function () {
12+
const { data } = await patch.projects.retrieveProjects({
13+
acceptLanguage: 'fr'
14+
});
15+
expect(data.length).to.be.above(0);
16+
expect(data[0].name).to.include('Projet'); // French
17+
});
18+
1119
it('supports fetching a single project', async function () {
1220
const { data } = await patch.projects.retrieveProjects();
1321
const projectId = data[0].id;
@@ -39,6 +47,16 @@ describe('Project Integration', function () {
3947
expect(inventory[0].unit).to.be.a('string');
4048
});
4149

50+
it('supports fetching a single project in a different language', async function () {
51+
const { data } = await patch.projects.retrieveProjects();
52+
const projectId = data[0].id;
53+
const projectResponse = await patch.projects.retrieveProject(projectId, {
54+
acceptLanguage: 'fr'
55+
});
56+
57+
expect(projectResponse.data.name).to.include('Projet'); // French
58+
});
59+
4260
it('supports fetching all projects from the United States', async function () {
4361
const country = 'US';
4462
const { data } = await patch.projects.retrieveProjects({ country });

0 commit comments

Comments
 (0)