1.9.2 • Published 4 years ago
geom-api-ts-client v1.9.2
geom-api-ts-client
A TypeScript client library for accessing GeOM APIs
Install
yarn add geom-api-ts-client
# or, with npm
npm i geom-api-ts-client
Usage
import { Operator } from "geom-api-ts-client";
const result = Operator.getMe(config);
// use result ...
Go to the examples section for more.
Endpoints
Here follows the list of implemented endpoints, with reference to the latest API docs.
n | name | endpoint [^1] | method |
---|---|---|---|
1 | token | /token | Authentication.login |
2 | barcode | /barcode-decode | Barcode.decode |
3 | operator collection | /operatori | Operator.collection |
4 | operator me | /operatori/me | Operator.me |
5 | operator single | /operatori/{id} | Operator.single |
6 | operator activity | /operatori/{id}/attivita | Activity.collectionByOperator |
7 | machine collection | /macchine | Machine.collection |
8 | machine single | /macchine/{id} | Machine.single |
9 | machine activity | /macchine/{id}/attivita | Activity.collectionByMachine |
23 | article subdivisions | /articoli/{id}/suddivisioni | Subdivision.collectionByArticle |
27 | article subdivision details | /articoli-suddivisioni/{subdivisionId} | Subdivision.single |
32 | freshman subdivisions | /articoli-matricole/{freshmanId}/suddivisioni | Subdivision.collectionByFreshman |
34 | new article subdivision | /articoli-suddivisioni | Subdivision.create |
37 | movement reason collection | /causali-magazzino | Warehouse.Reason.getCollection |
41 | activity types collection | /tipi-attivita | Activities.ActivityType.getCollection |
44 | create warehouse movement | /movimenti-magazzino | Warehouse.Movement.create |
46 | check action action phase | /fasi-lavorazione/{id}/check-action | Job.checkAction |
48 | start activity | /attivita/start | Activity.start |
49 | stop activity by machine | /attivita-macchine/{machineActivityId}/stop | Activity.stopByMachineActivity |
50 | stop activity by machine and operator | /attivita-macchine/{machineActivityId}/stopall | Activity,stopAllByMachineActivity |
51 | stop activity by operator | /attivita-operatori/{operatorActivityId}/stop | Activity.stopByOperatorActivity |
52 | end job | /fasi-lavorazione/{id}/fine | Job.end |
57 | shape collection | /forme | Shape.collection |
58 | shape details | /forma/{id} | Shape.single |
59 | job phase search by name | /fasi-lavorazione/fasecomune/{name} | Job.byName |
[^1]: version is excluded from endpoint url
Tests
yarn test
yarn lint
# or, with docker
docker-compose build # needed the fitst time
docker-compose run yarn yarn test
docker-compose run yarn yarn lint
Examples
Functional style
import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/pipeable";
import { Operator } from "geom-api-ts-client";
pipe(
Operator.getMe({
token: "my-token-123",
settings: { url: "www.myurl.com" },
}),
TE.fold(
(err) => {
// handle the error
}),
(operator) => {
// handle the result
})),
)();
Promise style
import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/pipeable";
import { Operator } from "geom-api-ts-client";
export const toResultTask = <E, A>(te: TE.TaskEither<E, A>): T.Task<A> =>
pipe(
te,
teFold(
(err) => () => Promise.reject(err),
(res) => tOf(res),
),
);
pipe(
Operator.getMe({
token: "my-token-123",
settings: { url: "www.foo.com" },
}),
toResultTask,
)()
.then((operator) => {
// handle the result
})
.catch((err) => {
// handle the error
});
Avoid callback hell
You can make related api calls with easy functional programming features.
const settings = { url: "www.foo.com" };
const activitiesByOperator = (settings: Settings) => (
operator: Operator.Operator,
) =>
pipe(
{
IdOperatore: operator.IdOperatore,
settings: settings,
},
Activities.collectionByOperator,
);
const getMe = (settings: Settings) => Operator.getMe(settings);
pipe(
getMe({ settings: settings }),
TE.chain(activitiesByOperator({ settings: settings })),
// You may continue chaining calls
);
Credits
License
The project is MIT licensed. See LICENSE file.
1.9.1
4 years ago
1.9.2
4 years ago
1.9.0
4 years ago
1.8.0
4 years ago
1.7.4
4 years ago
1.7.3
4 years ago
1.7.2
4 years ago
1.7.1
4 years ago
1.7.0
4 years ago
1.6.0
4 years ago
1.5.0
4 years ago
1.4.0
4 years ago
1.3.2
4 years ago
1.3.1
4 years ago
1.3.0
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.2.0
4 years ago
1.1.0
4 years ago
1.0.0
4 years ago
0.0.0-development
4 years ago