All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codota.service.client.requests.BoxRequest Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version
package com.codota.service.client.requests;

import com.codota.service.client.requests.base.GetRequest;
import com.codota.service.connector.ServiceConnector;
import com.codota.service.model.Snippet;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yahave on 21/12/2016.
 */
public class BoxRequest extends GetRequest> {

    private static final String BOX_SNIPPETS_ROUTE = "/api/user-snippets";

    public BoxRequest(ServiceConnector connector, String token) {
        super(connector,connector.getBase() + BOX_SNIPPETS_ROUTE, token, null);
    }

    @Override
    public List parse(String json) {
        List sr = new ArrayList();
        try {
            JsonParser parser = new JsonParser();
            JsonArray root = parser.parse(json).getAsJsonArray();
            for (JsonElement elem : root) {
                Snippet snip = gson.fromJson(elem, Snippet.class);
                sr.add(snip);
            }
        } catch (IllegalStateException e) {
            System.err.println("json" + json);
            e.printStackTrace();
        } catch (com.google.gson.JsonSyntaxException e) {
            System.err.println("json" + json);
            e.printStackTrace();
        }
        return sr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy