fritzbox-api
Version:
Straightforward, lightweight and extendable Node.js library to communicate with FRITZ!Box devices
35 lines (28 loc) • 856 B
JavaScript
// Copyright (c) 2024, Thorsten A. Weintz. All rights reserved.
// Licensed under the MIT license. See LICENSE in the project root for license information.
import FritzBoxApi, { url, login } from './config.mjs';
/**
* Writes a message to the console.
*/
const log = console.log;
/**
* Initializes new instance of @see FritzBoxApi and sets options.
*/
const fritzBoxApi = new FritzBoxApi({ url });
/**
* Processes authentication by username and password.
*/
const isValidAuth = await login(fritzBoxApi);
/**
* Validates authentication state before data fetching.
*/
if (isValidAuth) {
/**
* Fetches fonbook of FRITZ!Box device.
*/
const fonBook = await fritzBoxApi.getFonBook();
/**
* Prints fonbook of @see FritzBoxApi to stdout.
*/
log(fonBook?.phonebooks?.phonebook);
}