Remove services requiring HTML parsing
Not exposed via a regular API - likely fragile
MODIFY
lib/src/common.dart
lib/src/common.dart
@@ -6,8 +6,6 @@ import "dart:async";
import "dart:convert"
show base64Decode, base64Encode, jsonEncode, jsonDecode, LineSplitter, utf8;
-import "package:html/dom.dart" as html;
-import "package:html/parser.dart" as html_parser;
import "package:http/http.dart" as http;
import 'package:http_parser/http_parser.dart' as http_parser;
import "package:json_annotation/json_annotation.dart";
@@ -24,7 +22,6 @@ part "common.g.dart";
part "common/activity_service.dart";
part "common/authorizations_service.dart";
part "common/blog_service.dart";
-part "common/explore_service.dart";
part "common/gists_service.dart";
part "common/git_service.dart";
part "common/github.dart";
@@ -33,7 +30,6 @@ part "common/misc_service.dart";
part "common/model/activity.dart";
part "common/model/authorizations.dart";
part "common/model/blog.dart";
-part "common/model/explore.dart";
part "common/model/gists.dart";
part "common/model/git.dart";
part "common/model/issues.dart";

DELETE
lib/src/common/explore_service.dart
-part of github.common;
-
-/// The [ExploreService] provides methods for exploring GitHub.
-///
-/// API docs: https://github.com/explore
-class ExploreService extends Service {
- ExploreService(GitHub github) : super(github);
-
- Stream<TrendingRepository> listTrendingRepositories(
- {String language, String since: "daily"}) {
- var url = "https://github.com/trending";
-
- if (language != null) url += "?l=$language";
-
- if (since != null)
- url += language == null ? "?since=$since" : "&since=$since";
-
- var controller = new StreamController<TrendingRepository>();
-
- _github.client.get(url).then((response) {
- var doc = html_parser.parse(response.body);
- var items = doc.querySelectorAll(
- "li.repo-leaderboard-list-item.leaderboard-list-item");
-
- for (var item in items) {
- var repo = new TrendingRepository();
- repo.rank = item.querySelector("a.leaderboard-list-rank").text;
- repo.titleObject =
- item.querySelector("h2.repo-leaderboard-title").querySelector("a");
- var desc = item.querySelector("p.repo-leaderboard-description");
-
- if (desc == null) {
- repo.description = "No Description";
- } else {
- repo.description = desc.text;
- }
-
- controller.add(repo);
- }
-
- controller.close();
- });
-
- return controller.stream;
- }
-
- Future<Showcase> getShowcase(ShowcaseInfo info) {
- var completer = new Completer<Showcase>();
-
- _github.client.get(info.url).then((response) {
- var doc = html_parser.parse(response.body);
- var showcase = new Showcase();
-
- var title = doc.querySelector(".collection-header").text;
- var lastUpdated = parseDateTime(doc
- .querySelector(".meta-info.last-updated")
- .querySelector("time")
- .attributes['datetime']);
- var page = doc.querySelector(".collection-page");
-
- var description = page.querySelector(".collection-description");
-
- // TODO: This is most likely wrong
- showcase.description = description.text;
- showcase.lastUpdated = lastUpdated;
- showcase.title = title;
- showcase.items = [];
-
- var repos = page.querySelectorAll(".collection-repo");
-
- for (var repo in repos) {
- var repoTitle = repo.querySelector(".collection-repo-title");
- var path = repoTitle.querySelector("a").attributes['href'];
- var url = "https://githb.com$path";
- var name = path.substring(1);
-
- var item = new ShowcaseItem();
-
- item.name = name;
-
- item.url = url;
-
- showcase.items.add(item);
- }
-
- completer.complete(showcase);
- });
-
- return completer.future;
- }
-
- Stream<ShowcaseInfo> listShowcases() {
- var controller = new StreamController<ShowcaseInfo>();
-
- Function handleResponse;
-
- handleResponse = (response) {
- var doc = html_parser.parse(response.body);
-
- var cards = doc.querySelectorAll(".collection-card");
-
- for (var card in cards) {
- var title = card.querySelector(".collection-card-title").text;
- var description = card.querySelector(".collection-card-body").text;
- var img = card.querySelector(".collection-card-image");
- var url = "https://github.com" + img.attributes['href'];
-
- var showcase = new ShowcaseInfo();
-
- showcase
- ..title = title
- ..description = description
- ..url = url;
-
- controller.add(showcase);
- }
-
- var pag = doc.querySelector(".pagination");
-
- var links = pag.querySelectorAll("a");
-
- bool didFetchMore = false;
-
- for (var link in links) {
- if (link.text.contains("Next")) {
- didFetchMore = true;
-
- var client = new http.Client();
-
- client.get(link.attributes['href']).then(handleResponse);
- }
- }
-
- if (!didFetchMore) {
- controller.close();
- }
- };
-
- _github.client.get("https://github.com/showcases").then(handleResponse);
-
- return controller.stream;
- }
-}

