-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushbullet-tasker.min.js
11 lines (10 loc) · 2.58 KB
/
pushbullet-tasker.min.js
1
2
3
4
5
6
7
8
9
10
11
/**
* pushbullet-tasker.js
*
* Version: 1.0.4
* Date: 2016-07-24
*
* © 2016 Cristian Moncho Ivorra
* @license https://www.gnu.org/licenses/lgpl-3.0.txt
*/
if("undefined"==typeof tk)var tk={local:function(){},global:function(){},flashLong:(window.console||{}).log||function(){}};var PB=function(e,n){"use strict";function t(t,r){var o=u("POST",c,{"Access-Token":f.token});if(o.send(i({file_name:t,file_type:r})),f.debug&&e.flashLong(o.responseText),o.status!==h.OK)throw new n.Error("Unable to request upload URL: "+o.status);return JSON.parse(o.responseText)}function r(e){var t=u("GET",e);t.overrideMimeType("text/plain; charset=x-user-defined"),t.send();for(var r=t.responseText,o=new n.Uint8Array(r.length),i=0,a=r.length;a>i;i++)o[i]=r.charCodeAt(i);return new n.Blob([o])}function o(e,o,a){var l=t(e,o),s=u("POST",l.upload_url);if(s.send(i({file:r(a)})),s.status!==h.NO_CONTENT)throw new n.Error("Unable to upload file: "+s.status);return l.file_url}function i(e){var t=new n.FormData;for(var r in e)e.hasOwnProperty(r)&&t.append(r,e[r]);return t}function u(e,t,r){var o=new n.XMLHttpRequest;o.open(e.toUpperCase(),t,!1);for(var i in r||{})r.hasOwnProperty(i)&&o.setRequestHeader(i,r[i]);return o}function a(t,r){var o;if(t="pb_"+t,[n[t],e.local(t.toLowerCase()),e.global(t.toUpperCase()),r].some(function(e){return"undefined"!==e&&"undefined"!=typeof(o=e)}),"undefined"==typeof o)throw new n.Error('Undefined variable "'+t+'"!');return o}function l(t,r){var o=u("POST",d,{"Access-Token":f.token});if(r.type=t,o.send(i(r)),f.debug&&e.flashLong(o.responseText),o.status!==h.OK)throw new n.Error("Unable to push data: "+o.status);return o.responseText}function s(e){var t={};t.title=e.title||a("title",""),t.body=e.body||a("body","");var r=e.device_iden||a("device_iden",""),o=e.email||a("email","");if(r&&o)throw new n.Error("'device_iden' and 'email' are mutually exclusive.");return r?t.device_iden=r:o&&(t.email=o),t}var f={},p="https://api.pushbullet.com/v2/",d=p+"pushes",c=p+"upload-request",h={OK:200,NO_CONTENT:204,BAD_REQUEST:400,UNAUTHORIZED:401,NOT_FOUND:404};f.debug=a("debug",!1),f.token=a("token",null),f.pushNote=function(e){e=e||{};var n=s(e);return l("note",n)},f.pushLink=function(e){e=e||{};var n=s(e);return n.url=e.url||a("url"),l("link",n)},f.pushFile=function(e){e=e||{};var n=s(e),t=e.file_path||a("file_path");return n.file_name=e.file_name||a("file_name"),n.file_type=e.file_type||a("file_type"),n.file_url=o(n.file_name,n.file_type,t),l("file",n)};var v=a("type",null);return v&&({note:f.pushNote,link:f.pushLink,file:f.pushFile}[v]||function(){throw Error('Unknown type: "'+v+'"!')})(),f}(tk,this);