react-hadiths
Version:
A Simple SDK to use the Hadiths API effectively and efficiently
2 lines (1 loc) • 1.22 kB
JavaScript
import t from"isomorphic-unfetch";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},e.apply(this,arguments)}class r{constructor(t){this.apiKey=void 0,this.baseUrl=void 0,this.apiKey=t.apiKey,this.baseUrl=t.baseUrl||"https://hadiths-api.p.rapidapi.com"}invoke(r,i){const s=`${this.baseUrl}${r}`,a=e({},i,{headers:{"Content-Type":"application/json","X-RapidAPI-Host":"hadiths-api.p.rapidapi.com","X-RapidAPI-Key":this.apiKey}});return t(s,a).then(t=>{if(t.ok)return t.json();throw new Error(t.statusText)})}}class i extends r{}var s;s=i,[class extends r{getHadithById(t){return this.invoke(`/hadiths/${t}`)}getAllHadiths(){return this.invoke("/hadiths")}getHadithsByCollection(t){return this.invoke(`/hadiths?collection=${t}`)}getHadithsByCategory(t,e){return this.invoke(`/hadiths?collection=${t}&category=${e}`)}searchHadiths(t){return this.invoke(`/hadiths?search=${t}`)}}].forEach(t=>{Object.getOwnPropertyNames(t.prototype).forEach(e=>{Object.defineProperty(s.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})});export{i as default};