Ejemplo n.º 1
0
  public ArrayList<SVNTicket> getIssues(String user, String project) {
    ArrayList<SVNTicket> issues = new ArrayList<>();
    Requests requests = new Requests();
    URLBuilder urlbuilder = Guice.createInjector(new HttpModule()).getInstance(URLBuilder.class);
    String searchUrl =
        urlbuilder.uses(SVNAPI.ROOT).withSimpleParam("/", project).withParam("/bugs").sbuild();
    try {
      String jsonString = requests.get(searchUrl);
      JsonObject ticketObject = new JsonParser().parse(jsonString).getAsJsonObject();

      JsonArray jsonArray = ticketObject.get("tickets").getAsJsonArray();

      for (JsonElement element : jsonArray) {
        String ticket_num = element.getAsJsonObject().get("ticket_num").getAsString();
        SVNTicket issue = new SVNTicket(ticket_num);
        URLBuilder builder = Guice.createInjector(new HttpModule()).getInstance(URLBuilder.class);
        String bugUrl = builder.withParam(searchUrl).withSimpleParam("/", ticket_num).sbuild();
        String bugString = requests.get(bugUrl);
        JsonObject jObj = new JsonParser().parse(bugString).getAsJsonObject();

        JsonElement ticket = jObj.get("ticket").getAsJsonObject();

        issue.setSummary(ticket.getAsJsonObject().get("summary").getAsString());
        issue.setDescription(ticket.getAsJsonObject().get("description").getAsString());

        String status = ticket.getAsJsonObject().get("status").getAsString();
        String assigned_to_id = null;
        if (!ticket.getAsJsonObject().get("assigned_to_id").isJsonNull())
          assigned_to_id = ticket.getAsJsonObject().get("assigned_to_id").getAsString();

        issues.add(issue);
      }

    } catch (com.google.gson.JsonSyntaxException e) {
      e.printStackTrace();
    }
    return issues;
  }
Ejemplo n.º 2
0
  public List<Recipe> getSearchList(int page) {
    List<Recipe> list = new ArrayList<>();
    Recipe recipe;
    URL url = null;
    try {
      url = new URL(builder.getSearchURL(page, ingredients, sort));
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    String recipeJsonData = getRecipeJsonData(url);

    // These are the names of the JSON objects that need to be extracted.
    final String OWM_LIST = "recipes";
    final String OWM_PUBLISHER = "publisher";
    final String OWM_TITLE = "title";
    final String OWM_SOURCE_URL = "source_url";
    final String OWM_RECIPE_ID = "recipe_id";
    final String OWM_IMAGE_URL = "image_url";
    final String OWM_SOCIAL_RANK = "social_rank";
    final String OWM_PUBLISHER_URL = "publisher_url";

    JSONObject jsonObject = null;

    try {
      jsonObject = new JSONObject(recipeJsonData);

      JSONArray recipesArray = jsonObject.getJSONArray(OWM_LIST);

      for (int i = 0; i < recipesArray.length(); i++) {
        recipe = new Recipe();

        JSONObject recipeObj = (JSONObject) recipesArray.get(i);
        recipe.setPublisher(recipeObj.getString(OWM_PUBLISHER));
        recipe.setTitle(recipeObj.getString(OWM_TITLE));
        recipe.setSource_url(recipeObj.getString(OWM_SOURCE_URL));
        recipe.setRecipe_id(recipeObj.getString(OWM_RECIPE_ID));
        recipe.setImage_url(recipeObj.getString(OWM_IMAGE_URL));
        recipe.setSocial_rank(recipeObj.getString(OWM_SOCIAL_RANK));
        recipe.setPublisher_url(recipeObj.getString(OWM_PUBLISHER_URL));
        list.add(recipe);
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return list;
  }
Ejemplo n.º 3
0
  public Recipe getRecipe(String rId) {
    Recipe recipe;
    String recipeJsonData;
    URL url = null;
    try {
      url = new URL(builder.getGET_URL(rId));
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    recipeJsonData = getRecipeJsonData(url);
    final String OWM_LIST = "recipe";
    final String OWM_PUBLISHER = "publisher";
    final String OWM_TITLE = "title";
    final String OWM_SOURCE_URL = "source_url";
    final String OWM_RECIPE_ID = "recipe_id";
    final String OWM_IMAGE_URL = "image_url";
    final String OWM_SOCIAL_RANK = "social_rank";
    final String OWM_PUBLISHER_URL = "publisher_url";
    final String OWM_INGREDIENTS = "ingredients";

    JSONObject jsonObject = null;
    recipe = new Recipe();
    try {
      jsonObject = new JSONObject(recipeJsonData);
      JSONObject recipeObj = (JSONObject) jsonObject.getJSONObject(OWM_LIST);

      recipe.setPublisher(recipeObj.getString(OWM_PUBLISHER));
      recipe.setTitle(recipeObj.getString(OWM_TITLE));
      recipe.setSource_url(recipeObj.getString(OWM_SOURCE_URL));
      recipe.setRecipe_id(recipeObj.getString(OWM_RECIPE_ID));
      recipe.setImage_url(recipeObj.getString(OWM_IMAGE_URL));
      recipe.setSocial_rank(recipeObj.getString(OWM_SOCIAL_RANK));
      recipe.setPublisher_url(recipeObj.getString(OWM_PUBLISHER_URL));
      recipe.setIngredients(recipeObj.getString(OWM_INGREDIENTS));

    } catch (JSONException e) {
      e.printStackTrace();
    }
    return recipe;
  }
Ejemplo n.º 4
0
  @Test
  public void urls() throws IOException {
    String host = URLBuilder.builder("localhost").build();
    String paths = URLBuilder.builder("localhost").addPath("hello/world").build();
    String path = URLBuilder.builder("localhost").addPath(123).addPath("smith").addPath().build();
    String query =
        URLBuilder.builder("localhost").addQuery("hello").addQuery("key", "123456789").build();
    String queryPath =
        URLBuilder.builder("localhost").addPath("hello").addQuery("key", 123456789).build();
    String fromURL =
        URLBuilder.fromURL("http://localhost/jhon/smith?fname=bobby&lname=bob").build();

    Assert.assertEquals(host, "http://localhost/");
    Assert.assertEquals(paths, "http://localhost/hello/world");
    Assert.assertEquals(path, "http://localhost/123/smith/");
    Assert.assertEquals(query, "http://localhost/?hello=&key=123456789");
    Assert.assertEquals(queryPath, "http://localhost/hello?key=123456789");
    Assert.assertEquals(fromURL, "http://localhost/jhon/smith?fname=bobby&lname=bob");
  }