Skip to content

Commit 8666f4e

Browse files
authored
🤝 Merge pull request #36 from Instabug/feature/missing_apis
Feature/missing apis
2 parents 378f73b + 87b74ab commit 8666f4e

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

src/android/IBGPlugin.java

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.graphics.Color;
55
import android.net.Uri;
6+
import android.util.Log;
67

78
import com.instabug.library.Instabug;
89
import com.instabug.library.invocation.InstabugInvocationEvent;
@@ -18,6 +19,7 @@
1819

1920
import java.io.File;
2021
import java.lang.Integer;
22+
import java.util.HashMap;
2123

2224
/**
2325
* This plugin initializes Instabug.
@@ -133,7 +135,19 @@ public boolean execute(final String action, JSONArray args, final CallbackContex
133135
} else if ("removeUserAttribute".equals(action)) {
134136
removeUserAttribute(callbackContext, args.optString(0));
135137

136-
} else {
138+
} else if ("identifyUserWithEmail".equals(action)) {
139+
identifyUserWithEmail(callbackContext, args.optString(0), args.optString(1));
140+
141+
} else if ("logOut".equals(action)) {
142+
logOut(callbackContext);
143+
144+
} else if ("getAllUserAttributes".equals(action)) {
145+
getAllUserAttributes(callbackContext);
146+
147+
} else if ("getUserAttribute".equals(action)) {
148+
getUserAttribute(callbackContext, args.optString(0));
149+
150+
} else {
137151
// Method not found.
138152
return false;
139153
}
@@ -234,6 +248,7 @@ private void setPrimaryColor(final CallbackContext callbackContext, String color
234248
* @param email
235249
* User's default email
236250
*/
251+
@Deprecated
237252
private void setUserEmail(final CallbackContext callbackContext, String email) {
238253
if (email != null && email.length() > 0) {
239254
try {
@@ -253,6 +268,7 @@ private void setUserEmail(final CallbackContext callbackContext, String email) {
253268
* @param name
254269
* User's name
255270
*/
271+
@Deprecated
256272
private void setUserName(final CallbackContext callbackContext, String name) {
257273
if (name != null && name.length() > 0) {
258274
try {
@@ -264,6 +280,45 @@ private void setUserName(final CallbackContext callbackContext, String name) {
264280
} else callbackContext.error("A name must be provided.");
265281
}
266282

283+
/**
284+
* Set the user identity.
285+
* Instabug will pre-fill the user email in reports.
286+
*
287+
* @param callbackContext
288+
* Used when calling back into JavaScript
289+
* @param email
290+
* User's default email
291+
* @param name
292+
* Username
293+
*
294+
*/
295+
private void identifyUserWithEmail(final CallbackContext callbackContext, String email, String name) {
296+
if (name != null && name.length() > 0 && email != null && email.length() > 0) {
297+
try {
298+
Instabug.identifyUser(name, email);
299+
callbackContext.success();
300+
} catch (IllegalStateException e) {
301+
callbackContext.error(errorMsg);
302+
}
303+
} else callbackContext.error("A name and email must be provided.");
304+
}
305+
306+
307+
/**
308+
* Logout User
309+
*
310+
* @param callbackContext
311+
* Used when calling back into JavaScript
312+
*/
313+
private void logOut(final CallbackContext callbackContext) {
314+
try {
315+
Instabug.logoutUser();
316+
callbackContext.success();
317+
} catch (IllegalStateException e) {
318+
callbackContext.error(errorMsg);
319+
}
320+
}
321+
267322
/**
268323
* Adds specific user data that you need to reports.
269324
*
@@ -454,11 +509,9 @@ private void setDebugEnabled(final CallbackContext callbackContext, boolean isDe
454509
* Used when calling back into JavaScript
455510
* @param key the attribute
456511
* @param value the value
457-
* @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
458512
*
459513
*/
460-
461-
private void setUserAttribute(final CallbackContext callbackContext, String key, String value) {
514+
private void setUserAttribute(final CallbackContext callbackContext, String key, String value) {
462515
try {
463516
Instabug.setUserAttribute(key,value);
464517
callbackContext.success();
@@ -473,10 +526,8 @@ private void setUserAttribute(final CallbackContext callbackContext, String key,
473526
* @param callbackContext
474527
* Used when calling back into JavaScript
475528
* @param key the attribute key as string
476-
* @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
477529
*
478530
*/
479-
480531
private void removeUserAttribute(final CallbackContext callbackContext, String key) {
481532
try {
482533
Instabug.removeUserAttribute(key);
@@ -486,6 +537,41 @@ private void removeUserAttribute(final CallbackContext callbackContext, String k
486537
}
487538
}
488539

540+
541+
/**
542+
* Gets all saved user attributes.
543+
*
544+
* @param callbackContext
545+
* Used when calling back into JavaScript
546+
*/
547+
private void getAllUserAttributes(final CallbackContext callbackContext) {
548+
try {
549+
HashMap userAttributes = Instabug.getAllUserAttributes();
550+
JSONObject jsonUserAttributes = new JSONObject(userAttributes);
551+
callbackContext.success(jsonUserAttributes);
552+
} catch (IllegalStateException e) {
553+
callbackContext.error(errorMsg);
554+
}
555+
}
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+
489575
/**
490576
* Adds intent extras for all options passed to activate().
491577
*/

www/instabug.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ Instabug.removeUserAttribute = function (key, success, error) {
127127
exec(success, error, 'IBGPlugin', 'removeUserAttribute', [key]);
128128
};
129129

130+
Instabug.getAllUserAttributes = function (success, error) {
131+
exec(success, error, 'IBGPlugin', 'getAllUserAttributes', []);
132+
};
133+
134+
Instabug.getUserAttribute = function (key, success, error) {
135+
exec(success, error, 'IBGPlugin', 'getUserAttribute', [key]);
136+
};
137+
138+
Instabug.identifyUserWithEmail = function (email, name, success, error) {
139+
exec(success, error, 'IBGPlugin', 'identifyUserWithEmail', [email, name]);
140+
};
141+
142+
Instabug.logOut = function (success, error) {
143+
exec(success, error, 'IBGPlugin', 'logOut', []);
144+
};
145+
130146
Instabug.setDebugEnabled = function (isDebugEnabled, success, error) {
131147
exec(success, error, 'IBGPlugin', 'setDebugEnabled', [isDebugEnabled]);
132148
if(success) {

0 commit comments

Comments
 (0)