@cabin-interactive/qrz-api-client
Version:
A TypeScript wrapper for the QRZ.com API
43 lines (42 loc) • 1.35 kB
JavaScript
import { HttpService } from "./services/http";
import { QsoService } from "./services/qso";
import { QrzAuthError, QrzNetworkError } from "./errors";
import { validateConfig } from "./config";
export default class QrzApiClient {
constructor(config) {
// Perform validation here instead of relying on BaseQrzService
validateConfig(config);
this.http = new HttpService(config);
this.qso = new QsoService(config, this.http);
}
async makeRequest(params) {
return this.http.post(params);
}
async testAuth() {
try {
await this.http.post({ action: 'STATUS' });
return { isValid: true };
}
catch (error) {
if (error instanceof QrzAuthError) {
return {
isValid: false,
error: error.message
};
}
if (error instanceof QrzNetworkError) {
return {
isValid: false,
error: 'Could not connect to QRZ.com API'
};
}
return {
isValid: false,
error: 'Unknown error occurred while testing API key'
};
}
}
async uploadQso(adif, options) {
return this.qso.uploadQso(adif, options);
}
}