twitter-lite
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -0,1 +1,5 @@ | ||
# v0.9.1, 2019-Jan-16 | ||
- Fix encoding of special characters in direct messages ([#38](https://github.com/draftbit/twitter-lite/issues/38)) | ||
# v0.9, 2019-Jan-06 | ||
@@ -2,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var s=this._makeRequest("POST",e,u.includes(e)?null:t),o=s.requestData,i=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(t),i["Content-Type"]="application/x-www-form-urlencoded"),r(o.url,{method:"POST",headers:i,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h; | ||
var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var s=this._makeRequest("POST",e,u.includes(e)?null:t),o=s.requestData,i=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=c(n.stringify(t)),i["Content-Type"]="application/x-www-form-urlencoded"),r(o.url,{method:"POST",headers:i,body:t}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h; | ||
//# sourceMappingURL=twitter.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var s=this._makeRequest("POST",e,u.includes(e)?null:t),o=s.requestData,i=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(t),i["Content-Type"]="application/x-www-form-urlencoded"),r(o.url,{method:"POST",headers:i,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h; | ||
var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var s=this._makeRequest("POST",e,u.includes(e)?null:t),o=s.requestData,i=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=c(n.stringify(t)),i["Content-Type"]="application/x-www-form-urlencoded"),r(o.url,{method:"POST",headers:i,body:t}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h; | ||
//# sourceMappingURL=twitter.m.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),o=require("./stream"),s=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,o=Object.assign({},i,r);this.authType=o.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:o.consumer_key,secret:o.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:o.access_token_key,secret:o.access_token_secret},this.url=s(o.subdomain),this.oauth=s(o.subdomain,"oauth"),this.config=o};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return o(e)}},o)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{key:e.key,secret:e.secret})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return o(e)}},o)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var o={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?o.data=r:o.url+="?"+n.stringify(r));return{requestData:o,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var o=this._makeRequest("POST",e,u.includes(e)?null:t),s=o.requestData,i=Object.assign({},a,o.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(t),i["Content-Type"]="application/x-www-form-urlencoded"),r(s.url,{method:"POST",headers:i,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new o,a={url:s("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),o=require("./stream"),s=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,o=Object.assign({},i,r);this.authType=o.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:o.consumer_key,secret:o.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:o.access_token_key,secret:o.access_token_secret},this.url=s(o.subdomain),this.oauth=s(o.subdomain,"oauth"),this.config=o};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return o(e)}},o)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{key:e.key,secret:e.secret})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return o(e)}},o)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var o={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?o.data=r:o.url+="?"+n.stringify(r));return{requestData:o,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var o=this._makeRequest("POST",e,u.includes(e)?null:t),s=o.requestData,i=Object.assign({},a,o.headers);return u.includes(e)?t=JSON.stringify(t):(t=c(n.stringify(t)),i["Content-Type"]="application/x-www-form-urlencoded"),r(s.url,{method:"POST",headers:i,body:t}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new o,a={url:s("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h}); | ||
//# sourceMappingURL=twitter.umd.js.map |
{ | ||
"name": "twitter-lite", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "A tiny, full-featured client / server library for the Twitter API", | ||
@@ -47,3 +47,2 @@ "source": [ | ||
"test": "jest", | ||
"echover": "echo $npm_package_version", | ||
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish", | ||
@@ -50,0 +49,0 @@ "precommit": "lint-staged" |
@@ -246,2 +246,6 @@ # Twitter Lite | ||
## Examples | ||
You can find many more examples for various resources/endpoints in [the tests](test). | ||
## Troubleshooting | ||
@@ -248,0 +252,0 @@ |
@@ -240,3 +240,3 @@ const crypto = require("crypto"); | ||
} else { | ||
body = querystring.stringify(body); | ||
body = percentEncode(querystring.stringify(body)); | ||
postHeaders["Content-Type"] = "application/x-www-form-urlencoded"; | ||
@@ -248,3 +248,3 @@ } | ||
headers: postHeaders, | ||
body: percentEncode(body) | ||
body | ||
}) | ||
@@ -251,0 +251,0 @@ .then(Twitter._handleResponse) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84854
320