dev-to-js
Version:
An universal client for the Dev.to API written in Typescript
3 lines (2 loc) • 4.87 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("querystringify"),require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["querystringify","isomorphic-unfetch"],e):(t||self).devToJs=e(t.querystringify,t.isomorphicUnfetch)}(this,function(t,e){function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(t),i=r(e);function s(){return(s=Object.assign||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}).apply(this,arguments)}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var f,c=function(){function t(t){this.apiKey=t.apiKey,this.basePath=t.basePath||"https://dev.to/api/"}return t.prototype.request=function(t,e){var r=this.basePath+t,n=s({},e,{headers:{"api-key":this.apiKey,"Content-type":"application/json"}});return i.default(r,n).then(function(t){if(t.ok)return t.json();throw new Error(t.statusText)})},t}(),a=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var r=e.prototype;return r.getArticles=function(t){var e="articles";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},r.getArticle=function(t){return this.request("articles/"+t)},r.getArticleByPath=function(t,e){return this.request("articles/"+t+"/"+e)},r.getMyArticles=function(t){var e="articles/me";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},r.getMyPublishedArticles=function(t){var e="articles/me/published";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},r.getMyUnpublishedArticles=function(t){var e="articles/me/unpublished";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},r.getMyAllArticles=function(t){var e="articles/me/all";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},r.createArticle=function(t){return this.request("articles",{method:"POST",body:JSON.stringify({article:t})})},r.updateArticle=function(t,e){return this.request("articles/"+t,{method:"PUT",body:JSON.stringify({article:e})})},e}(c),h=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var r=e.prototype;return r.getComment=function(t){return this.request("comments/"+t)},r.getComments=function(t){return this.request("comments?a_id="+t)},e}(c),p=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var r=e.prototype;return r.getCurrentUser=function(){return this.request("users/me")},r.getUser=function(t){return this.request("users/"+t)},r.getUserByUsername=function(t){return this.request("users/by_username?url="+t)},e}(c),y=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.getFollowers=function(t){var e="followers/users";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},e}(c),l="listings",g=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var r=e.prototype;return r.getListings=function(t){var e=l;return t&&(e+=n.default.stringify(t,"?")),this.request(e)},r.getListingsByCategory=function(t,e){var r="listings/category/"+t;return e&&(r+=n.default.stringify(e,"?")),this.request(r)},r.getListing=function(t){return this.request("listings/"+t)},r.createListing=function(t){return this.request(l,{method:"POST",body:JSON.stringify({classified_listing:t})})},r.updateListing=function(t,e){return this.request("listings/"+t,{method:"PUT",body:JSON.stringify({classified_listing:e})})},e}(c),d=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.getPodcastEpisodes=function(t){var e="podcast_episodes";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},e}(c),q=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.getTags=function(t){var e="tags";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},e}(c),b=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.getVideos=function(t){var e="videos";return t&&(e+=n.default.stringify(t,"?")),this.request(e)},e}(c),m="webhooks",v=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var r=e.prototype;return r.getWebhooks=function(){return this.request(m)},r.getWebhook=function(t){return this.request("webhooks/"+t)},r.createWebhook=function(t){return this.request(m,{method:"POST",body:JSON.stringify({webhook_endpoint:t})})},r.deleteWebhook=function(t){return this.request("webhooks/"+t,{method:"DELETE"})},e}(c),O=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(c);return f=O,[a,h,p,y,g,d,q,b,v].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(f.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e))})}),O});
//# sourceMappingURL=index.umd.js.map