Skip to content

Commit 87b74ab

Browse files
committed
✨ Add new api getUserAttribute for Android.
1 parent cf81303 commit 87b74ab

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/android/IBGPlugin.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ public boolean execute(final String action, JSONArray args, final CallbackContex
144144
} else if ("getAllUserAttributes".equals(action)) {
145145
getAllUserAttributes(callbackContext);
146146

147-
}else {
147+
} else if ("getUserAttribute".equals(action)) {
148+
getUserAttribute(callbackContext, args.optString(0));
149+
150+
} else {
148151
// Method not found.
149152
return false;
150153
}
@@ -506,11 +509,9 @@ private void setDebugEnabled(final CallbackContext callbackContext, boolean isDe
506509
* Used when calling back into JavaScript
507510
* @param key the attribute
508511
* @param value the value
509-
* @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
510512
*
511513
*/
512-
513-
private void setUserAttribute(final CallbackContext callbackContext, String key, String value) {
514+
private void setUserAttribute(final CallbackContext callbackContext, String key, String value) {
514515
try {
515516
Instabug.setUserAttribute(key,value);
516517
callbackContext.success();
@@ -525,10 +526,8 @@ private void setUserAttribute(final CallbackContext callbackContext, String key,
525526
* @param callbackContext
526527
* Used when calling back into JavaScript
527528
* @param key the attribute key as string
528-
* @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
529529
*
530530
*/
531-
532531
private void removeUserAttribute(final CallbackContext callbackContext, String key) {
533532
try {
534533
Instabug.removeUserAttribute(key);
@@ -538,6 +537,13 @@ private void removeUserAttribute(final CallbackContext callbackContext, String k
538537
}
539538
}
540539

540+
541+
/**
542+
* Gets all saved user attributes.
543+
*
544+
* @param callbackContext
545+
* Used when calling back into JavaScript
546+
*/
541547
private void getAllUserAttributes(final CallbackContext callbackContext) {
542548
try {
543549
HashMap userAttributes = Instabug.getAllUserAttributes();
@@ -548,6 +554,24 @@ private void getAllUserAttributes(final CallbackContext callbackContext) {
548554
}
549555
}
550556

557+
/**
558+
* Gets specific user attribute.
559+
*
560+
* @param callbackContext
561+
* Used when calling back into JavaScript
562+
* @param key
563+
* the attribute key as string
564+
*
565+
*/
566+
private void getUserAttribute(final CallbackContext callbackContext, String key) {
567+
try {
568+
String userAttribute = Instabug.getUserAttribute(key);
569+
callbackContext.success(userAttribute);
570+
} catch (IllegalStateException e) {
571+
callbackContext.error(errorMsg);
572+
}
573+
}
574+
551575
/**
552576
* Adds intent extras for all options passed to activate().
553577
*/

www/instabug.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ Instabug.getAllUserAttributes = function (success, error) {
131131
exec(success, error, 'IBGPlugin', 'getAllUserAttributes', []);
132132
};
133133

134+
Instabug.getUserAttribute = function (key, success, error) {
135+
exec(success, error, 'IBGPlugin', 'getUserAttribute', [key]);
136+
};
137+
134138
Instabug.identifyUserWithEmail = function (email, name, success, error) {
135139
exec(success, error, 'IBGPlugin', 'identifyUserWithEmail', [email, name]);
136140
};

0 commit comments

Comments
 (0)