Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: samples/dartiverse_search/lib/stack_overflow_search_engine.dart

Issue 752303004: Delete dartiverse-search from the repo and update dart:io documentation to point (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of search_engine;
6
7
8 class StackOverflowSearchEngine implements SearchEngine {
9 String get name => 'StackOverflow';
10
11 Stream<SearchResult> search(String input) {
12 var query = {
13 'site': 'stackoverflow',
14 'tagged': 'dart',
15 'intitle': input,
16 'sort': 'relevance',
17 'order': 'desc',
18 'pagesize': '3'
19 };
20 var searchUri = new Uri.http(
21 'api.stackexchange.com',
22 '/2.1/search',
23 query);
24 var controller = new StreamController();
25 http_client.get(searchUri)
26 .then((http_client.Response response) {
27 if (response.statusCode != HttpStatus.OK) {
28 throw "Bad status code: ${response.statusCode}, "
29 "message: ${response.reasonPhrase}";
30 }
31 var json = JSON.decode(response.body);
32 json.putIfAbsent('items', () => []);
33 json['items'].take(3).forEach((item) {
34 controller.add(new SearchResult(
35 item['title'], item['link']));
36 });
37 })
38 .catchError(controller.addError)
39 .whenComplete(controller.close);
40 return controller.stream;
41 }
42 }
OLDNEW
« no previous file with comments | « samples/dartiverse_search/lib/search_engine.dart ('k') | samples/dartiverse_search/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698