-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.dart
52 lines (37 loc) · 1.23 KB
/
Parser.dart
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
class Parser {
final String baseUrl = "http://api.dartlang.org/";
String _json;
Request _request;
Parser(){
}
set reaquest(Request request) => this._request = request;
Future<List<String>> getUrlsStartingWith(String searchedString){
Completer resultComplete = new Completer();
Future<String> future = _request.makeRequest();
future.then((jsonFuture){
_json = jsonFuture;
List<Result> r = _parseStartWith(searchedString);
List<String> url = new List();
r.forEach((result){
url.add(result.toString());
});
resultComplete.complete(url);
});
return resultComplete.future;
}
List<Result> _parseStartWith(String name){
Map<String, Object> parsedJson = JSON.parse(_json);
List<Result> results = new List<Result>();
var packagesKeys = parsedJson.getKeys();
packagesKeys.forEach((k){
var packageValues = parsedJson[k];
packageValues.forEach((v){
if(v["name"].toUpperCase().startsWith(name.toUpperCase())){
Result result = new Result(v["name"],v["kind"],baseUrl + v["url"]);
results.add(result);
}
});
});
return results;
}
}