revolut-sdk
Version:
SDK for Revolut API
27 lines (26 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Either_1 = require("fp-ts/lib/Either");
const Option_1 = require("fp-ts/lib/Option");
const Task_1 = require("fp-ts/lib/Task");
const TaskEither_1 = require("fp-ts/lib/TaskEither");
class API {
constructor(client) {
this.client = client;
this.fetch = (url, config) => {
return this.handleError(this.client.get(url, config));
};
this.post = (url, data) => this.handleError(this.client.post(url, data));
this.put = (url, data, axiosReqConfig) => {
return this.handleError(this.client.put(url, data, axiosReqConfig));
};
this.delete = (url, axiosReqConfig) => {
return this.handleError(this.client.delete(url, axiosReqConfig));
};
this.handleError = (promise) => new TaskEither_1.TaskEither(new Task_1.Task(() => promise
.then((res) => Either_1.right(res.data))
.catch((err) => Either_1.left(err))
.then(result => result.map(v => Option_1.fromNullable(v)))));
}
}
exports.default = API;