예제 #1
0
  public static String[] findSimilar(String idToGetRelated) {
    String IDofRelated = "";
    OkHttpClient client = new OkHttpClient();

    Request request =
        new Request.Builder()
            .url(
                "https://hackingedu.chegg.com/hacking-edu/catalog/relateditem/priced/getRelatedItems?catalogItemId="
                    + idToGetRelated)
            .get()
            .addHeader("accept", "application/json")
            .addHeader("content-type", "application/json")
            .addHeader(
                "authorization",
                "Basic TXlPYUhWOUFtN01QdmxuSmJVVVV2SXZyaVBnYmVlQUE6MG1zQVFWbk1wemNS MXNjNA==")
            .addHeader("cache-control", "no-cache")
            // .addHeader("postman-token", "2b21d3c9-023b-519e-4681-a7e20281879e")
            .build();

    Response response = null;

    try {
      response = client.newCall(request).execute();
      // System.out.println(response.toString());
    } catch (Exception e) {
      System.out.println(e);
    }
    String myResponse = "";
    try {
      myResponse = response.body().string();
    } catch (Exception e) {
      System.out.println(e);
    }
    // System.out.println("MY RESPONSE " + myResponse);

    /*JSONObject jObject = new JSONObject(new String(myResponse));
    JSONArray jArray = jObject.getJSONArray("result");*/

    Object obj = JSONValue.parse(myResponse);
    JSONArray array = (JSONArray) obj;
    // System.out.println("ARRAY: " + array.toString());
    String[] IDlist = new String[array.size()];
    for (int i = 0; i < array.size(); i++) {
      IDlist[i] = (String) ((JSONObject) array.get(i)).get("catalogItemIdTo");
    }
    // IDofRelated = myResponse;

    // String [] IDlist = new String [response.result.length];
    //   for(int i=0; i<response.result.length; i++){
    //     IDlist [i] = response.result[i].responseContent.docs[0].id;
    //   }
    return IDlist;
  }
예제 #2
0
  public static String IDtoName(String idToBeConverted) {
    String textBookTitle = "";

    OkHttpClient client = new OkHttpClient();

    Request request =
        new Request.Builder()
            .url("http://hackingedu.chegg.com/hacking-edu/catalog/priced/byId/" + idToBeConverted)
            .get()
            .addHeader("accept", "application/json")
            .addHeader("content-type", "application/json")
            .addHeader(
                "authorization",
                "Basic TXlPYUhWOUFtN01QdmxuSmJVVVV2SXZyaVBnYmVlQUE6MG1zQVFWbk1wemNS MXNjNA==")
            .addHeader("cache-control", "no-cache")
            .addHeader("postman-token", "1cfc968c-0021-3d99-4dc7-e674d33db19c")
            .build();

    // Response response = client.newCall(request).execute();

    Response response = null;

    try {
      response = client.newCall(request).execute();
      // System.out.println(response.toString());
    } catch (Exception e) {
      System.out.println(e);
    }
    String myResponse = "";
    try {
      myResponse = response.body().string();
    } catch (Exception e) {
      System.out.println(e);
    }
    // System.out.println("MY RESPONSE " + myResponse);
    Object obj = JSONValue.parse(myResponse);
    JSONObject object = (JSONObject) obj;
    // System.out.println("IDtoText: " + object.toString());
    textBookTitle = (String) (object.get("title"));

    // textBookTitle = response.title;
    return textBookTitle;
  }