Skip to content

Commit

Permalink
Improving documentation of the SearchGitHub class and working on fetc…
Browse files Browse the repository at this point in the history
…hing more interesting data from the Google Code forge. Successfully could grab one more property: watchers count. Related to #20 and #14.
  • Loading branch information
Rodrigo Alves Vieira committed May 3, 2013
1 parent b44a402 commit 1b47cf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import com.google.inject.Inject;

/**
* Responsible for searching projects on GitHub via its official API
* Performs the project search on GitHub, via its official JSON API
* @author fjsj, gustavopinto, rodrigoalvesvieira
*
*/
public class SearchGitHub implements ForgeSearch {
private static String root = "https://api.github.com";
Expand All @@ -31,6 +30,13 @@ public SearchGitHub(Requests requests) {
this.requests = requests;
}

/**
*
* @param urlStr the URL of the JSON document
* @return a JSON object created filled with the content of the given JSON document
* @throws IOException
* @throws JSONException
*/
private JSONObject getJsonFromAPI(String urlStr) throws IOException, JSONException {
return new JSONObject(requests.get(urlStr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ public List<Project> getProjects(String term, int page) throws SearchException {
for (Element tr : doc.select("#serp table tbody tr")) {
Element el = tr.child(0).child(0);

// The span element within the main search result that contains the number
// of people watching the project on Google Code
Element span = tr.child(1).child(2).child(0);

String projectName, description, imgSrc, iconURL, sourceCodeUrl;
int stars;

projectName = el.attr("href").split("/")[2];
description = tr.child(1).ownText();
imgSrc = el.child(0).attr("src");
iconURL = imgSrc;
stars = Integer.parseInt(span.text());

if (imgSrc.startsWith("/")) {
iconURL = root + iconURL;
Expand All @@ -101,6 +107,8 @@ public List<Project> getProjects(String term, int page) throws SearchException {
sourceCodeUrl = "https://code.google.com/p/" + projectName + "/source/browse/";

Project forgeProject = new Project(projectName, description, iconURL, sourceCodeUrl);
forgeProject.setWatchersCount(stars);
forgeProject.setFollowersCount(stars);
projects.add(forgeProject);
}

Expand Down

0 comments on commit 1b47cf6

Please sign in to comment.