react-hadiths
Version:
A Simple SDK to use the Hadiths API effectively and efficiently
2 lines (1 loc) • 2.04 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["isomorphic-unfetch"],e):(t||self).reactHadiths=e(t.isomorphicUnfetch)}(this,function(t){function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=/*#__PURE__*/e(t);function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},o.apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}var a,c=/*#__PURE__*/function(){function t(t){this.apiKey=void 0,this.baseUrl=void 0,this.apiKey=t.apiKey,this.baseUrl=t.baseUrl||"https://hadiths-api.p.rapidapi.com"}return t.prototype.invoke=function(t,e){var i=""+this.baseUrl+t,r=o({},e,{headers:{"Content-Type":"application/json","X-RapidAPI-Host":"hadiths-api.p.rapidapi.com","X-RapidAPI-Key":this.apiKey}});return n.default(i,r).then(function(t){if(t.ok)return t.json();throw new Error(t.statusText)})},t}(),p=/*#__PURE__*/function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.getHadithById=function(t){return this.invoke("/hadiths/"+t)},n.getAllHadiths=function(){return this.invoke("/hadiths")},n.getHadithsByCollection=function(t){return this.invoke("/hadiths?collection="+t)},n.getHadithsByCategory=function(t,e){return this.invoke("/hadiths?collection="+t+"&category="+e)},n.searchHadiths=function(t){return this.invoke("/hadiths?search="+t)},e}(c),s=/*#__PURE__*/function(t){function e(){return t.apply(this,arguments)||this}return i(e,t),e}(c);return a=s,[p].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(a.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})}),s});