react-hadiths
Version:
A Simple SDK to use the Hadiths API effectively and efficiently
2 lines (1 loc) • 1.73 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 o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},e.apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}var n,i=/*#__PURE__*/function(){function r(t){this.apiKey=void 0,this.baseUrl=void 0,this.apiKey=t.apiKey,this.baseUrl=t.baseUrl||"https://hadiths-api.p.rapidapi.com"}return r.prototype.invoke=function(r,o){var n=""+this.baseUrl+r,i=e({},o,{headers:{"Content-Type":"application/json","X-RapidAPI-Host":"hadiths-api.p.rapidapi.com","X-RapidAPI-Key":this.apiKey}});return t(n,i).then(function(t){if(t.ok)return t.json();throw new Error(t.statusText)})},r}(),a=/*#__PURE__*/function(t){function e(){return t.apply(this,arguments)||this}r(e,t);var o=e.prototype;return o.getHadithById=function(t){return this.invoke("/hadiths/"+t)},o.getAllHadiths=function(){return this.invoke("/hadiths")},o.getHadithsByCollection=function(t){return this.invoke("/hadiths?collection="+t)},o.getHadithsByCategory=function(t,e){return this.invoke("/hadiths?collection="+t+"&category="+e)},o.searchHadiths=function(t){return this.invoke("/hadiths?search="+t)},e}(i),p=/*#__PURE__*/function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e}(i);n=p,[a].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(n.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})});export{p as default};