sh-albarrak-api-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

wakatime E2E Node.js CI GitHub License GitHub Release codecov Size typescript npm npm GitHub issues GitHub stars

sh-albarrak-api-sdk

SDK to access sh-albarrak.com APIs.

Installation

To install sh-albarrak-api-sdk, use npm or yarn:

npm install sh-albarrak-api-sdk
# or
yarn add sh-albarrak-api-sdk
# or
pnpm i sh-albarrak-api-sdk

Usage

Importing the SDK

import { getAllIdsFor, DataType } from 'sh-albarrak-api-sdk';

getAllIdsFor()

Gets all the unique identifiers for the given data type.

(async () => {
    try {
        const actual = await getAllIdsFor(DataType.BookExplanations); // [100, 200, 3011]
    } catch (error) {
        console.error(error.message);
    }
})();

getDataItems()

Retrieve a list of items for a data type. Note that AudioBooksLessons, BooksExplanationsLessons, and Recitations are not supported.

(async () => {
    try {
        const data = await getDataItems(DataType.Articles); // { items: [...], next: '/api/...' }
        const nextData = await getNextItems(data.next);
    } catch (error) {
        console.error(error.message);
    }
})();

If the return value includes a next path, you can use that to call getNextItems with that url to get the next set of paginated items.

getPage()

Retrieve a a specific item.

import { getPage } from 'sh-albarrak-api-sdk';

(async () => {
    try {
        const article = await getPage(100, DataType.Articles);
    } catch (error) {
        console.error(error.message);
    }
})();

getCollection()

Retrieve a a specific collection.

import { getCollection } from 'sh-albarrak-api-sdk';

(async () => {
    try {
        const audioBook = await getCollection(100, DataType.AudioBooks);
        const nextData = await getNextItems(audioBook.nextUrl);
    } catch (error) {
        console.error(error.message);
    }
})();

Package Sidebar

Install

npm i sh-albarrak-api-sdk

Weekly Downloads

4

Version

2.0.0

License

MIT

Unpacked Size

36.3 kB

Total Files

6

Last publish

Collaborators

  • ragaeeb