gist-wrapper
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -28,5 +28,7 @@ import { AxiosInstance } from 'axios'; | ||
'X-User-Agent': string; | ||
Accept: string; | ||
Authorization: string; | ||
} | { | ||
'X-User-Agent': string; | ||
Accept: string; | ||
Authorization?: undefined; | ||
@@ -33,0 +35,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("axios")):"function"==typeof define&&define.amd?define(["axios"],e):"object"==typeof exports?exports.GitHubGist=e(require("axios")):t.GitHubGist=e(t.axios)}(this,(function(t){return(()=>{"use strict";var e={546:function(t,e,s){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.HTTPError=void 0;const i=r(s(375));class n extends Error{constructor(t,e,s,r){super(`status: ${t}\nstatusText: ${e}\ndata: ${JSON.stringify(s,null,2)}\nconfig: ${JSON.stringify(r,null,2)}`),this.status=t,this.statusText=e,this.data=s,this.config=r}}e.HTTPError=n,e.default=class{constructor(t,e="github-gist-client-js/v0.4.0"){this.token=t,this.server="https://api.github.com",this.userAgentHeader=e,this._axios=i.default.create();const s=this._axios.request.bind(this._axios);this._axios.request=t=>{try{return s(t)}catch(t){throw t.response?new n(t.response.status,t.response.statusText,t.response.data,t.response.config):t}}}request(t){const e=t.url.startsWith("http")?t.url:this.server+t.url;return this._axios.request(Object.assign(Object.assign({},t),{url:e.toString(),headers:this._patchHeaders(t.headers)}))}get(t,e={}){return this.request(Object.assign(Object.assign({},e),{method:"get",url:t}))}delete(t,e={}){return this.request(Object.assign(Object.assign({},e),{method:"delete",url:t}))}post(t,e,s={}){return this.request(Object.assign(Object.assign({},s),{method:"post",url:t,data:e}))}put(t,e,s={}){return this.request(Object.assign(Object.assign({},s),{method:"put",url:t,data:e}))}patch(t,e,s={}){return this.request(Object.assign(Object.assign({},s),{method:"patch",url:t,data:e}))}create(t,e){return this.post("/gists",t,e)}update(t,e,s){return this.patch(`/gists/${t}`,e,s)}getOne(t,e){return this.get(`/gists/${t}`,e)}delOne(t,e){return this.delete(`/gists/${t}`,e)}_patchHeaders(t){return Object.assign(Object.assign(Object.assign({},this._authHeader()),{"X-User-Agent":this.userAgentHeader}),t)}_authHeader(){return this.token?{Authorization:`token ${this.token}`}:{}}}},375:e=>{e.exports=t}},s={};return function t(r){if(s[r])return s[r].exports;var i=s[r]={exports:{}};return e[r].call(i.exports,i,i.exports,t),i.exports}(546)})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("axios")):"function"==typeof define&&define.amd?define(["axios"],e):"object"==typeof exports?exports.GitHubGist=e(require("axios")):t.GitHubGist=e(t.axios)}(this,(function(t){return(()=>{"use strict";var e={546:function(t,e,s){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.HTTPError=void 0;const i=r(s(375));class n extends Error{constructor(t,e,s,r){super(`status: ${t}\nstatusText: ${e}\ndata: ${JSON.stringify(s,null,2)}\nconfig: ${JSON.stringify(r,null,2)}`),this.status=t,this.statusText=e,this.data=s,this.config=r}}e.HTTPError=n,e.default=class{constructor(t,e="github-gist-client-js/v0.4.1"){this.token=t,this.server="https://api.github.com",this.userAgentHeader=e,this._axios=i.default.create();const s=this._axios.request.bind(this._axios);this._axios.request=t=>{try{return s(t)}catch(t){throw t.response?new n(t.response.status,t.response.statusText,t.response.data,t.response.config):t}}}request(t){const e=t.url.startsWith("http")?t.url:this.server+t.url;return this._axios.request(Object.assign(Object.assign({},t),{url:e.toString(),headers:this._patchHeaders(t.headers)}))}get(t,e={}){return this.request(Object.assign(Object.assign({},e),{method:"get",url:t}))}delete(t,e={}){return this.request(Object.assign(Object.assign({},e),{method:"delete",url:t}))}post(t,e,s={}){return this.request(Object.assign(Object.assign({},s),{method:"post",url:t,data:e}))}put(t,e,s={}){return this.request(Object.assign(Object.assign({},s),{method:"put",url:t,data:e}))}patch(t,e,s={}){return this.request(Object.assign(Object.assign({},s),{method:"patch",url:t,data:e}))}create(t,e){return this.post("/gists",t,e)}update(t,e,s){return this.patch(`/gists/${t}`,e,s)}getOne(t,e){return this.get(`/gists/${t}`,e)}delOne(t,e){return this.delete(`/gists/${t}`,e)}_patchHeaders(t){return Object.assign(Object.assign(Object.assign({},this._authHeader()),{"X-User-Agent":this.userAgentHeader,Accept:"application/vnd.github+json"}),t)}_authHeader(){return this.token?{Authorization:`token ${this.token}`}:{}}}},375:e=>{e.exports=t}},s={};return function t(r){if(s[r])return s[r].exports;var i=s[r]={exports:{}};return e[r].call(i.exports,i,i.exports,t),i.exports}(546)})()})); | ||
//# sourceMappingURL=gist.js.map |
{ | ||
"name": "gist-wrapper", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Github gist API wrapper.", | ||
@@ -5,0 +5,0 @@ "author": "ZHAO Xudong <zxdong@gmail.com>", |
@@ -20,3 +20,3 @@ # Github Gist Client for JavaScript | ||
const gc = new RingCentralEnage( | ||
const gc = new GistWrapper( | ||
GITHUB_TOKEN, | ||
@@ -23,0 +23,0 @@ userAgentHeaderString |
@@ -103,2 +103,3 @@ // based on tyler's work: https://github.com/tylerlong/ringcentral-js-concise | ||
'X-User-Agent': this.userAgentHeader, | ||
Accept: 'application/vnd.github+json', | ||
...headers | ||
@@ -105,0 +106,0 @@ } |
Sorry, the diff of this file is not supported yet
20040
189