@clarify/api
v0.4.0
Published
Access Clarify.io’s API with ease using our API client
Downloads
24
Readme
Clarify API Client for JavaScript
Access Clarify.io’s API with ease using our API client for JavaScript
Install
The API client requires that the host application provides the package node-fetch
v2.
npm install @clarify/api node-fetch@2
Examples
import {Client} from '@clarify/api';
let client = new Client({
apiUrl: 'https://api.clarify.io/v1/',
integration: 'integration-id',
credentials: {
"type": "client-credentials",
"clientId": 'someId',
"clientSecret": 'someSecret',
}
});
let data = await client.insert({
data: {
times: [ "2022-03-27T17:20:12.046+02:00" ],
series: {
data: [ 20.69027555977774 ]
}
}
});
Tests
The companion package @clarify/api-test-support
allows you to easily simulate scenarios without having to stub out the library
import {validToken, rpc, CLARIFY_API_URL, insert} from '@clarify/api-test-support';
import {Client} from '@clarify/api';
import {setupServer} from 'msw/node';
import {fake} from 'sinon';
let server = setupServer();
server.listen();
let client = new Client({
apiUrl: CLARIFY_API_URL,
integration: 'c8u7thurpn5dtgek91b0',
credentials: {
"type": "client-credentials",
"clientId": 'someId',
"clientSecret": 'someSecret',
}
});
let insertRequest = fake();
let clarifyAPI = rpc.link(`${CLARIFY_API_URL}rpc`);
server.resetHandlers(
validToken(),
insert(clarifyAPI, insertRequest),
);
let data = await client.insert({
data: {
times: [ "2022-03-27T17:20:12.046+02:00" ],
series: {
data: [ 20.69027555977774 ]
}
}
});
assert(data)
assert(insertRequest.calledOnce);