diff --git a/DEVELOPING.md b/DEVELOPING.md
index dd522855..9bef1612 100644
--- a/DEVELOPING.md
+++ b/DEVELOPING.md
@@ -53,7 +53,7 @@ npm install;
> Build
```sh
-gulp predev;
+gulp prerelease;
```
> **[optional]** Update [iOS SDK](https://github.com/BranchMetrics/ios-branch-deep-linking/tags) (will need to update `plugin.xml` dependencies if new iOS files)
diff --git a/gulpfile.js b/gulpfile.js
index 00d8a921..dc9e0f70 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,12 +1,11 @@
-var gulp = require('gulp');
-var fs = require('fs');
+var gulp = require('gulp');
+var fs = require('fs');
var sourcemaps = require('gulp-sourcemaps');
-var babel = require('gulp-babel');
-var eslint = require('gulp-eslint');
-var jscs = require('gulp-jscs');
+var babel = require('gulp-babel');
+var eslint = require('gulp-eslint');
+var jscs = require('gulp-jscs');
gulp.task('prerelease', [ 'setupNpm', 'babel', 'lint' ]);
-gulp.task('predev', [ 'setupDev', 'babel', 'lint' ]);
// -----------------------------------------------------------------------------
// setup for development use
@@ -33,8 +32,8 @@ function genNpmPluginXML() {
files = files.concat(emitFiles(root + 'Branch-SDK/Requests/'));
var newLineIndent = '\n ';
- xml = xml.replace('', newLineIndent
- + files.join(newLineIndent));
+ xml = xml.replace('', newLineIndent +
+ files.join(newLineIndent));
fs.writeFileSync('plugin.xml', xml);
};
@@ -67,10 +66,10 @@ function setIosNpmOrDev(npmOrDev) {
if (npmOrDev === 'npm') {
content = '#define BRANCH_NPM true';
}
-else if (npmOrDev === 'dev') {
+ else if (npmOrDev === 'dev') {
content = '//empty';
}
-else {
+ else {
throw new Error('expected deployed|local, not ' + deployedOrLocal);
}
fs.writeFileSync('src/ios/BranchNPM.h', content + '\n');
@@ -84,7 +83,7 @@ function emitFiles(path) {
if (filename.match(/\.m$/)) {
fileType = 'source';
}
-else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
+ else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
fileType = 'header';
}
if (fileType) {
@@ -111,11 +110,11 @@ function babelize(taskName, dir) {
});
gulp.task(taskName + '-babel', [ taskName + '-copy' ], () => {
return gulp.src(srcPattern)
- .pipe(sourcemaps.init())
- .pipe(babel({
- presets: [ 'es2015', 'stage-2' ]
- }))
- .pipe(gulp.dest(destDir));
+ .pipe(sourcemaps.init())
+ .pipe(babel({
+ presets: [ 'es2015', 'stage-2' ]
+ }))
+ .pipe(gulp.dest(destDir));
});
}
@@ -131,30 +130,32 @@ gulp.task('babel', babelTasks);
gulp.task('lint', [ 'eslint', 'jscs-lint' ]);
var srcs = [
- 'hooks.es6/**/*.js',
- 'www.es6/**/*.js',
- 'gulpfile.js',
- 'tests.es6/**/*.js',
- 'testbed/www/js.es6/**/*.js',
- '!node_modules/**',
- '!testbed/platforms/**',
- '!testbed/plugins/**',
- '!tests-harness/platforms/**',
- '!tests-harness/plugins/**'
+'hooks.es6/**/*.js',
+'www.es6/**/*.js',
+'gulpfile.js',
+'tests.es6/**/*.js',
+'testbed/www/js.es6/**/*.js',
+'!node_modules/**',
+'!testbed/platforms/**',
+'!testbed/plugins/**',
+'!tests-harness/platforms/**',
+'!tests-harness/plugins/**'
];
gulp.task('eslint', () => {
return gulp.src(srcs)
- .pipe(eslint())
- .pipe(eslint.format())
- .pipe(eslint.failAfterError());
+ .pipe(eslint())
+ .pipe(eslint.format())
+ .pipe(eslint.failAfterError());
});
function jscsTask(fix) {
var ret = gulp.src(srcs)
- .pipe(jscs({ fix: fix }))
- .pipe(jscs.reporter())
- .pipe(jscs.reporter('fail'));
+ .pipe(jscs({
+ fix: fix
+ }))
+ .pipe(jscs.reporter())
+ .pipe(jscs.reporter('fail'));
if (fix) {
ret.pipe(gulp.dest('.'));
}
diff --git a/plugin.xml b/plugin.xml
index 34c53d6c..cd7b54a0 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -105,14 +105,14 @@ SOFTWARE.
-
+
-
+
@@ -167,7 +167,7 @@ SOFTWARE.
-
+
@@ -197,6 +197,6 @@ SOFTWARE.
-
+
diff --git a/testbed/www/js.es6/index.js b/testbed/www/js.es6/index.js
index 4e4332e4..365580fb 100644
--- a/testbed/www/js.es6/index.js
+++ b/testbed/www/js.es6/index.js
@@ -1,303 +1,314 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
- var app = {
- // Application Constructor
- initialize: function() {
- alert("hello");
- this.bindEvents();
- },
- // Bind Event Listeners
- //
- // Bind any events that are required on startup. Common events are:
- // 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: function() {
- document.addEventListener('deviceready', this.onDeviceReady, false);
- },
- // deviceready Event Handler
- //
- // The scope of 'this' is the event. In order to call the 'receivedEvent'
- // function, we must explicitly call 'app.receivedEvent(...);'
- onDeviceReady: function() {
- app.receivedEvent('app');
- },
- // Update DOM on a Received Event
- receivedEvent: function(id) {
-
- if (navigator.userAgent.indexOf('iPhone') >= 0) {
- document.getElementsByTagName("html")[0].className = 'ios';
- }
- else if (navigator.userAgent.indexOf('Android') >= 0) {
- document.getElementsByTagName("html")[0].className = 'android';
- }
-
- InitSession();
-
- }
+'use strict';
+
+// app
+
+var app = {
+ initialize: function initialize() {
+ this.bindEvents();
+ },
+ bindEvents: function bindEvents() {
+ document.addEventListener('deviceready', this.onDeviceReady, false);
+ },
+ onDeviceReady: function onDeviceReady() {
+ BranchInit(true);
+ }
};
-
app.initialize();
-function onBranchLinkHook(data) {
+// branch
+
+function BranchInit(isDebug) {
+ console.log('Trigger BranchInit()');
+
+ // for development and debugging only
+ Branch.setDebug(isDebug);
+
+ // sync with mixpanel if installed
+ Branch.setMixpanelToken('your_mixpanel_token');
+
+ // init
+ Branch.initSession(BranchLinkData).then(function(res) {
+ console.log(res);
+ }).catch(function(err) {
+ console.error(err);
+ });
+
+ // handler for deep link data
+ function BranchLinkData(data) {
+ console.log('Trigger BranchLinkData()');
+
if (data) {
- alert('Initialize: ' + JSON.stringify(data));
+ alert(JSON.stringify(data));
}
- else {
- alert('No data found');
- }
-}
+ }
+
+ // optional
+ Branch.onNonBranchLink(function NonBranchLinkHandler(data) {
+ console.log('Trigger NonBranchLinkData()');
-function InitSession() {
- console.log('Trigger InitSession()');
-
- Branch.setMixpanelToken('');
- Branch.initSession(onBranchLinkHook).then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
- Branch.onNonBranchLink(function NonBranchLinkHandler(data) {
- if (data) {
- alert('Non-branch link found: ' + JSON.stringify(data));
- }
- });
+ if (data) {
+ alert(JSON.stringify(data));
+ }
+ });
}
-function CustomAction() {
- console.log('Trigger CustomAction()');
+function BranchEvent() {
+ console.log('Trigger BranchEvent()');
- var action = document.getElementById('custom-action').value;
+ // event name
+ var event = document.getElementById('custom-action').value;
- Branch.userCompletedAction(action).then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+ // optional
+ var metadata = { "custom_dictionary": 123 };
+ Branch.userCompletedAction(event, metadata).then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function GetLatestReferringParams() {
- console.log('Trigger GetLatestReferringParams()');
+function BranchFirstData() {
+ console.log('Trigger BranchFirstData()');
- Branch.getLatestReferringParams().then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+ Branch.getFirstReferringParams().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function GetFirstReferringParams() {
- console.log('Trigger GetFirstReferringParams()');
+function BranchLatestData() {
+ console.log('Trigger BranchLatestData()');
- Branch.getFirstReferringParams().then(function(res) {
- alert('Response: ' + JSON.stringify(res));
- console.log(res);
- }).catch(function(err) {
- alert('Error: ' + JSON.stringify(err));
- console.error(err);
- });
+ Branch.getLatestReferringParams().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function SetIdentity() {
- console.log('Trigger SetIdentity()');
+function BranchUser() {
+ console.log('Trigger BranchUser()');
- var newIdentity = document.getElementById('identity').value;
-
- Branch.setIdentity(newIdentity).then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+ var userId = document.getElementById('identity').value;
+ Branch.setIdentity(userId).then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function Logout() {
- console.log('Trigger Logout()');
+function BranchLogout() {
+ console.log('Trigger BranchLogout()');
- Branch.logout().then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+ Branch.logout().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
var branchUniversalObj = null;
-
-function CreateBranchUniversalObject() {
-
- console.log('Trigger CreateBranchUniversalObject()');
-
- var properties = {
- canonicalIdentifier: 'testbed',
- title: 'testbed',
- contentDescription: 'Testbed Application',
- contentImageUrl: 'https://imgflip.com/s/meme/Derp.jpg',
- contentIndexingMode: 'public',
- contentMetadata: {}
- };
-
- Branch.createBranchUniversalObject(properties)
- .then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- branchUniversalObj = res;
- })
- .catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
-
+function BranchUniversalObject() {
+ console.log('Trigger BranchUniversalObject()');
+
+ // only canonicalIdentifier is required
+ var properties = {
+ canonicalIdentifier: "123",
+ canonicalUrl: "http://example.com/123",
+ title: "Content 123",
+ contentDescription: "Content 123 " + Date.now(),
+ contentImageUrl: "http://lorempixel.com/400/400/",
+ price: 12.12,
+ currency: "GBD",
+ contentIndexingMode: "private",
+ contentMetadata: {
+ "custom": "data",
+ "testing": 123,
+ "this_is": true
+ }
+ };
+
+ // create a branchUniversalObj variable to reference with other Branch methods
+ Branch.createBranchUniversalObject(properties).then(function(res) {
+ console.log(res);
+ branchUniversalObj = res;
+ alert("Response: " + JSON.stringify(res));
+ }).catch(function(err) {
+ console.log(err);
+ alert("Error: " + JSON.stringify(err));
+ });
}
-function RegisterView() {
- console.log('Trigger RegisterView()');
-
- branchUniversalObj.registerView().then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });;
+function BranchView() {
+ console.log('Trigger BranchView()');
+
+ if (branchUniversalObj === null) {
+ return alert('need to Generate Branch Universal Object');
+ }
+ branchUniversalObj.registerView().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function GenerateShortUrl() {
- console.log('Trigger GenerateShortUrl()');
-
- var properties = {
- feature: 'test',
- alias: document.getElementById('alias').value,
- channel: 'test',
- stage: 'test',
- duration: 10000
- };
- var controlParams = {
- $fallback_url: 'www.another.com',
- $desktop_url: 'www.desktop.com',
- $android_url: 'test',
- $ios_url: 'ios',
- $ipad_url: 'ipad',
- $fire_url: 'fire',
- $blackberry_url: 'blackberry',
- $windows_phone_url: 'win-phone'
- };
-
- branchUniversalObj.generateShortUrl(properties, controlParams).then(function(res) {
- console.log(res);
- document.getElementById('generated-url').value = res.url;
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+function BranchDeepLink() {
+ console.log('Trigger BranchDeepLink()');
+
+ // optional fields
+ var analytics = {
+ channel: "channel",
+ feature: "feature",
+ campaign: "campaign",
+ stage: "stage",
+ tags: [ "one", "two", "three" ],
+ alias: document.getElementById('alias').value
+ };
+
+ // optional fields
+ var properties = {
+ $fallback_url: "www.example.com",
+ $desktop_url: "www.desktop.com",
+ $android_url: "www.android.com",
+ $ios_url: "www.ios.com",
+ $ipad_url: "www.ipad.com",
+ more_custom: "data",
+ even_more_custom: true,
+ this_is_custom: 41231
+ };
+
+ // needs a universal object
+ if (branchUniversalObj === null) {
+ return alert('need to Generate Branch Universal Object');
+ }
+
+ branchUniversalObj.generateShortUrl(analytics, properties).then(function(res) {
+ console.log(res);
+ document.getElementById('generated-url').placeholder = '';
+ document.getElementById('generated-url').value = res.url;
+ alert(JSON.stringify(res.url));
+ }).catch(function(err) {
+ console.error(err);
+ alert(JSON.stringify(err));
+ });
}
-function ShowShareSheet() {
- console.log('Trigger ShowShareSheet()');
-
- var properties = {
- feature: 'test',
- alias: document.getElementById('alias').value,
- channel: 'test',
- stage: 'test',
- duration: 10000
- };
- var controlParams = {
- $fallback_url: 'www.another.com',
- $desktop_url: 'www.desktop.com',
- $android_url: 'test',
- $ios_url: 'ios',
- $ipad_url: 'ipad',
- $fire_url: 'fire',
- $blackberry_url: 'blackberry',
- $windows_phone_url: 'win-phone'
- };
-
- console.log(branchUniversalObj);
-
- // Set listeners
- branchUniversalObj.onShareSheetLaunched(function() {
- console.log('Share sheet launched');
- });
- branchUniversalObj.onShareSheetDismissed(function() {
- console.log('Share sheet dismissed');
+function BranchShareSheet() {
+ console.log('Trigger BranchShareSheet()');
+
+ // optional fields
+ var analytics = {
+ channel: "channel",
+ feature: "feature",
+ campaign: "campaign",
+ stage: "stage",
+ tags: [ "one", "two", "three" ]
+ };
+
+ // optional fields
+ var properties = {
+ $fallback_url: "www.example.com",
+ $desktop_url: "www.desktop.com",
+ $android_url: "www.android.com",
+ $ios_url: "www.ios.com",
+ $ipad_url: "www.ipad.com",
+ more_custom: "data",
+ even_more_custom: true,
+ this_is_custom: 41231
+ };
+
+ var message = "Check out this link";
+
+ // needs a universal object
+ if (branchUniversalObj === null) {
+ return alert('need to Generate Branch Universal Object');
+ }
+
+ // optional listeners (must be called before showShareSheet)
+ branchUniversalObj.onShareSheetLaunched(function(res) {
+ // android only
+ console.log(res);
+ alert(JSON.stringify(res));
});
- branchUniversalObj.onLinkShareResponse(function(res) {
- console.log('Share link response: ' + JSON.stringify(res));
+ branchUniversalObj.onShareSheetDismissed(function(res) {
+ console.log(res);
+ alert(JSON.stringify(res));
});
- branchUniversalObj.onChannelSelected(function(res) {
- console.log('Channel selected: ' + JSON.stringify(res));
+ branchUniversalObj.onLinkShareResponse(function(res) {
+ console.log(res);
+ alert(JSON.stringify(res));
+ });
+ branchUniversalObj.onChannelSelected(function(res) {
+ // android only
+ console.log(res);
+ alert(JSON.stringify(res));
});
- branchUniversalObj.showShareSheet(properties, controlParams, 'Custom Text');
-
+ // share sheet
+ branchUniversalObj.showShareSheet(analytics, properties, message);
}
-function ListOnSpotlight() {
- console.log('Trigger ListOnSpotlight()');
- branchUniversalObj.listOnSpotlight().then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+function BranchSpotlight() {
+ console.log('Trigger ListOnSpotlight()');
+
+ if (branchUniversalObj === null) {
+ return alert('need to Generate Branch Universal Object');
+ }
+ branchUniversalObj.listOnSpotlight().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function LoadRewards() {
- console.log('Trigger LoadRewards()');
- Branch.loadRewards().then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+function BranchReferralsLoad() {
+ console.log('Trigger BranchReferralsLoad()');
+
+ Branch.loadRewards().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function RedeemRewards() {
- console.log('Trigger RedeemRewards()');
- var reward = 1000;
-
- Branch.redeemRewards(reward).then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+function BranchReferralsRedeem() {
+ console.log('Trigger BranchReferralsRedeem()');
+
+ var reward = 1000;
+ Branch.redeemRewards(reward).then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
-function CreditHistory() {
- console.log('Trigger CreditHistory()');
- Branch.creditHistory().then(function(res) {
- console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
- console.error(err);
- alert('Error: ' + JSON.stringify(err));
- });
+function BranchReferralsHistory() {
+ console.log('Trigger BranchReferralsHistory()');
+
+ Branch.creditHistory().then(function(res) {
+ console.log(res);
+ alert('Response: ' + JSON.stringify(res));
+ }).catch(function(err) {
+ console.error(err);
+ alert('Error: ' + JSON.stringify(err));
+ });
}
diff --git a/testbed/www/js/index.js b/testbed/www/js/index.js
index 2b774ec0..b56ba0aa 100644
--- a/testbed/www/js/index.js
+++ b/testbed/www/js/index.js
@@ -1,52 +1,53 @@
'use strict';
// app
+
var app = {
initialize: function initialize() {
- alert("Launched the simulator now for Safari debug");
this.bindEvents();
},
bindEvents: function bindEvents() {
document.addEventListener('deviceready', this.onDeviceReady, false);
- document.addEventListener('resume', this.onDeviceResume, false);
},
onDeviceReady: function onDeviceReady() {
BranchInit(true);
- },
- onDeviceResume: function onDeviceResume() {
- BranchInit(true);
}
};
app.initialize();
// branch
-function onBranchLinkHook(data) {
- if (data) {
- alert('Initialize: ' + JSON.stringify(data));
- }
- else {
- alert('No data found');
- }
-}
function BranchInit(isDebug) {
console.log('Trigger BranchInit()');
// for development and debugging only
Branch.setDebug(isDebug);
+
// sync with mixpanel if installed
Branch.setMixpanelToken('your_mixpanel_token');
+
// init
- Branch.initSession(onBranchLinkHook).then(function(res) {
+ Branch.initSession(BranchLinkData).then(function (res) {
console.log(res);
- alert('Response: ' + JSON.stringify(res));
- }).catch(function(err) {
+ }).catch(function (err) {
console.error(err);
- alert('Error: ' + JSON.stringify(err));
});
+
+ // handler for deep link data
+ function BranchLinkData(data) {
+ console.log('Trigger BranchLinkData()');
+
+ if (data) {
+ alert(JSON.stringify(data));
+ }
+ }
+
+ // optional
Branch.onNonBranchLink(function NonBranchLinkHandler(data) {
+ console.log('Trigger NonBranchLinkData()');
+
if (data) {
- alert('Non-branch link found: ' + JSON.stringify(data));
+ alert(JSON.stringify(data));
}
});
}
@@ -127,7 +128,7 @@ function BranchUniversalObject() {
canonicalUrl: "http://example.com/123",
title: "Content 123",
contentDescription: "Content 123 " + Date.now(),
- contentImageUrl: "http://lorempixel.com/400/400",
+ contentImageUrl: "http://lorempixel.com/400/400/",
price: 12.12,
currency: "GBD",
contentIndexingMode: "private",
@@ -310,4 +311,4 @@ function BranchReferralsHistory() {
console.error(err);
alert('Error: ' + JSON.stringify(err));
});
-}
+}
\ No newline at end of file
diff --git a/www.es6/branch.js b/www.es6/branch.js
index f1840bc2..dbe2273f 100644
--- a/www.es6/branch.js
+++ b/www.es6/branch.js
@@ -154,12 +154,11 @@ Branch.prototype.setMixpanelToken = function(token) {
*/
Branch.prototype.setDebug = function(isEnabled) {
- isEnabled = (typeof isEnabled !== 'boolean') ? false : isEnabled;
+ isEnabled = typeof isEnabled !== 'boolean' ? false : isEnabled;
this.debugMode = isEnabled;
return execute('setDebug', [ isEnabled ]);
-
};
/**
@@ -476,4 +475,4 @@ Branch.prototype.creditHistory = function() {
var defaultNonBranchLinkHandler = function(response) {};
window.NonBranchLinkHandler = (typeof NonBranchLinkHandler === 'undefined') ? defaultNonBranchLinkHandler : NonBranchLinkHandler;
-module.exports = new Branch;
+module.exports = new Branch();
diff --git a/www/branch.js b/www/branch.js
index d85e472f..79771785 100644
--- a/www/branch.js
+++ b/www/branch.js
@@ -1,3 +1,5 @@
+'use strict';
+
/**
* Branch.IO SDK
* -------------
@@ -20,16 +22,15 @@ var _API_CLASS = 'BranchSDK'; // SDK Class
*/
function execute(method, params) {
- params = (!params) ? [] : params;
+ params = !params ? [] : params;
- return new Promise(function(resolve, reject) {
- exec(function(res) {
+ return new Promise(function (resolve, reject) {
+ exec(function (res) {
resolve(res);
- }, function(err) {
+ }, function (err) {
reject(err);
}, _API_CLASS, method, params);
});
-
}
/**
@@ -43,21 +44,19 @@ function execute(method, params) {
*/
function executeCallback(method, callback, params) {
- params = (!params) ? [] : params;
+ params = !params ? [] : params;
- exec(callback, function(err) {
+ exec(callback, function (err) {
console.error(err);
}, _API_CLASS, method, params);
-
}
/**
* @class Branch
*/
-var Branch = function() {
+var Branch = function Branch() {
this.debugMode = false;
-
};
var disableGlobalListenersWarnings = false;
@@ -65,7 +64,7 @@ var disableGlobalListenersWarnings = false;
/**
* Don't emit warnings regarding use of global listeners.
*/
-Branch.prototype.disableGlobalListenersWarnings = function() {
+Branch.prototype.disableGlobalListenersWarnings = function () {
disableGlobalListenersWarnings = true;
};
@@ -79,19 +78,14 @@ function onBranchLinkStub(data) {
* @param (Function) onBranchLinkHook. listener to trigger on deep links.
* @return (Promise)
*/
-Branch.prototype.initSession = function(onBranchLinkHook) {
+Branch.prototype.initSession = function (onBranchLinkHook) {
if (!onBranchLinkHook && !disableGlobalListenersWarnings) {
- console.log('WARNING: branch link hook is not being passed to initSession. ' +
- 'Falling back to global DeepLinkHandler method. See https://goo.gl/GijGKP for details.');
- }
- else {
+ console.log('WARNING: branch link hook is not being passed to initSession. ' + 'Falling back to global DeepLinkHandler method. See https://goo.gl/GijGKP for details.');
+ } else {
var currentHook = window.DeepLinkHandler;
if (currentHook !== undefined && currentHook !== onBranchLinkStub) {
if (!disableGlobalListenersWarnings) {
- console.log('WARNING: you are calling initSession with a branch link hook when an ' +
- 'existing global DeepLinkHandler is defined. The global ' +
- 'DeepLinkHandler will be overwritten. See https://goo.gl/GijGKP ' +
- 'for details.');
+ console.log('WARNING: you are calling initSession with a branch link hook when an ' + 'existing global DeepLinkHandler is defined. The global ' + 'DeepLinkHandler will be overwritten. See https://goo.gl/GijGKP ' + 'for details.');
}
}
if (onBranchLinkHook) {
@@ -103,7 +97,6 @@ Branch.prototype.initSession = function(onBranchLinkHook) {
return execute('initSession');
};
-
var nonBranchLinkListener = null;
function onNonBranchLinkStub(data) {
nonBranchLinkListener(data);
@@ -112,7 +105,7 @@ function onNonBranchLinkStub(data) {
/**
* Register listener for non branch links.
*/
-Branch.prototype.onNonBranchLink = function(newHook) {
+Branch.prototype.onNonBranchLink = function (newHook) {
if (!newHook) {
throw new Error('non branch link hook is falsy, expected a function, not: "' + newHook + '"');
}
@@ -120,15 +113,12 @@ Branch.prototype.onNonBranchLink = function(newHook) {
var currentHook = window.NonBranchLinkHandler;
if (currentHook !== undefined && currentHook !== onNonBranchLinkStub && currentHook !== defaultNonBranchLinkHandler) {
if (!disableGlobalListenersWarnings) {
- console.log('WARNING: you are calling onNonBranchLink when an ' +
- 'existing global NonBranchLinkHandler is defined. The global ' +
- 'NonBranchLinkHandler will be overwritten. See https://goo.gl/GijGKP ' +
- 'for details.');
+ console.log('WARNING: you are calling onNonBranchLink when an ' + 'existing global NonBranchLinkHandler is defined. The global ' + 'NonBranchLinkHandler will be overwritten. See https://goo.gl/GijGKP ' + 'for details.');
}
}
nonBranchLinkListener = newHook;
window.NonBranchLinkHandler = onNonBranchLinkStub;
-}
+};
/**
* Get Mixpanel tolen/assisstance.
@@ -138,10 +128,9 @@ Branch.prototype.onNonBranchLink = function(newHook) {
*
* @return (Promise)
*/
-Branch.prototype.setMixpanelToken = function(token) {
-
- return execute('setMixpanelToken', [ token ]);
+Branch.prototype.setMixpanelToken = function (token) {
+ return execute('setMixpanelToken', [token]);
};
/**
@@ -152,7 +141,7 @@ Branch.prototype.setMixpanelToken = function(token) {
*
* @return (Promise)
*/
-Branch.prototype.setDebug = function(isEnabled) {
+Branch.prototype.setDebug = function (isEnabled) {
isEnabled = typeof isEnabled !== 'boolean' ? false : isEnabled;
@@ -166,10 +155,9 @@ Branch.prototype.setDebug = function(isEnabled) {
*
* @return (Promise)
*/
-Branch.prototype.getFirstReferringParams = function() {
+Branch.prototype.getFirstReferringParams = function () {
return execute('getFirstReferringParams');
-
};
/**
@@ -177,10 +165,9 @@ Branch.prototype.getFirstReferringParams = function() {
*
* @return (Promise)
*/
-Branch.prototype.getLatestReferringParams = function() {
+Branch.prototype.getLatestReferringParams = function () {
return execute('getLatestReferringParams');
-
};
/**
@@ -191,17 +178,15 @@ Branch.prototype.getLatestReferringParams = function() {
* @return (Promise)
*
*/
-Branch.prototype.setIdentity = function(identity) {
+Branch.prototype.setIdentity = function (identity) {
if (identity) {
- return execute('setIdentity', [ identity ]);
- }
- else {
- return new Promise(function(resolve, reject) {
+ return execute('setIdentity', [identity]);
+ } else {
+ return new Promise(function (resolve, reject) {
reject('Please set an identity');
});
}
-
};
/**
@@ -209,10 +194,9 @@ Branch.prototype.setIdentity = function(identity) {
*
* @return (Promise)
*/
-Branch.prototype.logout = function() {
+Branch.prototype.logout = function () {
return execute('logout');
-
};
/**
@@ -223,16 +207,15 @@ Branch.prototype.logout = function() {
*
* @return (Promise)
*/
-Branch.prototype.userCompletedAction = function(action, metaData) {
+Branch.prototype.userCompletedAction = function (action, metaData) {
- var args = [ action ];
+ var args = [action];
if (metaData) {
args.push(metaData);
}
return execute('userCompletedAction', args);
-
};
/**
@@ -255,10 +238,10 @@ Branch.prototype.userCompletedAction = function(action, metaData) {
* | contentMetadata | Object | Custom key/value |
* --------------------------------------------------------------
*/
-Branch.prototype.createBranchUniversalObject = function(options) {
+Branch.prototype.createBranchUniversalObject = function (options) {
- return new Promise(function(resolve, reject) {
- execute('createBranchUniversalObject', [ options ]).then(function(res) {
+ return new Promise(function (resolve, reject) {
+ execute('createBranchUniversalObject', [options]).then(function (res) {
var obj = {
message: res.message,
@@ -271,10 +254,9 @@ Branch.prototype.createBranchUniversalObject = function(options) {
*
* @return (Promise)
*/
- obj.registerView = function() {
-
- return execute('registerView', [ obj.instanceId ]);
+ obj.registerView = function () {
+ return execute('registerView', [obj.instanceId]);
};
/**
@@ -310,10 +292,9 @@ Branch.prototype.createBranchUniversalObject = function(options) {
* | $windows_phone_url | String | Kindle Fire URL |
* -------------------------------------------------------
*/
- obj.generateShortUrl = function(options, controlParameters) {
-
- return execute('generateShortUrl', [ obj.instanceId, options, controlParameters ]);
+ obj.generateShortUrl = function (options, controlParameters) {
+ return execute('generateShortUrl', [obj.instanceId, options, controlParameters]);
};
/**
@@ -350,14 +331,13 @@ Branch.prototype.createBranchUniversalObject = function(options) {
* | $windows_phone_url | String | Kindle Fire URL |
* -------------------------------------------------------
*/
- obj.showShareSheet = function(options, controlParameters, shareText) {
+ obj.showShareSheet = function (options, controlParameters, shareText) {
if (!shareText) {
shareText = 'This stuff is awesome: ';
}
- return execute('showShareSheet', [ obj.instanceId, options, controlParameters, shareText ]);
-
+ return execute('showShareSheet', [obj.instanceId, options, controlParameters, shareText]);
};
/**
@@ -365,29 +345,26 @@ Branch.prototype.createBranchUniversalObject = function(options) {
*
* @param (Function) callback
*/
- obj.onShareSheetLaunched = function(callback) {
+ obj.onShareSheetLaunched = function (callback) {
if (deviceVendor.indexOf('Apple') < 0) {
- executeCallback('onShareLinkDialogLaunched', callback, [ obj.instanceId ]);
+ executeCallback('onShareLinkDialogLaunched', callback, [obj.instanceId]);
}
-
};
- obj.onShareSheetDismissed = function(callback) {
+ obj.onShareSheetDismissed = function (callback) {
- executeCallback('onShareLinkDialogDismissed', callback, [ obj.instanceId ]);
-
- }
+ executeCallback('onShareLinkDialogDismissed', callback, [obj.instanceId]);
+ };
/**
* Set on link share listener callback.
*
* @param (Function) callback
*/
- obj.onLinkShareResponse = function(callback) {
-
- executeCallback('onLinkShareResponse', callback, [ obj.instanceId ]);
+ obj.onLinkShareResponse = function (callback) {
+ executeCallback('onLinkShareResponse', callback, [obj.instanceId]);
};
/**
@@ -395,30 +372,26 @@ Branch.prototype.createBranchUniversalObject = function(options) {
*
* @param (Function) callback
*/
- obj.onChannelSelected = function(callback) {
+ obj.onChannelSelected = function (callback) {
if (deviceVendor.indexOf('Apple') < 0) {
- executeCallback('onChannelSelected', callback, [ obj.instanceId ]);
+ executeCallback('onChannelSelected', callback, [obj.instanceId]);
}
-
};
/**
* List item on Spotlight (iOS Only).
*/
- obj.listOnSpotlight = function() {
-
- return execute('listOnSpotlight', [ obj.instanceId ]);
+ obj.listOnSpotlight = function () {
+ return execute('listOnSpotlight', [obj.instanceId]);
};
resolve(obj);
-
- }, function(err) {
+ }, function (err) {
reject(err);
});
});
-
};
/**
@@ -426,14 +399,13 @@ Branch.prototype.createBranchUniversalObject = function(options) {
*
* @return (Promise)
*/
-Branch.prototype.loadRewards = function(bucket) {
+Branch.prototype.loadRewards = function (bucket) {
if (!bucket) {
bucket = '';
}
- return execute('loadRewards', [ bucket ]);
-
+ return execute('loadRewards', [bucket]);
};
/**
@@ -444,16 +416,15 @@ Branch.prototype.loadRewards = function(bucket) {
*
* @return (Promise)
*/
-Branch.prototype.redeemRewards = function(value, bucket) {
+Branch.prototype.redeemRewards = function (value, bucket) {
- var params = [ value ];
+ var params = [value];
if (bucket) {
params.push(bucket);
}
return execute('redeemRewards', params);
-
};
/**
@@ -461,10 +432,9 @@ Branch.prototype.redeemRewards = function(value, bucket) {
*
* @return (Promise)
*/
-Branch.prototype.creditHistory = function() {
+Branch.prototype.creditHistory = function () {
return execute('getCreditHistory');
-
};
/**
@@ -472,7 +442,7 @@ Branch.prototype.creditHistory = function() {
*
* @param {String} response
*/
-var defaultNonBranchLinkHandler = function(response) {};
-window.NonBranchLinkHandler = (typeof NonBranchLinkHandler === 'undefined') ? defaultNonBranchLinkHandler : NonBranchLinkHandler;
+var defaultNonBranchLinkHandler = function defaultNonBranchLinkHandler(response) {};
+window.NonBranchLinkHandler = typeof NonBranchLinkHandler === 'undefined' ? defaultNonBranchLinkHandler : NonBranchLinkHandler;
-module.exports = new Branch();
+module.exports = new Branch();
\ No newline at end of file