diff --git a/README.md b/README.md index eba830f4..edcbc20e 100644 --- a/README.md +++ b/README.md @@ -554,10 +554,14 @@ branchUniversalObj.listOnSpotlight().then(function (res) { ## Referral System Rewarding -### loadRewards() +### loadRewards([bucket]) Reward balances change randomly on the backend when certain actions are taken (defined by your rules), so you'll need to make an asynchronous call to retrieve the balance. Here is the syntax: +**Parameters** + +**bucket**: `String` _[Optional]_ - Load rewards of a specific bucket. If no value provided it will use the `default` bucket. + ##### Usage ```js Branch.loadRewards().then(function (rewards) { diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index de7d89ea..0cf26eff 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -286,11 +286,12 @@ private void redeemRewards(int value, String bucket, CallbackContext callbackCon * in the callback to update the credit totals in your UX.

* * @param callbackContext A callback to execute at the end of this method + * @param bucket Load reward of a specific bucket */ - private void loadRewards(CallbackContext callbackContext) + private void loadRewards(CallbackContext callbackContext, String bucket) { - this.instance.loadRewards(new LoadRewardsListener(callbackContext)); + this.instance.loadRewards(new LoadRewardsListener(callbackContext, this.instance, bucket)); } @@ -802,10 +803,14 @@ public void onRegisterViewFinished(boolean registered, BranchError error) { protected class LoadRewardsListener implements Branch.BranchReferralStateChangedListener { private CallbackContext _callbackContext; + private Branch _instance; + private String _bucket; // Constructor that takes in a required callbackContext object - public LoadRewardsListener(CallbackContext callbackContext) { + public LoadRewardsListener(CallbackContext callbackContext, Branch instance, String bucket) { this._callbackContext = callbackContext; + this._instance = instance; + this._bucket = bucket; } // Listener that implements BranchReferralStateChangedListener for loadRewards @@ -813,8 +818,14 @@ public LoadRewardsListener(CallbackContext callbackContext) { public void onStateChanged(boolean changed, BranchError error) { if (error == null) { - int credits = instance.getCredits(); - + int credits = 0; + + if (this._bucket.length()) { + credits = this._instance.getCreditsForBucket(this._bucket); + } else { + credits = this._instance.getCredits(); + } + this._callbackContext.success(credits); } else { @@ -1127,7 +1138,9 @@ public void run() { } else if (this.action.equals("logout")) { logout(this.callbackContext); } else if (this.action.equals("loadRewards")) { - loadRewards(this.callbackContext); + if (this.args.length() == 1) { + loadRewards(this.callbackContext, this.args.getString(0)); + } } else if (this.action.equals("redeemRewards")) { if (this.args.length() == 1) { redeemRewards(this.args.getInt(0), this.callbackContext); diff --git a/src/ios/BranchSDK.m b/src/ios/BranchSDK.m index 6b5c5d80..687a56bf 100644 --- a/src/ios/BranchSDK.m +++ b/src/ios/BranchSDK.m @@ -263,12 +263,24 @@ - (void)logout:(CDVInvokedUrlCommand*)command - (void)loadRewards:(CDVInvokedUrlCommand*)command { Branch *branch = [self getInstance]; + NSString *bucket = @""; + + if ([command.arguments count] == 1) { + bucket = [command.arguments objectAtIndex:0]; + } [branch loadRewardsWithCallback:^(BOOL changed, NSError *error) { CDVPluginResult* pluginResult = nil; if(!error) { - int credits = (int)[branch getCredits]; + int credits = 0; + + if ([bucket length]) { + credits = (int)[branch getCreditsForBucket:bucket]; + } else { + credits = (int)[branch getCredits]; + } + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:credits]; } else { diff --git a/testbed/npm-debug.log b/testbed/npm-debug.log deleted file mode 100644 index 15585cf1..00000000 --- a/testbed/npm-debug.log +++ /dev/null @@ -1,39 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/Users/alexaustin/.nvm/v0.10.29/bin/node', -1 verbose cli '/Users/alexaustin/.nvm/v0.10.29/bin/npm', -1 verbose cli 'publish' ] -2 info using npm@1.4.14 -3 info using node@v0.10.29 -4 verbose publish [ '.' ] -5 verbose cache add [ '.', null ] -6 verbose cache add name=undefined spec="." args=[".",null] -7 verbose parsed url { protocol: null, -7 verbose parsed url slashes: null, -7 verbose parsed url auth: null, -7 verbose parsed url host: null, -7 verbose parsed url port: null, -7 verbose parsed url hostname: null, -7 verbose parsed url hash: null, -7 verbose parsed url search: null, -7 verbose parsed url query: null, -7 verbose parsed url pathname: '.', -7 verbose parsed url path: '.', -7 verbose parsed url href: '.' } -8 silly lockFile 3a52ce78- . -9 verbose lock . /Users/alexaustin/.npm/3a52ce78-.lock -10 silly lockFile 3a52ce78- . -11 silly lockFile 3a52ce78- . -12 error addLocal Could not install . -13 error Error: ENOENT, open 'package.json' -14 error If you need help, you may report this *entire* log, -14 error including the npm and node versions, at: -14 error -15 error System Darwin 15.5.0 -16 error command "/Users/alexaustin/.nvm/v0.10.29/bin/node" "/Users/alexaustin/.nvm/v0.10.29/bin/npm" "publish" -17 error cwd /Users/alexaustin/Documents/Javascript/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK/testbed -18 error node -v v0.10.29 -19 error npm -v 1.4.14 -20 error path package.json -21 error code ENOENT -22 error errno 34 -23 verbose exit [ 34, true ] diff --git a/www/branch.js b/www/branch.js index f67dfad0..e4e0d330 100644 --- a/www/branch.js +++ b/www/branch.js @@ -353,9 +353,13 @@ Branch.prototype.createBranchUniversalObject = function (options) { * * @return (Promise) */ -Branch.prototype.loadRewards = function () { +Branch.prototype.loadRewards = function (bucket) { - return execute('loadRewards'); + if ( ! bucket) { + bucket = ''; + } + + return execute('loadRewards', [bucket]); };