UNPKG

aa-daily-reflections

Version:

A lightweight Node.js library to fetch Daily Reflections from Alcoholics Anonymous (AA)

38 lines (37 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DailyReflections = void 0; const date_1 = require("./utils/date"); const url_1 = require("./utils/url"); const http_client_1 = require("./services/http-client"); const reflection_parser_1 = require("./parsers/reflection-parser"); class DailyReflections { constructor(language = 'en') { this.language = language; this.httpClient = new http_client_1.HttpClient(); this.parser = new reflection_parser_1.ReflectionParser(); } async getToday() { const { month, day } = (0, date_1.getCurrentDate)(); return this.getReflection(month, day); } async getReflection(month, day) { (0, date_1.validateDate)(month, day); const url = (0, url_1.buildApiUrl)(month, day, this.language); try { const response = await this.httpClient.fetchData(url); return this.parser.parse(response); } catch (error) { throw new Error(`Failed to fetch daily reflection: ${error}`); } } setLanguage(language) { this.language = language; } getLanguage() { return this.language; } } exports.DailyReflections = DailyReflections; exports.default = DailyReflections;