UNPKG

@sno2/pex

Version:

An unofficial promise-based Pexels API wrapper with top-notch TypeScript support.

3 lines (2 loc) 1.54 kB
function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("axios")),r=0;function o(e){return"__private_"+r+++"_"+e}function i(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var n=o("opts"),s=o("axios");exports.Pex=class{constructor(e){Object.defineProperty(this,n,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:void 0}),i(this,n)[n]=e,i(this,s)[s]=t.default.create({baseURL:"https://api.pexels.com",headers:{Authorization:i(this,n)[n].key}})}getPhoto(e){try{return Promise.resolve(i(this,s)[s].get(`/v1/photos${e.id}`)).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}getPhotos(e){try{return Promise.resolve(i(this,s)[s].get("/v1/search",{params:e})).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}getCuratedPhotos(e){try{return Promise.resolve(i(this,s)[s].get("/v1/curated",{params:e})).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}getVideo(e){try{return Promise.resolve(i(this,s)[s].get(`/videos/${e.id}`)).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}getVideos(e){try{return Promise.resolve(i(this,s)[s].get("/videos/search",{params:e})).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}getPopularVideos(e){try{return Promise.resolve(i(this,s)[s].get("/videos/popular",{params:e})).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}}; //# sourceMappingURL=index.js.map