twitter-lite
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,2 +0,2 @@ | ||
var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t){return"https://"+t+".twitter.com/1.1"},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.config=i};c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e){return new Promise(function(n,i){var o,s;return o={url:this.url+"/"+t+".json",method:"POST"},s={},s="User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(o.url,{method:"POST",headers:Object.assign({},u,s),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return n(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c; | ||
var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t){return"https://"+t+".twitter.com/1.1"},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.config=i};c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e,i){return new Promise(function(o,s){var c,a;return c={url:this.url+"/"+t+".json",method:"POST"},i&&(c.url+="?"+n.stringify(i)),a={},a="User"===this.authType?this.client.toHeader(this.client.authorize(c,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(c.url,{method:"POST",headers:Object.assign({},u,a),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return s(t)}}.bind(this),s)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c; | ||
//# sourceMappingURL=twitter.js.map |
@@ -1,2 +0,2 @@ | ||
var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t){return"https://"+t+".twitter.com/1.1"},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.config=i};c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e){return new Promise(function(n,i){var o,s;return o={url:this.url+"/"+t+".json",method:"POST"},s={},s="User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(o.url,{method:"POST",headers:Object.assign({},u,s),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return n(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c; | ||
var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t){return"https://"+t+".twitter.com/1.1"},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.config=i};c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e,i){return new Promise(function(o,s){var c,a;return c={url:this.url+"/"+t+".json",method:"POST"},i&&(c.url+="?"+n.stringify(i)),a={},a="User"===this.authType?this.client.toHeader(this.client.authorize(c,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(c.url,{method:"POST",headers:Object.assign({},u,a),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return s(t)}}.bind(this),s)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c; | ||
//# 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"),i=require("./stream"),o=function(e){return"https://"+e+".twitter.com/1.1"},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:i.consumer_key,secret:i.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:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.config=i};c.prototype.get=function(e,t){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+e+".json",method:"GET"},t&&(s.url+="?"+n.stringify(t)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(e){return e.json()}).then(function(e){try{return i(e)}catch(e){return o(e)}}.bind(this),o)}.bind(this))},c.prototype.post=function(e,t){return new Promise(function(n,i){var o,s;return o={url:this.url+"/"+e+".json",method:"POST"},s={},s="User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(o.url,{method:"POST",headers:Object.assign({},u,s),body:JSON.stringify(t)}).then(function(e){return e.json()}).then(function(e){try{return n(e)}catch(e){return i(e)}}.bind(this),i)}.bind(this))},c.prototype.stream=function(e,t){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+e+".json",method:"GET"};t&&(c.url+="?"+n.stringify(t));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(e){s.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=c}); | ||
!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"),i=require("./stream"),o=function(e){return"https://"+e+".twitter.com/1.1"},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:i.consumer_key,secret:i.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:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.config=i};c.prototype.get=function(e,t){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+e+".json",method:"GET"},t&&(s.url+="?"+n.stringify(t)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(e){return e.json()}).then(function(e){try{return i(e)}catch(e){return o(e)}}.bind(this),o)}.bind(this))},c.prototype.post=function(e,t,i){return new Promise(function(o,s){var c,a;return c={url:this.url+"/"+e+".json",method:"POST"},i&&(c.url+="?"+n.stringify(i)),a={},a="User"===this.authType?this.client.toHeader(this.client.authorize(c,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(c.url,{method:"POST",headers:Object.assign({},u,a),body:JSON.stringify(t)}).then(function(e){return e.json()}).then(function(e){try{return o(e)}catch(e){return s(e)}}.bind(this),s)}.bind(this))},c.prototype.stream=function(e,t){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+e+".json",method:"GET"};t&&(c.url+="?"+n.stringify(t));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(e){s.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=c}); | ||
//# sourceMappingURL=twitter.umd.js.map |
{ | ||
"name": "twitter-lite", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A tiny, full-featured client / server library for the Twitter API", | ||
@@ -5,0 +5,0 @@ "source": [ |
@@ -60,4 +60,3 @@ const crypto = require("crypto"); | ||
}; | ||
if (parameters) | ||
requestData.url += "?" + querystring.stringify(parameters); | ||
if (parameters) requestData.url += "?" + querystring.stringify(parameters); | ||
@@ -81,3 +80,3 @@ let headers = {}; | ||
async post(resource, body) { | ||
async post(resource, body, parameters) { | ||
const requestData = { | ||
@@ -88,2 +87,4 @@ url: `${this.url}/${resource}.json`, | ||
if (parameters) requestData.url += "?" + querystring.stringify(parameters); | ||
let headers = {}; | ||
@@ -116,6 +117,5 @@ if (this.authType === "User") { | ||
url: `${getUrl("stream")}/${resource}.json`, | ||
method: "GET", | ||
method: "GET" | ||
}; | ||
if (parameters) | ||
requestData.url += "?" + querystring.stringify(parameters); | ||
if (parameters) requestData.url += "?" + querystring.stringify(parameters); | ||
@@ -122,0 +122,0 @@ const headers = this.client.toHeader( |
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
42252
191