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