-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdweet.io.min.js
2 lines (2 loc) · 4.83 KB
/
dweet.io.min.js
1
2
!function(){function t(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){return"function"==typeof t}var n=!0;try{n=require}catch(o){n=!1}var io,r,i,c="last-thing.dat",u="https://dweet.io:443",a=!0,l=5e3;if(n){if(io=require("socket.io-client"),r=require("request"),require("fs").existsSync(c))try{i=require("fs").readFileSync(c).toString()}catch(o){}}else r=function(t,e){var n=t.url+(t.url.indexOf("?")+1?"&":"?"),o=[],r="";for(r in t.json)o.push(r+"="+encodeURIComponent(t.json[r]));for(var i="callback",c=0;window.dweetCallback[i+c];)c++;i+=c,window.dweetCallback[i]=function(t){e(null,t,t)},o.push("callback=dweetCallback."+i),o.push("_="+Date.now()),n+=o.join("&"),dweet_script_loader(n,function(t){t.parentNode.removeChild(t),window.dweetCallback[i]=void 0,delete window.dweetCallback[i]})},window.dweetCallback={},function(){var t=/ded|co/,e="onload",n="onreadystatechange",o="readyState",r=function(r,i){var c=document.createElement("script");c[e]=c[n]=function(){(!this[o]||t.test(this[o]))&&(c[e]=c[n]=null,i&&i(c),c=null)},c.async=!0,c.src=r,document.body.appendChild(c)};window.dweet_script_loader=function(t,e){if("string"==typeof t)return void r(t,e);var n=t.shift();r(n,function(n){t.length?window.dweet_script_loader(t,e):e&&e(n)})}}();var f=function(){function o(t){return t.created&&(t.created=new Date(t.created)),t}function f(t){if(t instanceof Array)for(var e=0;e<t.length;e++){var n=t[e];o(n)}else o(t);return t}function s(t){var e;try{e="string"==typeof t||t instanceof String?JSON.parse(t):t}catch(n){}return e}function d(t){var e,n=s(t);return n?"failed"==n["this"]&&(e=new Error(n.because)):e=new Error("server returned an invalid response"),e}function w(t,e){return e?t+(t.indexOf("?")+1?"&":"?")+"key="+encodeURIComponent(e):t}function h(t,e,n){var o=s(n);t||(t=d(o)),o&&o["with"]?e&&e(t,f(o["with"])):e&&e("no response from server",void 0)}var S,_=this,g={},m=i;_.set_server=function(t,e){u=t,a=e,n&&(e?require("https").globalAgent.options.rejectUnauthorized=!0:require("https").globalAgent.options.rejectUnauthorized=!1)},_.dweet=function(t,e){m?_.dweet_for(m,t,e):r({url:u+"/dweet",jar:!0,method:"POST",followAllRedirects:!0,timeout:l,strictSSL:a,json:t},function(t,o,r){var i=s(r);i["with"]&&i["with"].thing!=m&&(m=i["with"].thing,n&&require("fs").writeFile(c,m)),h(t,e,i)})},_.dweet_for=function(t,n,o,i){e(o)&&(i=o,o=null),r({url:w(u+"/dweet/for/"+t,o),jar:!0,method:"POST",followAllRedirects:!0,timeout:l,strictSSL:a,json:n},function(t,e,n){h(t,i,n)})},_.get_latest_dweet_for=function(t,n,o){e(n)&&(o=n,n=null),r({url:w(u+"/get/latest/dweet/for/"+t,n),jar:!0,timeout:l,strictSSL:a},function(t,e,n){h(t,o,n)})},_.get_all_dweets_for=function(t,n,o){e(n)&&(o=n,n=null),r({url:w(u+"/get/dweets/for/"+t,n),jar:!0,timeout:l,strictSSL:a},function(t,e,n){h(t,o,n)})},_.get_key_for=function(t,e,n){r({url:w(u+"/get/key/for/"+t+"/"+e),jar:!0,timeout:l,strictSSL:a},function(t,e,o){h(t,n,o)})},_.create_key_for=function(t,e,n){r({url:w(u+"/create/key/for/"+t+"/"+e),jar:!0,timeout:l,strictSSL:a},function(t,e,o){h(t,n,o)})},_.get_keys_for_account=function(t,e){r({url:w(u+"/get/keys/for/"+t),jar:!0,timeout:l,strictSSL:a},function(t,n,o){h(t,e,o)})},_.get_keys_for_account=function(t,e,n,o){r({url:w(u+"/get/keys/for/"+t+"?startPosition="+e+"&endPosition="+n),jar:!0,timeout:l,strictSSL:a},function(t,e,n){h(t,o,n)})},_.listen_for=function(t,o,r){function i(){S=io.connect(u+"/stream"),S.on("connect",function(){for(var t in g)S.emit("subscribe",{thing:t,key:o})}),S.on("new_dweet",function(t){if(g[t.thing]){f(t);for(var e=g[t.thing],n=0;n<e.length;n++)e[n](t)}})}e(o)&&(r=o,o=null),g[t]||(g[t]=[]),-1==g[t].indexOf(r)&&g[t].push(r),S||(n?i():dweet_script_loader([u+"/socket.io/socket.io.js"],function(){io=window.io,i()})),S&&S.emit("subscribe",{thing:t,key:o})},_.stop_listening=function(){g={},S&&(S.disconnect(),S=void 0)},_.stop_listening_for=function(t){g[t]=void 0,delete g[t],S&&S.emit("unsubscribe",{thing:t})},_.lock=function(t,e,n,o){r({url:u+"/lock/"+t+"?lock="+e+"&key="+n,jar:!0,timeout:l,strictSSL:a},function(t,e,n){t||(t=d(n)),o&&o(t)})},_.unlock=function(t,e,n){r({url:w(u+"/unlock/"+t,e),jar:!0,timeout:l,strictSSL:a},function(t,e,o){t||(t=d(o)),n&&n(t)})},_.remove_lock=function(t,e,n){r({url:u+"/remove/lock/"+t+"?key="+e,jar:!0,timeout:l,strictSSL:a},function(t,e,o){t||(t=d(o)),n&&n(t)})},_.set_alert=function(e,n,o,i,c){t(n)&&(n=n.join()),r({url:w(u+"/alert/"+encodeURIComponent(n)+"/when/"+e+"/"+encodeURIComponent(o),i),jar:!0,timeout:l,strictSSL:a},function(t,e,n){t||(t=d(n)),c&&c(t)})},_.get_alert=function(t,e,n){r({url:w(u+"/get/alert/for/"+t,e),jar:!0,timeout:l,strictSSL:a},function(t,e,o){t||(t=d(o));var r=s(o);n&&n(t,r["with"])})},_.remove_alert=function(t,e,n){r({url:u+"/remove/alert/for/"+t+"?key="+e,jar:!0,timeout:l,strictSSL:a},function(t,e,o){t||(t=d(o)),n&&n(t)})}};n?module.exports=f:window.dweetio=new f}();
//# sourceMappingURL=dweet.io.min.map