Search in sources :

Example 1 with JsonResponse

use of com.jcabi.http.response.JsonResponse in project jcabi-github by jcabi.

the class RtUser method notifications.

@Override
public List<Notification> notifications() throws IOException {
    final List<Notification> list = new LinkedList<Notification>();
    final JsonResponse resp = this.github().entry().uri().path("notifications").back().fetch().as(JsonResponse.class);
    final JsonArray array = resp.json().readArray();
    for (final JsonValue value : array) {
        final JsonObject notif = (JsonObject) value;
        list.add(this.createNotification(notif));
    }
    return list;
}
Also used : JsonArray(javax.json.JsonArray) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) LinkedList(java.util.LinkedList) JsonResponse(com.jcabi.http.response.JsonResponse)

Example 2 with JsonResponse

use of com.jcabi.http.response.JsonResponse in project jcabi-github by jcabi.

the class Main method main.

/**
 * Main entry point.
 * @param args Command line arguments
 */
public static void main(final String[] args) throws Exception {
    final Github github = new RtGithub();
    final JsonResponse resp = github.entry().uri().path("/search/repositories").queryParam("q", "java").back().fetch().as(JsonResponse.class);
    final List<JsonObject> items = resp.json().readObject().getJsonArray("items").getValuesAs(JsonObject.class);
    for (final JsonObject item : items) {
        System.out.println(String.format("repository found: %s", item.get("full_name").toString()));
    }
}
Also used : RtGithub(com.jcabi.github.RtGithub) Github(com.jcabi.github.Github) JsonObject(javax.json.JsonObject) RtGithub(com.jcabi.github.RtGithub) JsonResponse(com.jcabi.http.response.JsonResponse)

Example 3 with JsonResponse

use of com.jcabi.http.response.JsonResponse in project jcabi-github by jcabi.

the class RtSearchTest method readNonUnicode.

/**
 * RtSearch can read non-unicode.
 * @throws Exception if any problem inside
 */
@Test
public void readNonUnicode() throws Exception {
    final Response resp = new FakeRequest().withBody("{\"help\": \"\u001Fblah\u0001cwhoa\u0000!\"}").fetch();
    final JsonResponse response = new JsonResponse(resp);
    MatcherAssert.assertThat(response.json().readObject().getString("help"), Matchers.is("\u001Fblah\u0001cwhoa\u0000!"));
}
Also used : Response(com.jcabi.http.Response) JsonResponse(com.jcabi.http.response.JsonResponse) JsonResponse(com.jcabi.http.response.JsonResponse) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Aggregations

JsonResponse (com.jcabi.http.response.JsonResponse)3 JsonObject (javax.json.JsonObject)2 Github (com.jcabi.github.Github)1 RtGithub (com.jcabi.github.RtGithub)1 Response (com.jcabi.http.Response)1 FakeRequest (com.jcabi.http.request.FakeRequest)1 LinkedList (java.util.LinkedList)1 JsonArray (javax.json.JsonArray)1 JsonValue (javax.json.JsonValue)1 Test (org.junit.Test)1