"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DDApi {
    constructor(settings, request) {
        this.apiUrl = settings.api_host;
        this.request = request;
    }
    async get(endpoint, params) {
        const url = new URL(`${this.apiUrl}${endpoint}`);
        if (params) {
            url.search = new URLSearchParams(Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))).toString();
        }
        return await this.request(`${url}`, {
            method: 'GET'
        });
    }
    async post(endpoint, data) {
        return await this.request(`${this.apiUrl}${endpoint}`, {
            method: 'POST',
            json: data,
            headers: { 'Content-Type': 'application/json' }
        });
    }
    async delete(endpoint) {
        return await this.request(`${this.apiUrl}${endpoint}`, {
            method: 'DELETE'
        });
    }
    async patch(endpoint, data) {
        return await this.request(`${this.apiUrl}${endpoint}`, {
            method: 'PATCH',
            json: data,
            headers: { 'Content-Type': 'application/json' }
        });
    }
}
exports.default = DDApi;
//# sourceMappingURL=dd-api.js.map