sh-albarrak-api-sdk
v2.0.0
Published
JavaScript SDK for accessing sh-albarrak.com content
Downloads
20
Maintainers
Readme
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);
}
})();