Skip to content

Commit

Permalink
Merge pull request #227 from rAbdelHadi/master
Browse files Browse the repository at this point in the history
Add DeepLink functionality
  • Loading branch information
DanielHindi committed Jun 1, 2016
2 parents 65dcd90 + caa47dd commit 0ddf834
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 51 deletions.
68 changes: 37 additions & 31 deletions scripts/buildfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ var buildfire = {
,userData: {
/// ref:
get: function (tag, callback) {

var tagType = typeof (tag);
if (tagType == "undefined")
tag = '';
Expand All @@ -911,13 +911,13 @@ var buildfire = {
},
/// ref:
getById: function (id, tag, callback) {

var idType = typeof (id);
if (idType == "function" && typeof (callback) == "undefined") {
callback = id;
id = '';
}

var tagType = typeof (tag);
if (tagType == "undefined")
tag = '';
Expand All @@ -932,7 +932,7 @@ var buildfire = {
}
/// ref:
, save: function (obj, tag,userToken, callback) {

var tagType = typeof (tag);
if (tagType == "undefined")
tag = '';
Expand All @@ -947,16 +947,16 @@ var buildfire = {
callback = userToken;
userToken = '';
}

var p = new Packet(null, 'userData.save', { tag: tag,userToken: userToken, obj: obj });
buildfire._sendPacket(p, function (err, result) {

if (callback) callback(err, result);
});
}
/// ref:
, insert: function (obj, tag, userToken, checkDuplicate, callback) {

var userTokenType = typeof (userToken);
if (userTokenType == "undefined")
userToken = '';
Expand Down Expand Up @@ -986,18 +986,18 @@ var buildfire = {
callback = tag;
tag = '';
}

var p = new Packet(null, 'userData.insert', { tag: tag, userToken: userToken, obj: obj, checkDuplicate: checkDuplicate });
buildfire._sendPacket(p, function (err, result) {

callback(err, result);
});
}
/// ref:
, bulkInsert: function (arrayObj, tag, userToken, callback) {

if (arrayObj.constructor !== Array) {

callback({ "code": "error", "message": "the data should be an array" }, null);
return;
}
Expand All @@ -1015,10 +1015,10 @@ var buildfire = {
callback = tag;
tag = '';
}

var p = new Packet(null, 'userData.bulkInsert', { tag: tag, userToken: userToken, obj: arrayObj });
buildfire._sendPacket(p, function (err, result) {

callback(err, result);
});
}
Expand All @@ -1039,16 +1039,16 @@ var buildfire = {
callback = tag;
tag = '';
}

var p = new Packet(null, 'userData.update', { tag: tag, userToken: userToken, id: id, obj: obj });
buildfire._sendPacket(p, function (err, result) {

if (callback) callback(err, result);
});
}
/// ref
, delete: function (id, tag, userToken, callback) {

var userTokenType = typeof (userToken);
if (userTokenType == "undefined")
userToken = '';
Expand All @@ -1063,28 +1063,28 @@ var buildfire = {
callback = tag;
tag = '';
}

var p = new Packet(null, 'userData.delete', { tag: tag, userToken: userToken, id: id });
buildfire._sendPacket(p, function (err, result) {

if (callback) callback(err, result);
});
}
///
, search: function (options, tag, callback) {

var tagType = typeof (tag);
if (tagType == "undefined")
tag = '';
else if (tagType == "function" && typeof (callback) == "undefined") {
callback = tag;
tag = '';
}

//auto correct empty string filter
if (typeof (options) == "undefined") options = { filter: {} };
if (!options.filter) options.filter = {};

var p = new Packet(null, 'userData.search', { tag: tag, obj: options });
buildfire._sendPacket(p, function (err, result) {
callback(err, result);
Expand Down Expand Up @@ -1130,7 +1130,7 @@ var buildfire = {
if(ratio < 1){
var ratio = 1;
}

if (!options)
options = {width: window.innerWidth};
else if (typeof(options) != "object")
Expand Down Expand Up @@ -1292,7 +1292,7 @@ var buildfire = {
console.warn("smartcrop.js isnt imported");



if (url.indexOf("http://imageserver.prod.s3.amazonaws.com") == 0 || url.indexOf("https://imageserver.prod.s3.amazonaws.com") == 0) {
url = url.replace(/^https:\/\//i, 'http://');

Expand All @@ -1313,7 +1313,7 @@ var buildfire = {
canvas.height = options.height;

SmartCrop.crop(img, options, function(result){

var sug = result.topCrop;
ctx.drawImage(img, sug.x, sug.y, sug.width, sug.height,0,0,options.width, options.height);

Expand Down Expand Up @@ -1456,14 +1456,20 @@ var buildfire = {
, deeplink: {
getData: function (callback) {
var qs = buildfire.parseQueryString();
callback(qs.dld); /// dld: Deep Link Data
}
, createLink: function (obj) {
var root = "app" + buildfire._context.appId + "://plugin";
if (!obj)
return root;
if(qs.dld)
callback(JSON.parse(qs.dld)); /// dld: Deep Link Data
else
return root + "?dld=" + JSON.stringify(obj);
callback(null);
},
template: {
get: function (callback) {
var p = new Packet(null, 'deepLink.getTemplate', {});
buildfire._sendPacket(p, callback);
}
},
setData: function (obj, options, callback) {
var p = new Packet(null, 'deepLink.setData', {data : obj, options: options});
buildfire._sendPacket(p, callback);
}
}
/// ref: https://github.com/BuildFire/sdk/wiki/Spinners
Expand Down
15 changes: 0 additions & 15 deletions test/deeplink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,4 @@ describe('buildfire.deeplink', function () {
});
});

describe('deeplink createLink', function () {
beforeEach( function () {
spyOn(buildfire.deeplink, 'createLink');

buildfire.deeplink.createLink('section:7');
});

it("deeplink createLink should exist and be a function", function () {
expect(typeof buildfire.deeplink.createLink).toEqual("function");
});

it("deeplink createLink", function () {
expect(buildfire.deeplink.createLink).toHaveBeenCalledWith('section:7');
});
});
});
5 changes: 0 additions & 5 deletions test/ftest/deeplink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ describe('buildfire.deeplink', function () {
});
});

describe('deeplink createLink', function () {
it("deeplink createLink should exist and be a function", function () {
expect(buildfire.deeplink.createLink).to.a("function");
});
});
});

0 comments on commit 0ddf834

Please sign in to comment.