@@ -144,7 +144,10 @@ public boolean execute(final String action, JSONArray args, final CallbackContex
144
144
} else if ("getAllUserAttributes" .equals (action )) {
145
145
getAllUserAttributes (callbackContext );
146
146
147
- }else {
147
+ } else if ("getUserAttribute" .equals (action )) {
148
+ getUserAttribute (callbackContext , args .optString (0 ));
149
+
150
+ } else {
148
151
// Method not found.
149
152
return false ;
150
153
}
@@ -506,11 +509,9 @@ private void setDebugEnabled(final CallbackContext callbackContext, boolean isDe
506
509
* Used when calling back into JavaScript
507
510
* @param key the attribute
508
511
* @param value the value
509
- * @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
510
512
*
511
513
*/
512
-
513
- private void setUserAttribute (final CallbackContext callbackContext , String key , String value ) {
514
+ private void setUserAttribute (final CallbackContext callbackContext , String key , String value ) {
514
515
try {
515
516
Instabug .setUserAttribute (key ,value );
516
517
callbackContext .success ();
@@ -525,10 +526,8 @@ private void setUserAttribute(final CallbackContext callbackContext, String key,
525
526
* @param callbackContext
526
527
* Used when calling back into JavaScript
527
528
* @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
529
529
*
530
530
*/
531
-
532
531
private void removeUserAttribute (final CallbackContext callbackContext , String key ) {
533
532
try {
534
533
Instabug .removeUserAttribute (key );
@@ -538,6 +537,13 @@ private void removeUserAttribute(final CallbackContext callbackContext, String k
538
537
}
539
538
}
540
539
540
+
541
+ /**
542
+ * Gets all saved user attributes.
543
+ *
544
+ * @param callbackContext
545
+ * Used when calling back into JavaScript
546
+ */
541
547
private void getAllUserAttributes (final CallbackContext callbackContext ) {
542
548
try {
543
549
HashMap userAttributes = Instabug .getAllUserAttributes ();
@@ -548,6 +554,24 @@ private void getAllUserAttributes(final CallbackContext callbackContext) {
548
554
}
549
555
}
550
556
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
+
551
575
/**
552
576
* Adds intent extras for all options passed to activate().
553
577
*/
0 commit comments