Skip to content

Commit 39d884a

Browse files
authored
[Mob 3209] - [MOB-32011]: Flutter API [Surveys] (#60)
* Android API Mappings * IOS API Mapping * Flutter API Mapping * Adds tests for new API * updates Readme * updated Changelog ## Mapped APIs: * showSurvey * hasRespondedToSurvey ### Note: I will bump the version after the changes are accepted and start the release process
1 parent de700ff commit 39d884a

File tree

8 files changed

+112
-10
lines changed

8 files changed

+112
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## Master
1+
## Version 0.0.4 (2019-04-14)
22

3+
* Adds hasRespondedToSurvey API mapping.
4+
* Adds showSurvey API mapping.
35
* Adds showSurveyIfAvailable API mapping.
46
* Adds setShouldShowWelcomeScreen API mapping.
57
* Adds setOnDismissCallback API mapping.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ The section below contains the APIs we're planning to implement for our 1.0 rele
8888
| `setOnDismissCallback(Function function)` | `setOnDismissCallback(OnDismissCallback onDismissCallback)`<br>`didDismissSurveyHandler` |
8989
| `setShouldShowWelcomeScreen(bool shouldShowWelcomeScreen)` | `setShouldShowWelcomeScreen(boolean shouldShow)`<br>`shouldShowWelcomeScreen` |
9090
| `showSurveyIfAvailable()` | `showSurveyIfAvailable()`<br>`+ showSurveyIfAvailable` |
91-
| | `showSurvey(String token)`<br>`+ showSurveyWithToken:` |
92-
| | `setThresholdForReshowingSurveyAfterDismiss(int sessionsCount, int daysCount)`<br>`+ setThresholdForReshowingSurveyAfterDismiss:daysCount:` |
93-
| | `hasRespondToSurvey(String token)`<br>`+ hasRespondedToSurveyWithToken:` |
91+
| `showSurvey(String surveyToken)` | `showSurvey(String token)`<br>`+ showSurveyWithToken:` |
92+
| `hasRespondedToSurvey(String surveyToken, Function function)` | `hasRespondToSurvey(String token)`<br>`+ hasRespondedToSurveyWithToken:` |
9493

9594
## Integration
9695

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,29 @@ public void showSurveysIfAvailable() {
707707
Surveys.showSurveyIfAvailable();
708708
}
709709

710+
/**
711+
* Shows survey with a specific token.
712+
* Does nothing if there are no available surveys with that specific token.
713+
* Answered and cancelled surveys won't show up again.
714+
*
715+
* @param surveyToken A String with a survey token.
716+
*/
717+
public void showSurveyWithToken(String surveyToken) {
718+
Surveys.showSurvey(surveyToken);
719+
}
720+
721+
722+
/**
723+
* Returns true if the survey with a specific token was answered before.
724+
* Will return false if the token does not exist or if the survey was not answered before.
725+
*
726+
* @param surveyToken the attribute key as string
727+
* @return the desired value of whether the user has responded to the survey or not.
728+
*/
729+
public void hasRespondedToSurveyWithToken(String surveyToken) {
730+
boolean hasResponded;
731+
hasResponded = Surveys.hasRespondToSurvey(surveyToken);
732+
channel.invokeMethod("hasRespondedToSurveyCallback", hasResponded);
733+
}
734+
710735
}

