// Path: src/main/java/ch/cyclops/publish/ParseQueryResult.java
// public class ParseQueryResult {
// 
// 
//     public static List map(List<Map> list, Class clazz) {
//         List<Object> mapped = new ArrayList<>();
// 
//         // iterate and map those objects
//         if (list != null) {
//             for (Map map : list) {
//                 try {
//                     Object bean = clazz.newInstance();
// 
//                     // map HashMap to POJO
//                     BeanUtils.populate(bean, map);
// 
//                     // add it to list of mapped CDRs
//                     mapped.add(bean);
// 
//                 } catch (Exception ignored) {
//                     return null;
//                 }
//             }
//         }
// 
//         return mapped;
//     }
// }


import ch.cyclops.publish.ParseQueryResult;
import com.google.gson.Gson;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import java.net.URL;
import java.util.List;
import java.util.Map;
package ch.cyclops.publish;
/*
 * Copyright (c) 2016. Zuercher Hochschule fuer Angewandte Wissenschaften
 *  All Rights Reserved.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License"); you may
 *     not use this file except in compliance with the License. You may obtain
 *     a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *     License for the specific language governing permissions and limitations
 *     under the License.
 */



/**
 * Author: Skoviera
 * Created: 29/07/16
 * Description: Call API endpoint
 */
public class APICaller {

    public class Response {
        private String object;

        public Response(String obj) {
            object = obj;
        }

        public String getAsString() throws Exception {
            return object;
        }

        public List getAsList() throws Exception {
            return new Gson().fromJson(object, List.class);
        }

        public Map getAsMap() throws Exception {
            return new Gson().fromJson(object, Map.class);
        }

        public Object getAsClass(Class clazz) throws Exception {
            return new Gson().fromJson(object, clazz);
        }

        public List getAsListOfType(Class clazz) throws Exception {
            List<Map> list = new Gson().fromJson(object, List.class);
// Path: src/main/java/ch/cyclops/publish/ParseQueryResult.java
// public class ParseQueryResult {
// 
// 
//     public static List map(List<Map> list, Class clazz) {
//         List<Object> mapped = new ArrayList<>();
// 
//         // iterate and map those objects
//         if (list != null) {
//             for (Map map : list) {
//                 try {
//                     Object bean = clazz.newInstance();
// 
//                     // map HashMap to POJO
//                     BeanUtils.populate(bean, map);
// 
//                     // add it to list of mapped CDRs
//                     mapped.add(bean);
// 
//                 } catch (Exception ignored) {
//                     return null;
//                 }
//             }
//         }
// 
//         return mapped;
//     }
// }


// Path: src/main/java/ch/cyclops/publish/APICaller.java
import ch.cyclops.publish.ParseQueryResult;
import com.google.gson.Gson;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import java.net.URL;
import java.util.List;
import java.util.Map;

package ch.cyclops.publish;
/*
 * Copyright (c) 2016. Zuercher Hochschule fuer Angewandte Wissenschaften
 *  All Rights Reserved.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License"); you may
 *     not use this file except in compliance with the License. You may obtain
 *     a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *     License for the specific language governing permissions and limitations
 *     under the License.
 */



/**
 * Author: Skoviera
 * Created: 29/07/16
 * Description: Call API endpoint
 */
public class APICaller {

    public class Response {
        private String object;

        public Response(String obj) {
            object = obj;
        }

        public String getAsString() throws Exception {
            return object;
        }

        public List getAsList() throws Exception {
            return new Gson().fromJson(object, List.class);
        }

        public Map getAsMap() throws Exception {
            return new Gson().fromJson(object, Map.class);
        }

        public Object getAsClass(Class clazz) throws Exception {
            return new Gson().fromJson(object, clazz);
        }

        public List getAsListOfType(Class clazz) throws Exception {
            List<Map> list = new Gson().fromJson(object, List.class);
            return ParseQueryResult.map(list, clazz);