@matheustrres/brasilapi
Version:
Lightweight, easy-to-use & free of dependencies wrapper for BrasilAPI
98 lines • 3.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrasilAPICPTEC = void 0;
const source_1 = require("./source");
const http_client_1 = require("../clients/http-client");
const paginator_1 = require("../utils/paginator");
/**
* Represents the source from BrasilAPI CPTEC's endpoint responses
*/
class BrasilAPICPTEC extends source_1.Source {
URL = 'https://brasilapi.com.br/api/cptec/v1';
/**
* Lists all the cities with their respective codes in the CPTEC services
*
* @param {ListParams} [params] - The listing parameters
* @param {Number} [params.itemsPerPage] - The limit of items per page
* @param {Number} [params.page] - The page number to start with
* @param {Number} [params.skip] - The amount of items to skip
* @param {Number} [params.take] - The amount of items to take
* @returns {Promise<Result<Paginator<City>>>}
*/
async listCities(params) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/cidade`);
return this.followUp(new paginator_1.Paginator({
items: res,
...params,
}));
}
/**
* Lists the current weather conditions in the country's capitals,
* based on the ground stations at their airport
*
* @param {ListParams} [params] - The listing parameters
* @param {Number} [params.itemsPerPage] - The limit of items per page
* @param {Number} [params.page] - The page number to start with
* @param {Number} [params.skip] - The amount of items to skip
* @param {Number} [params.take] - The amount of items to take
* @returns {Promise<Result<Paginator<Weather>>>}
*/
async listWeatherInCapitals(params) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/clima/capital`);
return this.followUp(new paginator_1.Paginator({
items: res,
...params,
}));
}
/**
* Lists all the cities corresponding to the search term along with their
* respective codes in the CPTEC services
*
* @param {String} cityName - The name of the city to search for
* @param {ListParams} [params] - The listing parameters
* @param {Number} [params.itemsPerPage] - The limit of items per page
* @param {Number} [params.page] - The page number to start with
* @param {Number} [params.skip] - The amount of items to skip
* @param {Number} [params.take] - The amount of items to take
* @returns {Promise<Result<Paginator<City>>>}
*/
async getCity(cityName, params) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/cidade/${cityName}`);
return this.followUp(new paginator_1.Paginator({
items: res,
...params,
}));
}
/**
* Gets current weather conditions at an airport
*
* @param {String} icaoCode - The airport ICAO code
* @returns {Promise<Result<Weather>>}
*/
async getAirportWeather(icaoCode) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/clima/aeroporto/${icaoCode}`);
return this.followUp(res);
}
/**
* Gets the weather forecast for 1 day in the city entered
*
* @param {Number} cityCode - The city code
* @returns {Promise<Result<WeatherForecast>>}
*/
async getCityWeatherForecast(cityCode) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/clima/previsao/${cityCode}`);
return this.followUp(res);
}
/**
* Gets the ocean forecast for 1 day in the city entered
*
* @param {Number} cityCode - The city code
* @returns {Promise<Result<OceanForecast>>}
*/
async getCityOceanForecast(cityCode) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/ondas/${cityCode}`);
return this.followUp(res);
}
}
exports.BrasilAPICPTEC = BrasilAPICPTEC;
//# sourceMappingURL=cptec.js.map