opexrate
Version:
Access Open Exchange Rates API.
69 lines (66 loc) • 1.93 kB
JavaScript
var __getOwnPropNames = Object.getOwnPropertyNames;
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
// source/opexrate.ts
import axios from "axios";
var Opexrate;
var init_opexrate = __esm({
"source/opexrate.ts"() {
"use strict";
Opexrate = class {
constructor(id) {
this.id = id;
this.id = id;
}
base_api_url = "https://openexchangerates.org/api/";
async request(endpoint, params = {}) {
try {
params.app_id = this.id;
const response = await axios.get(
`${this.base_api_url}${endpoint}`,
{ params }
);
if (response.data.error === true) {
const { error, ...details } = response.data;
throw details;
} else return response.data;
} catch (error) {
throw error;
}
}
latest(params) {
return this.request("latest.json", params);
}
historical(date, params) {
return this.request(`historical/${date}.json`, params);
}
currencies(params) {
return this.request("currencies.json", params);
}
timeSeries(params) {
return this.request("time-series.json", params);
}
convert(value, from, to, params) {
return this.request(`convert/${value}/${from}/${to}`, params);
}
ohlc(params) {
return this.request("ohlc.json", params);
}
usage(params) {
return this.request("usage.json", params);
}
};
}
});
// source/main.ts
var require_main = __commonJS({
"source/main.ts"(exports, module) {
init_opexrate();
module.exports = Opexrate;
}
});
export default require_main();