forked from flutter/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_survey_api.dart
More file actions
102 lines (91 loc) · 3.3 KB
/
_survey_api.dart
File metadata and controls
102 lines (91 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2020 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
part of 'server.dart';
/// Set DevTools parameter value for the active survey (e.g. 'Q1-2020').
///
/// The value is stored in the file '~/.flutter-devtools/.devtools'.
///
/// This method must be called before calling other survey related methods
/// ([surveyActionTaken], [setSurveyActionTaken], [surveyShownCount],
/// [incrementSurveyShownCount]). If the active survey is not set, warnings are
/// logged.
Future<bool> setActiveSurvey(String value) async {
if (isDevToolsServerAvailable) {
final resp = await request(
'${SurveyApi.setActiveSurvey}'
'?$apiParameterValueKey=$value',
);
if ((resp?.statusOk ?? false) && json.decode(resp!.body)) {
return true;
} else {
logWarning(resp, SurveyApi.setActiveSurvey);
}
}
return false;
}
/// Request DevTools property value 'surveyActionTaken' for the active survey.
///
/// The value is stored in the file '~/.flutter-devtools/.devtools'.
///
/// Requires [setActiveSurvey] to have been called prior to calling this method.
Future<bool> surveyActionTaken() async {
bool surveyActionTaken = false;
if (isDevToolsServerAvailable) {
final resp = await request(SurveyApi.getSurveyActionTaken);
if (resp?.statusOk ?? false) {
surveyActionTaken = json.decode(resp!.body);
} else {
logWarning(resp, SurveyApi.getSurveyActionTaken);
}
}
return surveyActionTaken;
}
/// Set DevTools property value 'surveyActionTaken' for the active survey.
///
/// The value is stored in the file '~/.flutter-devtools/.devtools'.
///
/// Requires [setActiveSurvey] to have been called prior to calling this method.
Future<void> setSurveyActionTaken() async {
if (isDevToolsServerAvailable) {
final resp = await request(SurveyApi.setSurveyActionTaken);
if (resp == null || !resp.statusOk || !(json.decode(resp.body) as bool)) {
logWarning(resp, SurveyApi.setSurveyActionTaken);
}
}
}
/// Request DevTools property value 'surveyShownCount' for the active survey.
///
/// The value is stored in the file '~/.flutter-devtools/.devtools'.
///
/// Requires [setActiveSurvey] to have been called prior to calling this method.
Future<int> surveyShownCount() async {
int surveyShownCount = 0;
if (isDevToolsServerAvailable) {
final resp = await request(SurveyApi.getSurveyShownCount);
if (resp?.statusOk ?? false) {
surveyShownCount = json.decode(resp!.body);
} else {
logWarning(resp, SurveyApi.getSurveyShownCount);
}
}
return surveyShownCount;
}
/// Increment DevTools property value 'surveyShownCount' for the active survey.
///
/// The value is stored in the file '~/.flutter-devtools/.devtools'.
///
/// Requires [setActiveSurvey] to have been called prior to calling this method.
Future<int> incrementSurveyShownCount() async {
// Any failure will still return 0.
int surveyShownCount = 0;
if (isDevToolsServerAvailable) {
final resp = await request(SurveyApi.incrementSurveyShownCount);
if (resp?.statusOk ?? false) {
surveyShownCount = json.decode(resp!.body);
} else {
logWarning(resp, SurveyApi.incrementSurveyShownCount);
}
}
return surveyShownCount;
}