Comparing version 0.10.0 to 0.10.1
319
backbeam.js
@@ -72,3 +72,3 @@ (function(undefined) { | ||
var query = params ? serialize(params) : '' | ||
if (method === 'GET') { | ||
if (method === 'GET' || method === 'DELETE') { | ||
url += '?'+query | ||
@@ -122,3 +122,3 @@ } | ||
var opts = { url:url, method:method, headers:headers } | ||
if (method === 'GET') { | ||
if (method === 'GET' || method === 'DELETE') { | ||
opts.qs = params | ||
@@ -389,2 +389,4 @@ } else { | ||
if (data.status === 'InvalidAuthCode') { backbeam.logout() } | ||
callback(null, data, false) | ||
@@ -401,2 +403,5 @@ }) | ||
} | ||
if (typeof obj === 'boolean') { | ||
return obj ? '1' : '0' | ||
} | ||
if (obj && obj.id && typeof obj.id === 'function' && obj.entity && typeof obj.entity === 'function') { | ||
@@ -412,6 +417,8 @@ if (addEntity) { | ||
} | ||
if (obj.constructor.name === 'Array' || obj.constructor.name === 'Object') { | ||
return JSON.stringify(obj) | ||
} | ||
if (obj && typeof obj.toString === 'function') { | ||
return obj.toString() | ||
} | ||
// TODO: location | ||
return null | ||
@@ -518,2 +525,8 @@ } | ||
o[key+'#t'] = value | ||
} else if (typeof value === 'boolean') { | ||
o[key+'#b'] = value | ||
} else if (value.constructor.name === 'Location') { | ||
o[key+'#l'] = value.toString() | ||
} else if (value.constructor.name === 'Day') { | ||
o[key+'#c'] = value.toString() | ||
} | ||
@@ -628,3 +641,2 @@ } | ||
var type = field.substring(i+1, field.length) | ||
// TODO: check types | ||
if (type === 'r') { | ||
@@ -651,5 +663,10 @@ if (value.constructor == Object) { | ||
} else if (type === 'd') { | ||
value = new Date(parseInt(value, 10) || 0) | ||
value = new Date(+value || 0) | ||
} else if (type === 'n') { | ||
value = parseFloat(value) || 0 | ||
value = +value || 0 | ||
} else if (type === 'l') { | ||
value = new backbeam.Location(value.addr, value.lat, value.lon) | ||
} else if (type === 'c') { | ||
var comps = value.split('-') | ||
value = new backbeam.Day(+comps[0], +comps[1], +comps[2]) | ||
} | ||
@@ -678,5 +695,9 @@ | ||
obj.getFacebookData = function(key) { | ||
return obj.getLoginData('facebook', key) | ||
return obj.getLoginData('fb', key) | ||
} | ||
obj.getGooglePlusData = function(key) { | ||
return obj.getLoginData('gp', key) | ||
} | ||
return obj | ||
@@ -703,106 +724,152 @@ } | ||
var q, params | ||
return { | ||
policy: function(value) { | ||
policy = value | ||
return this | ||
}, | ||
query: function() { | ||
var args = Array.prototype.slice.call(arguments) | ||
q = args[0] | ||
var prms = null | ||
if (args[1] && args[1].constructor == Array) { prms = args[1] } | ||
else { prms = args.slice(1, args.length) } | ||
if (prms) { | ||
params = prms | ||
for (var i = 0; i < params.length; i++) { | ||
params[i] = stringFromObject(params[i], true) // TODO: if returns null? | ||
} | ||
var query = {} | ||
query.policy = function(value) { | ||
policy = value | ||
return this | ||
} | ||
query.query = function() { | ||
var args = Array.prototype.slice.call(arguments) | ||
q = args[0] | ||
var prms = null | ||
if (args[1] && args[1].constructor == Array) { prms = args[1] } | ||
else { prms = args.slice(1, args.length) } | ||
if (prms) { | ||
params = prms | ||
for (var i = 0; i < params.length; i++) { | ||
params[i] = stringFromObject(params[i], true) // TODO: if returns null? | ||
} | ||
return this | ||
}, | ||
fetch: function() { | ||
var args = guments(arguments, true) | ||
var limit = args.nextNumber('limit') | ||
var offset = args.nextNumber('offset') | ||
var callback = args.callback() | ||
} | ||
return this | ||
} | ||
signedRequest('GET', '/data/'+entity, { q:q || '', params:params || [], limit:limit, offset:offset }, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
var objects = objectsFromValues(data.objects, null) | ||
var objs = [] | ||
for (var i = 0; i < data.ids.length; i++) { | ||
objs.push(objects[data.ids[i]]) | ||
} | ||
callback(null, objs, data.count, fromCache) | ||
}) | ||
return this | ||
}, | ||
near: function() { | ||
var args = guments(arguments, true) | ||
var field = args.nextString('field') | ||
var lat = args.nextNumber('lat') | ||
var lon = args.nextNumber('lon') | ||
var limit = args.nextNumber('limit') | ||
var callback = args.callback() | ||
query.fetch = function() { | ||
var args = guments(arguments, true) | ||
var limit = args.nextNumber('limit') | ||
var offset = args.nextNumber('offset') | ||
var callback = args.callback() | ||
var _params = { | ||
q : q || '', | ||
params : params || [], | ||
limit : limit, | ||
lat : lat, | ||
lon : lon, | ||
signedRequest('GET', '/data/'+entity, { q:q || '', params:params || [], limit:limit, offset:offset }, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
var objects = objectsFromValues(data.objects, null) | ||
var objs = [] | ||
for (var i = 0; i < data.ids.length; i++) { | ||
objs.push(objects[data.ids[i]]) | ||
} | ||
callback(null, objs, data.count, fromCache) | ||
}) | ||
return this | ||
} | ||
signedRequest('GET', '/data/'+entity+'/near/'+field, _params, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
var objects = objectsFromValues(data.objects, null) | ||
var objs = [] | ||
for (var i = 0; i < data.ids.length; i++) { | ||
objs.push(objects[data.ids[i]]) | ||
} | ||
callback(null, objs, data.distances, fromCache) | ||
}) | ||
return this | ||
}, | ||
bounding: function() { | ||
var args = guments(arguments, true) | ||
var field = args.nextString('field') | ||
var swlat = args.nextNumber('swlat') | ||
var swlon = args.nextNumber('swlon') | ||
var nelat = args.nextNumber('nelat') | ||
var nelon = args.nextNumber('nelon') | ||
var limit = args.nextNumber('limit') | ||
var callback = args.callback() | ||
query.near = function() { | ||
var args = guments(arguments, true) | ||
var field = args.nextString('field') | ||
var lat = args.nextNumber('lat') | ||
var lon = args.nextNumber('lon') | ||
var limit = args.nextNumber('limit') | ||
var callback = args.callback() | ||
var _params = { | ||
q : q || '', | ||
params : params || [], | ||
limit : limit, | ||
swlat : swlat, | ||
nelat : nelat, | ||
swlon : swlon, | ||
nelon : nelon | ||
var _params = { | ||
q : q || '', | ||
params : params || [], | ||
limit : limit, | ||
lat : lat, | ||
lon : lon, | ||
} | ||
signedRequest('GET', '/data/'+entity+'/near/'+field, _params, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
var objects = objectsFromValues(data.objects, null) | ||
var objs = [] | ||
for (var i = 0; i < data.ids.length; i++) { | ||
objs.push(objects[data.ids[i]]) | ||
} | ||
callback(null, objs, data.distances, fromCache) | ||
}) | ||
return this | ||
} | ||
signedRequest('GET', '/data/'+entity+'/bounding/'+field, _params, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
var objects = objectsFromValues(data.objects, null) | ||
var objs = [] | ||
for (var i = 0; i < data.ids.length; i++) { | ||
objs.push(objects[data.ids[i]]) | ||
} | ||
callback(null, objs, fromCache) | ||
}) | ||
return this | ||
query.bounding = function() { | ||
var args = guments(arguments, true) | ||
var field = args.nextString('field') | ||
var swlat = args.nextNumber('swlat') | ||
var swlon = args.nextNumber('swlon') | ||
var nelat = args.nextNumber('nelat') | ||
var nelon = args.nextNumber('nelon') | ||
var limit = args.nextNumber('limit') | ||
var callback = args.callback() | ||
var _params = { | ||
q : q || '', | ||
params : params || [], | ||
limit : limit, | ||
swlat : swlat, | ||
nelat : nelat, | ||
swlon : swlon, | ||
nelon : nelon | ||
} | ||
signedRequest('GET', '/data/'+entity+'/bounding/'+field, _params, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
var objects = objectsFromValues(data.objects, null) | ||
var objs = [] | ||
for (var i = 0; i < data.ids.length; i++) { | ||
objs.push(objects[data.ids[i]]) | ||
} | ||
callback(null, objs, fromCache) | ||
}) | ||
return this | ||
} | ||
query._remove = function(_params, callback) { | ||
signedRequest('DELETE', '/data/'+entity, _params, policy, function(error, data, fromCache) { | ||
if (error) { return callback(error) } | ||
var status = data.status | ||
if (!status) { return callback(new BackbeamError('InvalidResponse')) } | ||
if (status !== 'Success') { return callback(new BackbeamError(status, data.errorMessage)) } | ||
callback(null, data.removed) | ||
}) | ||
} | ||
query.remove = function() { | ||
var args = guments(arguments, true) | ||
var limit = args.nextNumber('limit') | ||
var offset = args.nextNumber('offset') | ||
var _callback = args.callback() | ||
var _params = { | ||
q : q || '', | ||
params : params || [], | ||
limit : limit, | ||
offset : offset, | ||
} | ||
query._remove(_params, _callback) | ||
return this | ||
} | ||
query.removeAll = function() { | ||
var args = guments(arguments, true) | ||
var _callback = args.callback() | ||
var _params = { | ||
q : q || '', | ||
params : params || [], | ||
limit : 'all', | ||
offset : 0 | ||
} | ||
query._remove(_params, _callback) | ||
return this | ||
} | ||
return query | ||
} | ||
@@ -940,2 +1007,37 @@ | ||
backbeam.Location = function Location(addr, lat, lon, alt) { | ||
this.addr = addr | ||
this.lat = lat | ||
this.lon = lon | ||
this.alt = alt | ||
this.toString = function() { | ||
return (+this.lat||0)+','+(+this.lon||0)+','+(+this.alt||0)+'|'+(this.addr||'') | ||
} | ||
} | ||
function zeroFill(str, n) { return (new Array(n + 1 - str.length)).join('0') + str } | ||
backbeam.Day = function Day(year, month, day) { | ||
if (!year) year = new Date() | ||
if (year && year.constructor.name === 'Date') { | ||
this.year = year.getFullYear() | ||
this.month = year.getMonth() + 1 | ||
this.day = year.getDate() | ||
} else { | ||
this.year = year | ||
this.month = month | ||
this.day = day | ||
} | ||
this.toDate = function() { | ||
return new Date(this.year, this.month-1, this.day) | ||
} | ||
this.toString = function() { | ||
return [zeroFill(this.year+'', 4), zeroFill(this.month+'', 2), zeroFill(this.day+'', 2)].join('-') | ||
} | ||
} | ||
backbeam.clearCache = function() { | ||
@@ -960,2 +1062,6 @@ cache && cache.clear() | ||
backbeam.unsubscribeFromAllRealTimeConnectionEvents = function() { | ||
realtimeDelegates = [] | ||
} | ||
backbeam.subscribeToRealTimeEvents = function(event, delegate) { | ||
@@ -984,2 +1090,9 @@ var room = roomName(event) | ||
backbeam.unsubscribeFromAllRealTimeEvents = function() { | ||
roomDelegates = {} | ||
if (!socket) return false; | ||
socket.emit('unsubscribe-all', {}) | ||
return true | ||
} | ||
backbeam.sendRealTimeEvent = function(event, _data) { | ||
@@ -1357,2 +1470,6 @@ if (!socket) return false | ||
}, | ||
addGooglePlus: function() { | ||
addWithPrefix(arguments, 'gp:') | ||
return this | ||
}, | ||
addEmail: function() { | ||
@@ -1359,0 +1476,0 @@ addWithPrefix(arguments, 'email:') |
{ | ||
"name": "backbeam", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "Javascript library for backbeam.io. For both nodejs and the browser", | ||
@@ -5,0 +5,0 @@ "main": "backbeam.js", |
@@ -92,3 +92,3 @@ if (typeof backbeam === 'undefined') { | ||
chai.assert.isNull(error) | ||
chai.assert.equal(fromCache, true) | ||
chai.assert.equal(fromCache, backbeam.sdk ? false : true) | ||
chai.assert.equal(objects.length, 1) | ||
@@ -95,0 +95,0 @@ chai.assert.equal(objects[0].entity(), 'place') |
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
278630
9314