UNPKG

react-hadiths

Version:

A Simple SDK to use the Hadiths API effectively and efficiently

2 lines (1 loc) 1.82 kB
function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=/*#__PURE__*/t(require("isomorphic-unfetch"));function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},r.apply(this,arguments)}function n(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 i,a=/*#__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,n){var o=""+this.baseUrl+t,i=r({},n,{headers:{"Content-Type":"application/json","X-RapidAPI-Host":"hadiths-api.p.rapidapi.com","X-RapidAPI-Key":this.apiKey}});return e.default(o,i).then(function(t){if(t.ok)return t.json();throw new Error(t.statusText)})},t}(),c=/*#__PURE__*/function(t){function e(){return t.apply(this,arguments)||this}n(e,t);var r=e.prototype;return r.getHadithById=function(t){return this.invoke("/hadiths/"+t)},r.getAllHadiths=function(){return this.invoke("/hadiths")},r.getHadithsByCollection=function(t){return this.invoke("/hadiths?collection="+t)},r.getHadithsByCategory=function(t,e){return this.invoke("/hadiths?collection="+t+"&category="+e)},r.searchHadiths=function(t){return this.invoke("/hadiths?search="+t)},e}(a),p=/*#__PURE__*/function(t){function e(){return t.apply(this,arguments)||this}return n(e,t),e}(a);i=p,[c].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(i.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})}),module.exports=p;