example/lib/main.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class _MyAppState extends State<MyApp> {
3030
// Platform messages may fail, so we use a try/catch PlatformException.
3131
try {
3232
if (Platform.isIOS) {
33-
Instabug.start('9582e6cfe34e2b8897f48cfa3b617adb', <InvocationEvent>[InvocationEvent.shake]);
33+
Instabug.start('068ba9a8c3615035e163dc5f829c73be', <InvocationEvent>[InvocationEvent.shake]);
3434
}
3535
//Instabug.showWelcomeMessageWithMode(WelcomeMessageMode.beta);
3636
//Instabug.setWelcomeMessageMode(WelcomeMessageMode.beta);
@@ -115,16 +115,21 @@ class _MyAppState extends State<MyApp> {
115115
debugPrint('SDK Dismissed ReportType: ' + reportType.toString());
116116
}
117117

118+
void hasResponded(bool hasResponded) {
119+
debugPrint(hasResponded.toString());
120+
}
118121
void show() {
119122
//Instabug.show();
120-
Surveys.getAvailableSurveys(getSurveys);
121-
Surveys.showSurveyIfAvailable();
122-
Surveys.setShouldShowWelcomeScreen(true);
123+
// Surveys.getAvailableSurveys(getSurveys);
124+
// Surveys.showSurveyIfAvailable();
125+
// Surveys.setShouldShowWelcomeScreen(true);
126+
Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg");
123127
//BugReporting.showWithOptions(ReportType.bug, <InvocationOption>[InvocationOption.emailFieldHidden]);
124128
}
125129

126130
void invokeWithMode() {
127-
BugReporting.invokeWithMode(InvocationMode.bug, [InvocationOption.emailFieldHidden]);
131+
Surveys.hasRespondedToSurvey("BHJI1iaKYhr4CYHHcUAaTg", hasResponded);
132+
// BugReporting.invokeWithMode(InvocationMode.bug, [InvocationOption.emailFieldHidden]);
128133
}
129134

130135
void getTags() async {

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,30 @@ + (void)showSurveysIfAvailable {
590590
[IBGSurveys showSurveyIfAvailable];
591591
}
592592

593+
/**
594+
* Shows survey with a specific token.
595+
* Does nothing if there are no available surveys with that specific token.
596+
* Answered and cancelled surveys won't show up again.
597+
*
598+
* @param surveyToken A String with a survey token.
599+
*/
600+
+ (void)showSurveyWithToken:(NSString *)surveyToken {
601+
[IBGSurveys showSurveyWithToken:surveyToken];
602+
}
603+
604+
/**
605+
* Returns true if the survey with a specific token was answered before.
606+
* Will return false if the token does not exist or if the survey was not answered before.
607+
*
608+
* @param surveyToken the attribute key as string
609+
* @return the desired value of whether the user has responded to the survey or not.
610+
*/
611+
+ (void)hasRespondedToSurveyWithToken:(NSString *)surveyToken {
612+
bool hasResponded = [IBGSurveys hasRespondedToSurveyWithToken:surveyToken];
613+
NSNumber *boolNumber = [NSNumber numberWithBool:hasResponded];
614+
[channel invokeMethod:@"hasRespondedToSurveyCallback" arguments:boolNumber];
615+
}
616+
593617

594618
+ (NSDictionary *)constants {
595619
return @{

lib/Surveys.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Surveys {
99
static Function onShowCallback;
1010
static Function onDismissCallback;
1111
static Function availableSurveysCallback;
12+
static Function hasRespondedToSurveyCallback;
1213
static const MethodChannel _channel = MethodChannel('instabug_flutter');
1314

1415
static Future<String> get platformVersion async {
@@ -32,6 +33,9 @@ class Surveys {
3233
}
3334
availableSurveysCallback(params);
3435
return ;
36+
case 'hasRespondedToSurveyCallback':
37+
hasRespondedToSurveyCallback(call.arguments);
38+
return ;
3539
}
3640
}
3741
/// @summary Sets whether surveys are enabled or not.
@@ -97,4 +101,25 @@ class Surveys {
97101
static void showSurveyIfAvailable() async {
98102
await _channel.invokeMethod<Object>('showSurveysIfAvailable');
99103
}
104+
105+
/// Shows survey with a specific token.
106+
/// Does nothing if there are no available surveys with that specific token.
107+
/// Answered and cancelled surveys won't show up again.
108+
/// [surveyToken] - A String with a survey token.
109+
static void showSurvey(String surveyToken) async {
110+
final List<dynamic> params = <dynamic>[surveyToken];
111+
await _channel.invokeMethod<Object>('showSurveyWithToken:', params);
112+
}
113+
114+
/// Sets a block of code to be executed just before the SDK's UI is presented.
115+
/// This block is executed on the UI thread. Could be used for performing any
116+
/// UI changes after the survey's UI is dismissed.
117+
/// [function] A callback that gets executed after the survey's UI is dismissed.
118+
static void hasRespondedToSurvey(String surveyToken, Function function) async {
119+
_channel.setMethodCallHandler(_handleMethod);
120+
hasRespondedToSurveyCallback = function;
121+
final List<dynamic> params = <dynamic>[surveyToken];
122+
await _channel.invokeMethod<Object>('hasRespondedToSurveyWithToken:', params);
123+
}
124+
100125
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: instabug_flutter
2-
version: 0.0.3-alpha.1
2+
version: 0.0.4-alpha.1
33
description: >-
44
Instabug is an in-app feedback and bug reporting tool for mobile apps.
55
With just a simple shake, your users or beta testers can report bugs or

test/instabug_flutter_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,28 @@ test('startWithToken:invocationEvents: Test', () async {
510510
]);
511511
});
512512

513+
test('showSurveyWithToken Test', () async {
514+
String token = "token";
515+
final List<dynamic> args = <dynamic>[token];
516+
Surveys.showSurvey(token);
517+
expect(log, <Matcher>[
518+
isMethodCall('showSurveyWithToken:',
519+
arguments: args,
520+
)
521+
]);
522+
});
523+
524+
test('hasRespondedToSurvey Test', () async {
525+
String token = "token";
526+
final List<dynamic> args = <dynamic>[token];
527+
Surveys.hasRespondedToSurvey(token,()=> (){});
528+
expect(log, <Matcher>[
529+
isMethodCall('hasRespondedToSurveyWithToken:',
530+
arguments: args,
531+
)
532+
]);
533+
});
534+
513535
}
514536

515537

0 commit comments

Comments
 (0)