diff --git a/src/quran/audio.test.ts b/src/apis/audio.test.ts similarity index 100% rename from src/quran/audio.test.ts rename to src/apis/audio.test.ts diff --git a/src/quran/audio.ts b/src/apis/audio.ts similarity index 93% rename from src/quran/audio.ts rename to src/apis/audio.ts index 9d2ee5e..9a57128 100644 --- a/src/quran/audio.ts +++ b/src/apis/audio.ts @@ -1,7 +1,13 @@ import { AxiosError } from "axios"; import url from "url"; -import Api from "../api"; -import { AudioApi, AudioQueryParams, IAudio, IListOfAllAudioOfAReciter, IRecitation, ISingleRecitation, IReciters, IAyahRecitationSpecificSurah, IAyahRecitationSpecificJuz, IAyahRecitationSpecificMadaniMushafPage, IAyahRecitationSpecificRubelHizb, IAyahRecitationSpecificHizb, IAyahRecitationSpecificAyah, ALLOWED_LANGUAGES } from "../types"; +import Api from "../req"; +import { + AudioApi, AudioQueryParams, + IAudio, IListOfAllAudioOfAReciter, IRecitation, + ISingleRecitation, IReciters, IAyahRecitationSpecificSurah, IAyahRecitationSpecificJuz, + IAyahRecitationSpecificMadaniMushafPage, IAyahRecitationSpecificRubelHizb, + IAyahRecitationSpecificHizb, IAyahRecitationSpecificAyah, ALLOWED_LANGUAGES +} from "../types"; import { handleError, handleResponse } from "../utils"; const api = Api(); @@ -127,5 +133,4 @@ const audio: AudioApi = { }; - export default audio; \ No newline at end of file diff --git a/src/quran/chapter.test.ts b/src/apis/chapter.test.ts similarity index 100% rename from src/quran/chapter.test.ts rename to src/apis/chapter.test.ts diff --git a/src/quran/chapter.ts b/src/apis/chapter.ts similarity index 98% rename from src/quran/chapter.ts rename to src/apis/chapter.ts index 2875a97..fcd4f0d 100644 --- a/src/quran/chapter.ts +++ b/src/apis/chapter.ts @@ -1,5 +1,5 @@ import { AxiosError } from "axios"; -import Api from "../api"; +import Api from "../req"; import { ChapterApi, ListChapters, Chapter, ChapterInfo, ALLOWED_LANGUAGES } from "../types"; import { handleError, handleResponse } from "../utils"; diff --git a/src/quran/index.ts b/src/apis/index.ts similarity index 100% rename from src/quran/index.ts rename to src/apis/index.ts diff --git a/src/quran/juz.test.ts b/src/apis/juz.test.ts similarity index 100% rename from src/quran/juz.test.ts rename to src/apis/juz.test.ts diff --git a/src/quran/juz.ts b/src/apis/juz.ts similarity index 94% rename from src/quran/juz.ts rename to src/apis/juz.ts index 35241ed..c4479f5 100644 --- a/src/quran/juz.ts +++ b/src/apis/juz.ts @@ -1,5 +1,5 @@ import { AxiosError } from "axios"; -import Api from "../api"; +import Api from "../req"; import { JuzApi, JuzResponse } from "../types"; import { handleError, handleResponse } from "../utils"; diff --git a/src/apis/quran.ts b/src/apis/quran.ts new file mode 100644 index 0000000..a69b951 --- /dev/null +++ b/src/apis/quran.ts @@ -0,0 +1,90 @@ +import { AxiosError } from "axios"; +import Api from "../req"; +import { + QuranQuery, QuranResponse, UthmaniTajweedResponse, + UthmaniScriptResponse, + UthmaniSimpleScriptResponse, ImlaeiSimpleTextResponse, + TranslationQuery, SingleTranslationResponse, + SingleTafsirResponse, + GlyphCodesOfAyahV1Response, + GlyphCodesOfAyahV2Response, + QuranApi +} from "../types"; +import { handleError, handleResponse } from "../utils"; + +const api = Api(); + +const quran: QuranApi = { + getIndoPakScriptOfAyah(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/code_v1?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/code_v1'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getUthmaniTajweedScriptOfAyah(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/uthmani_tajweed?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/uthmani_tajweed'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getUthmaniScriptOfAyah(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/uthmani?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/uthmani'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getUthmaniSimpleScriptOfAyah(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/uthmani_simple?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/uthmani_simple'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getImlaeiSimpleTextOfAyah(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/imlaei?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/imlaei'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getASingleTranslation(translation_id: string, query?: TranslationQuery): Promise { + const uri = query ? `/quran/translations/${translation_id}?${new URLSearchParams(query as URLSearchParams)}` : `/quran/translations/${translation_id}`; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getSingleTafsir(tafsir_id: string, query?: TranslationQuery): Promise { + const uri = query ? `/quran/tafsirs/${tafsir_id}/info?${new URLSearchParams(query as URLSearchParams)}` : `/quran/tafsirs/${tafsir_id}/info`; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getGlyphCodesOfAyahV1(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/code_v1?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/code_v1'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, + getGlyphCodesOfAyahV2(query?: QuranQuery): Promise { + const uri = query ? `/quran/verses/code_v2?${new URLSearchParams(query as URLSearchParams)}` : '/quran/verses/code_v2'; + return new Promise((resolve, reject) => { + api.get(uri) + .then(handleResponse(resolve)) + .catch(handleError(reject)); + }); + }, +}; \ No newline at end of file diff --git a/src/quran/resource.test.ts b/src/apis/resource.test.ts similarity index 100% rename from src/quran/resource.test.ts rename to src/apis/resource.test.ts diff --git a/src/quran/resource.ts b/src/apis/resource.ts similarity index 99% rename from src/quran/resource.ts rename to src/apis/resource.ts index 0456f85..8d165d0 100644 --- a/src/quran/resource.ts +++ b/src/apis/resource.ts @@ -1,5 +1,5 @@ import { AxiosError } from "axios"; -import Api from "../api"; +import Api from "../req"; import { ResourceApi, RecitaionInfo, TranslationInfo, TranslationResponse, TafsirsResponse, TafsirInfoResponse, RecitationStyleResponse, LanguageResponse, ChapterInfos, VerseMediaResponse, ALLOWED_LANGUAGES } from "../types"; import { handleError, handleResponse } from "../utils"; diff --git a/src/quran/verse.test.ts b/src/apis/verse.test.ts similarity index 100% rename from src/quran/verse.test.ts rename to src/apis/verse.test.ts diff --git a/src/quran/verse.ts b/src/apis/verse.ts similarity index 99% rename from src/quran/verse.ts rename to src/apis/verse.ts index a3edc70..552f503 100644 --- a/src/quran/verse.ts +++ b/src/apis/verse.ts @@ -1,5 +1,5 @@ import { AxiosError } from "axios"; -import Api from "../api"; +import Api from "../req"; import { ALLOWED_LANGUAGES, VerseApi, VerseQuery, VerseResponse } from "../types"; import { handleError, handleResponse } from "../utils"; diff --git a/src/api.ts b/src/req.ts similarity index 100% rename from src/api.ts rename to src/req.ts diff --git a/src/types.ts b/src/types.ts index 789529e..4055bc7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -363,4 +363,139 @@ export interface VerseApi { getVerseByRubElHizbNumber: (rub_el_hizb_number: string, query?: VerseQuery) => Promise; getSpecificVerseByVerseKey: (verse_key: string, query?: VerseQuery) => Promise; getRandomAyah: (query?: VerseQuery) => Promise; +}; + +export interface QuranQuery { + chapter_number?: string; + juz_number?: string; + page_number?: string; + hizb_number?: string; + rub_el_hizb_number?: string; + verse_key?: string; +}; + +export interface QuranResponse { + verses: IndoPakVerse[]; +}; + +export interface IndoPakVerse { + id: number; + verse_key: string; + text_indopak: string; +}; + +export interface UthmaniTajweedResponse { + verses: UthManiVerse[]; +}; + +export interface UthManiVerse { + id: number; + verse_key: string; + text_uthmani_tajweed: string; +}; + +export interface UthmaniScriptResponse { + verses: UthmaniScript[]; +}; + +export interface UthmaniScript { + id: number; + verse_key: string; + text_uthmani: string; +}; + +export interface UthmaniSimpleScriptResponse { + verses: UthmaniSimpleScript[]; +}; + +export interface UthmaniSimpleScript { + id: number; + verse_key: string; + text_uthmani_simple: string; +}; + +export interface ImlaeiSimpleTextResponse { + verses: ImlaeiSimpleText[]; +}; + +export interface ImlaeiSimpleText { + id: number; + verse_key: string; + text_imlaei: string; +}; + +export interface TranslationQuery { + fields?: string; + chapter_number?: string; + juz_number?: string; + page_number?: string; + hizb_number?: string; + rub_el_hizb_number?: string; + verse_key?: string; +}; + +export interface SingleTranslationResponse { + translations: Translation[]; + meta: TranslationMeta; +}; + +export interface VerseTranslation { + resource_id: number; + text: string; +}; + +export interface TranslationMeta { + translation_name: string; + author_name: string; +}; + +export interface SingleTafsirResponse { + tafsirs: Tafsir[] + meta: TafsirMeta; +}; + +export interface SingleTafsir { + resource_id: number; + text: string; +}; + +export interface TafsirMeta { + tafsir_name: string; + author_name: string; +}; + +export interface GlyphCodesOfAyahV1Response { + verses: GlyphCodesOfAyahV1[]; +}; + +export interface GlyphCodesOfAyahV1 { + id: number; + verse_key: string; + code_v1: string; + v1_page: number; +}; + + +export interface GlyphCodesOfAyahV2Response { + verses: GlyphCodesOfAyahV2[]; +} + +export interface GlyphCodesOfAyahV2 { + id: number; + verse_key: string; + code_v2: string; + v2_page: number; +}; + + +export interface QuranApi { + getIndoPakScriptOfAyah: (query?: QuranQuery) => Promise; + getUthmaniTajweedScriptOfAyah: (query?: QuranQuery) => Promise; + getUthmaniScriptOfAyah: (query?: QuranQuery) => Promise; + getUthmaniSimpleScriptOfAyah: (query?: QuranQuery) => Promise; + getImlaeiSimpleTextOfAyah: (query?: QuranQuery) => Promise; + getASingleTranslation: (translation_id: string, query?: TranslationQuery) => Promise; + getSingleTafsir: (tafsir_id: string, query?: TranslationQuery) => Promise; + getGlyphCodesOfAyahV1: (query?: QuranQuery) => Promise; + getGlyphCodesOfAyahV2: (query?: QuranQuery) => Promise; }; \ No newline at end of file