radar-sdk-js
Advanced tools
Comparing version 1.0.0-beta2 to 1.0.0-beta3
@@ -6,3 +6,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "1.0.0-beta2", | ||
"version": "1.0.0-beta3", | ||
"main": "radar.js", | ||
@@ -9,0 +9,0 @@ "scripts": { |
10
radar.js
@@ -1,2 +0,2 @@ | ||
var SDK_VERSION = '1.0.0-beta2'; | ||
var SDK_VERSION = '1.0.0-beta3'; | ||
var HOST_COOKIE = 'radar-host'; | ||
@@ -186,5 +186,9 @@ var DEVICE_ID_COOKIE = 'radar-deviceId'; | ||
res = JSON.parse(res); | ||
callback(this.STATUS.SUCCESS, position.coords, res.user, res.events); | ||
if (callback) { | ||
callback(this.STATUS.SUCCESS, position.coords, res.user, res.events); | ||
} | ||
} catch (err) { | ||
callback(this.STATUS.ERROR_SERVER); | ||
if (callback) { | ||
callback(this.STATUS.ERROR_SERVER); | ||
} | ||
} | ||
@@ -191,0 +195,0 @@ }.bind(this), function(err) { |
@@ -1,1 +0,1 @@ | ||
!function(e){var t={};function i(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=t,i.d=function(e,t,o){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},i.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){var o={_getCookie:function(e){if(!document||!document.cookie)return null;for(var t=e+"=",i=document.cookie.split(";"),o=0;o<i.length;o++){var r=i[o];if(-1!=r.indexOf(t))return r.substring(t.length+1)}return null},_setCookie:function(e,t){if(document&&document.cookie&&"string"==typeof t){var i=new Date;i.setFullYear(i.getFullYear()+10),expires="expires="+i.toGMTString(),document.cookie=e+"="+t+";path=/;"+expires}},_deleteCookie:function(e){document&&document.cookie&&(document.cookie=e+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/")},_request:function(e,t,i,o,r,n){var s=new XMLHttpRequest;for(var R in s.open(e,t,!0),s.setRequestHeader("Content-Type","application/json"),o)s.setRequestHeader(R,o[R]);s.onload=function(){200==s.status?r(s.response):401==s.status?n(this.STATUS.ERROR_UNAUTHORIZED):429==s.status?n(this.STATUS.ERROR_RATE_LIMIT):n(this.STATUS.ERROR_SERVER)}.bind(this),s.onerror=function(){n(this.STATUS.ERROR_SERVER)}.bind(this),s.timeout=function(){n(this.STATUS.ERROR_NETWORK)}.bind(this),s.send(JSON.stringify(i))},_getDeviceId:function(){var e=this._getCookie("radar-deviceId");if(e)return e;var t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)});return this._setCookie("radar-deviceId",t,!0),t},_setHost:function(e){this._setCookie("radar-host",e,!0)},STATUS:{SUCCESS:"SUCCESS",ERROR_PUBLISHABLE_KEY:"ERROR_PUBLISHABLE_KEY",ERROR_PERMISSIONS:"ERROR_PERMISSIONS",ERROR_LOCATION:"ERROR_LOCATION",ERROR_NETWORK:"ERROR_NETWORK",ERROR_UNAUTHORIZED:"ERROR_UNAUTHORIZED",ERROR_RATE_LIMIT:"ERROR_RATE_LIMIT",ERROR_SERVER:"ERROR_SERVER"},PLACES_PROVIDER:{FACEBOOK:"facebook",NONE:"none"},initialize:function(e){this._setCookie("radar-publishableKey",e)},setPlacesProvider:function(e){e!==this.PLACES_PROVIDER.FACEBOOK&&(e=this.PLACES_PROVIDER.NONE),this._setCookie("radar-placesProvider",e)},setUserId:function(e){e?("string"!=typeof e&&(e=String(e)),0===(e=e.trim()).length||e.length>256?this._deleteCookie("radar-userId"):this._setCookie("radar-userId",e)):this._deleteCookie("radar-userId")},setDescription:function(e){e?("string"!=typeof e&&(e=String(e)),0===(e=e.trim()).length||e.length>256?this._deleteCookie("radar-description"):this._setCookie("radar-description",e)):this._deleteCookie("radar-description")},trackOnce:function(e){var t=this._getCookie("radar-publishableKey");t?navigator&&navigator.geolocation?navigator.geolocation.getCurrentPosition(function(i){if(i&&i.coords){var o=this._getDeviceId(),r=this._getCookie("radar-placesProvider"),n=this._getCookie("radar-userId"),s=this._getCookie("radar-description"),R=n||o,a=(this._getCookie("radar-host")||"https://api.radar.io")+"/v1/users/"+R,d={longitude:i.coords.longitude,latitude:i.coords.latitude,accuracy:i.coords.accuracy,foreground:!0,stopped:!0,deviceId:o,userId:n,description:s,deviceType:"Web",userAgent:navigator.userAgent,placesProvider:r,sdkVersion:"1.0.0-beta2"},u={Authorization:t};this._request("PUT",a,d,u,function(t){try{t=JSON.parse(t),e(this.STATUS.SUCCESS,i.coords,t.user,t.events)}catch(t){e(this.STATUS.ERROR_SERVER)}}.bind(this),function(t){e&&e(t)})}else e&&e(this.STATUS.ERROR_LOCATION)}.bind(this),function(t){e&&t&&t.code&&(1===t.code?e(this.STATUS.ERROR_PERMISSIONS):e(this.STATUS.ERROR_LOCATION))}.bind(this)):e&&e(this.STATUS.ERROR_LOCATION):e&&e(this.STATUS.ERROR_PUBLISHABLE_KEY)}};window.Radar=o,e.exports=o}]); | ||
!function(e){var t={};function i(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=t,i.d=function(e,t,o){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},i.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){var o={_getCookie:function(e){if(!document||!document.cookie)return null;for(var t=e+"=",i=document.cookie.split(";"),o=0;o<i.length;o++){var r=i[o];if(-1!=r.indexOf(t))return r.substring(t.length+1)}return null},_setCookie:function(e,t){if(document&&document.cookie&&"string"==typeof t){var i=new Date;i.setFullYear(i.getFullYear()+10),expires="expires="+i.toGMTString(),document.cookie=e+"="+t+";path=/;"+expires}},_deleteCookie:function(e){document&&document.cookie&&(document.cookie=e+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/")},_request:function(e,t,i,o,r,n){var s=new XMLHttpRequest;for(var R in s.open(e,t,!0),s.setRequestHeader("Content-Type","application/json"),o)s.setRequestHeader(R,o[R]);s.onload=function(){200==s.status?r(s.response):401==s.status?n(this.STATUS.ERROR_UNAUTHORIZED):429==s.status?n(this.STATUS.ERROR_RATE_LIMIT):n(this.STATUS.ERROR_SERVER)}.bind(this),s.onerror=function(){n(this.STATUS.ERROR_SERVER)}.bind(this),s.timeout=function(){n(this.STATUS.ERROR_NETWORK)}.bind(this),s.send(JSON.stringify(i))},_getDeviceId:function(){var e=this._getCookie("radar-deviceId");if(e)return e;var t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)});return this._setCookie("radar-deviceId",t,!0),t},_setHost:function(e){this._setCookie("radar-host",e,!0)},STATUS:{SUCCESS:"SUCCESS",ERROR_PUBLISHABLE_KEY:"ERROR_PUBLISHABLE_KEY",ERROR_PERMISSIONS:"ERROR_PERMISSIONS",ERROR_LOCATION:"ERROR_LOCATION",ERROR_NETWORK:"ERROR_NETWORK",ERROR_UNAUTHORIZED:"ERROR_UNAUTHORIZED",ERROR_RATE_LIMIT:"ERROR_RATE_LIMIT",ERROR_SERVER:"ERROR_SERVER"},PLACES_PROVIDER:{FACEBOOK:"facebook",NONE:"none"},initialize:function(e){this._setCookie("radar-publishableKey",e)},setPlacesProvider:function(e){e!==this.PLACES_PROVIDER.FACEBOOK&&(e=this.PLACES_PROVIDER.NONE),this._setCookie("radar-placesProvider",e)},setUserId:function(e){e?("string"!=typeof e&&(e=String(e)),0===(e=e.trim()).length||e.length>256?this._deleteCookie("radar-userId"):this._setCookie("radar-userId",e)):this._deleteCookie("radar-userId")},setDescription:function(e){e?("string"!=typeof e&&(e=String(e)),0===(e=e.trim()).length||e.length>256?this._deleteCookie("radar-description"):this._setCookie("radar-description",e)):this._deleteCookie("radar-description")},trackOnce:function(e){var t=this._getCookie("radar-publishableKey");t?navigator&&navigator.geolocation?navigator.geolocation.getCurrentPosition(function(i){if(i&&i.coords){var o=this._getDeviceId(),r=this._getCookie("radar-placesProvider"),n=this._getCookie("radar-userId"),s=this._getCookie("radar-description"),R=n||o,a=(this._getCookie("radar-host")||"https://api.radar.io")+"/v1/users/"+R,d={longitude:i.coords.longitude,latitude:i.coords.latitude,accuracy:i.coords.accuracy,foreground:!0,stopped:!0,deviceId:o,userId:n,description:s,deviceType:"Web",userAgent:navigator.userAgent,placesProvider:r,sdkVersion:"1.0.0-beta3"},u={Authorization:t};this._request("PUT",a,d,u,function(t){try{t=JSON.parse(t),e&&e(this.STATUS.SUCCESS,i.coords,t.user,t.events)}catch(t){e&&e(this.STATUS.ERROR_SERVER)}}.bind(this),function(t){e&&e(t)})}else e&&e(this.STATUS.ERROR_LOCATION)}.bind(this),function(t){e&&t&&t.code&&(1===t.code?e(this.STATUS.ERROR_PERMISSIONS):e(this.STATUS.ERROR_LOCATION))}.bind(this)):e&&e(this.STATUS.ERROR_LOCATION):e&&e(this.STATUS.ERROR_PUBLISHABLE_KEY)}};window.Radar=o,e.exports=o}]); |
32442
230