voltra-hub-api-client
Version:
A Voltra Hub API Client
35 lines (34 loc) • 1.17 kB
JavaScript
import createClient from "openapi-fetch";
export class VoltraHubAPIClient {
constructor(baseUrl) {
this.authenticate = {
onRequest: ({ request }) => {
if (this.authentication) {
request.headers.set('Authorization', `Bearer ${this.authentication}`);
}
return request;
}
};
this.auth = {
set: (access_token) => {
this.authentication = access_token;
},
get: () => {
return this.authentication;
}
};
this.pvpc = {
get: (date) => {
const year = date.getFullYear();
const month = `${date.getMonth() + 1}`.padStart(2, '0');
const day = date.getDate();
return this.client.GET('/pvpc', { params: { query: { date: [year, month, day].join('-') } } });
}
};
this.client = createClient({ baseUrl, headers: { Bearer: 'access_token' } });
this.client.use(this.authenticate);
}
healthCheck() {
return this.client.GET('/health-check');
}
}