Skip to content

Commit

Permalink
feat: quran api wrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
PrantaDas committed Aug 7, 2024
1 parent bd4d879 commit 6d94c15
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 7 deletions.
File renamed without changes.
11 changes: 8 additions & 3 deletions src/quran/audio.ts → src/apis/audio.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -127,5 +133,4 @@ const audio: AudioApi = {

};


export default audio;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/quran/chapter.ts → src/apis/chapter.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/quran/juz.ts → src/apis/juz.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
90 changes: 90 additions & 0 deletions src/apis/quran.ts
Original file line number Diff line number Diff line change
@@ -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<QuranResponse | AxiosError | Error> {
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<UthmaniTajweedResponse | AxiosError | Error> {
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<UthmaniScriptResponse | AxiosError | Error> {
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<UthmaniSimpleScriptResponse | AxiosError | Error> {
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<ImlaeiSimpleTextResponse | AxiosError | Error> {
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<SingleTranslationResponse | AxiosError | Error> {
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<SingleTafsirResponse | AxiosError | Error> {
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<GlyphCodesOfAyahV1Response | AxiosError | Error> {
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<GlyphCodesOfAyahV2Response | AxiosError | Error> {
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));
});
},
};
File renamed without changes.
2 changes: 1 addition & 1 deletion src/quran/resource.ts → src/apis/resource.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/quran/verse.ts → src/apis/verse.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
File renamed without changes.
135 changes: 135 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,139 @@ export interface VerseApi {
getVerseByRubElHizbNumber: (rub_el_hizb_number: string, query?: VerseQuery) => Promise<VerseResponse | Error | AxiosError>;
getSpecificVerseByVerseKey: (verse_key: string, query?: VerseQuery) => Promise<VerseResponse | Error | AxiosError>;
getRandomAyah: (query?: VerseQuery) => Promise<VerseResponse | Error | AxiosError>;
};

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<QuranResponse | AxiosError | Error>;
getUthmaniTajweedScriptOfAyah: (query?: QuranQuery) => Promise<UthmaniTajweedResponse | AxiosError | Error>;
getUthmaniScriptOfAyah: (query?: QuranQuery) => Promise<UthmaniScriptResponse | AxiosError | Error>;
getUthmaniSimpleScriptOfAyah: (query?: QuranQuery) => Promise<UthmaniSimpleScriptResponse | AxiosError | Error>;
getImlaeiSimpleTextOfAyah: (query?: QuranQuery) => Promise<ImlaeiSimpleTextResponse | AxiosError | Error>;
getASingleTranslation: (translation_id: string, query?: TranslationQuery) => Promise<SingleTranslationResponse | AxiosError | Error>;
getSingleTafsir: (tafsir_id: string, query?: TranslationQuery) => Promise<SingleTafsirResponse | AxiosError | Error>;
getGlyphCodesOfAyahV1: (query?: QuranQuery) => Promise<GlyphCodesOfAyahV1Response | AxiosError | Error>;
getGlyphCodesOfAyahV2: (query?: QuranQuery) => Promise<GlyphCodesOfAyahV2Response | AxiosError | Error>;
};

0 comments on commit 6d94c15

Please sign in to comment.