MODIFY
lib/src/common/github.dart
lib/src/common/github.dart
@@ -26,7 +26,6 @@ class GitHub {
ActivityService _activity;
AuthorizationsService _authorizations;
BlogService _blog;
- ExploreService _explore;
GistsService _gists;
GitService _git;
IssuesService _issues;
@@ -103,14 +102,6 @@ class GitHub {
return _blog;
}
- /// Service to explore GitHub.
- ExploreService get explore {
- if (_explore == null) {
- _explore = new ExploreService(this);
- }
- return _explore;
- }
-
/// Service for gist related methods of the GitHub API.
GistsService get gists {
if (_gists == null) {

MODIFY
lib/src/common/misc_service.dart
lib/src/common/misc_service.dart
@@ -65,39 +65,6 @@ class MiscService extends Service {
_github.getJSON("https://status.github.com/api/status.json",
statusCode: StatusCodes.OK, convert: APIStatus.fromJSON);
- /// Returns a stream of Octocats from Octodex.
- ///
- /// See: https://octodex.github.com/
- Stream<Octocat> listOctodex({bool cors: false}) {
- var controller = new StreamController<Octocat>();
-
- var u = "http://feeds.feedburner.com/Octocats.xml";
-
- _github.client
- .get(
- "${cors ? "http://whateverorigin.org/get?url=" : ""}${cors ? Uri.encodeComponent(u) : u}")
- .then((response) {
- var document = html_parser.parse(response.body);
- document.querySelectorAll("entry").forEach((entry) {
- var name = entry.querySelector("title").text;
- var c = "<html><body>" +
- entry.querySelector("content").innerHtml +
- "</body></html>";
- var content = html_parser.parse(c);
- var image = content.querySelector("a img").attributes['src'];
- var url = entry.querySelector("link").attributes['href'];
-
- controller.add(new Octocat()
- ..image = image
- ..name = name
- ..url = url);
- });
- return controller.close();
- });
-
- return controller.stream;
- }
-
/// Returns an ASCII Octocat with the specified [text].
Future<String> getOctocat([String text]) {
var params = <String, String>{};

DELETE
lib/src/common/model/explore.dart
-part of github.common;
-
-class TrendingRepository {
- String rank;
- html.Element titleObject;
- String get title => titleObject.text;
-
- String get url => "https://github.com/$title";
- String description;
-}
-
-class ShowcaseInfo {
- String title;
- String description;
- String url;
-}
-
-class Showcase extends ShowcaseInfo {
- DateTime lastUpdated;
- List<ShowcaseItem> items;
-}
-
-class ShowcaseItem {
- String name;
- String url;
-}

MODIFY
pubspec.yaml
pubspec.yaml
@@ -6,7 +6,6 @@ homepage: https://github.com/DirectMyFile/github.dart
environment:
sdk: '>=2.0.0-dev.36 <3.0.0'
dependencies:
- html: '>=0.12.0 <0.14.0'
http: '>=0.11.3 <0.13.0'
http_parser: ^3.1.1
json_annotation: ^1.1.0

DELETE
test/experiment/showcases.dart
-import "package:github/server.dart";
-
-void main() {
- var github = createGitHubClient();
-
- github.explore.listShowcases().listen((info) {
- print("- ${info.title}");
- }).onDone(() => github.dispose());
-}

DELETE
test/experiment/trending.dart
-import "package:github/server.dart";
-
-void main() {
- var github = createGitHubClient();
-
- github.explore
- .listTrendingRepositories(language: "Dart", since: "month")
- .listen((repo) => print("${repo.title}: ${repo.description}"));
-}

Remove services requiring HTML parsing

Not exposed via a regular API - likely fragile