Skip to content

Commit

Permalink
Add support for Accept-Language (#66)
Browse files Browse the repository at this point in the history
* Add support for acceptLanguage header

* Changelog
  • Loading branch information
pcothenet authored May 17, 2022
1 parent 04165df commit f3f05bd
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 19 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.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
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
30 changes: 18 additions & 12 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.21.0",
"version": "1.22.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.21.0'
'User-Agent': 'patch-node/1.22.0'
};

/**
Expand Down
16 changes: 11 additions & 5 deletions src/api/ProjectsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'];
Expand All @@ -52,8 +56,8 @@ export default class ProjectsApi {
);
}

retrieveProject(id) {
return this.retrieveProjectWithHttpInfo(id);
retrieveProject(id, opts) {
return this.retrieveProjectWithHttpInfo(id, opts);
}

retrieveProjectsWithHttpInfo(opts) {
Expand All @@ -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'];
Expand Down
18 changes: 18 additions & 0 deletions test/integration/projects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit f3f05bd

Please sign in to comment.