Skip to content

Instantly share code, notes, and snippets.

@felangel
Created January 21, 2019 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felangel/675d156c0513cb57fdb584048a291dbf to your computer and use it in GitHub Desktop.
Save felangel/675d156c0513cb57fdb584048a291dbf to your computer and use it in GitHub Desktop.
[github_search] Github Client
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:common_github_search/common_github_search.dart';
class GithubClient {
final String baseUrl;
final http.Client httpClient;
GithubClient({
http.Client httpClient,
this.baseUrl = "https://api.github.com/search/repositories?q=",
}) : this.httpClient = httpClient ?? http.Client();
Future<SearchResult> search(String term) async {
final response = await httpClient.get(Uri.parse("$baseUrl$term"));
final results = json.decode(response.body);
if (response.statusCode == 200) {
return SearchResult.fromJson(results);
} else {
throw SearchResultError.fromJson(results);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment