@@ -0,0 +1,2098 @@
+package com.falydoor.limesurveyrest;%0A%0Aimport com.falydoor.limesurveyrest.dto.*;%0Aimport com.falydoor.limesurveyrest.exception.LimesurveyRestException;%0Aimport com.google.gson.*;%0Aimport org.apache.http.HttpResponse;%0Aimport org.apache.http.client.methods.HttpPost;%0Aimport org.apache.http.entity.StringEntity;%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0Aimport org.apache.http.impl.client.HttpClientBuilder;%0Aimport org.apache.http.util.EntityUtils;%0A%0Aimport java.io.IOException;%0Aimport java.time.ZonedDateTime;%0Aimport java.util.Comparator;%0Aimport java.util.stream.Stream;%0Aimport java.util.stream.StreamSupport;%0A%0Apublic class LimesurveyRest %7B%0A%0A    private String url;%0A%0A    private String user;%0A%0A    private String password;%0A%0A    private int keyTimeout = 7200;%0A%0A    private String key = %22%22;%0A%0A    private ZonedDateTime keyExpiration = ZonedDateTime.now();%0A%0A    public LimesurveyRest(String url, String user, String password) %7B%0A        this.url = url;%0A        this.user = user;%0A        this.password = password;%0A    %7D%0A%0A    public void setKeyTimeout(int timeout) %7B%0A        keyTimeout = timeout;%0A    %7D%0A%0A    public JsonElement callApi(LimesurveyApiBody limesurveyApiBody) throws LimesurveyRestException %7B%0A        try (CloseableHttpClient client = HttpClientBuilder.create().build()) %7B%0A            HttpPost post = new HttpPost(url);%0A            post.setHeader(%22Content-type%22, %22application/json%22);%0A            post.setEntity(new StringEntity(new Gson().toJson(limesurveyApiBody)));%0A            HttpResponse response = client.execute(post);%0A            if (response.getStatusLine().getStatusCode() == 200) %7B%0A                String result = EntityUtils.toString(response.getEntity());%0A                return new JsonParser().parse(result).getAsJsonObject().get(%22result%22);%0A            %7D else %7B%0A                throw new LimesurveyRestException(%22Expecting status code 200, got %22 + response.getStatusLine().getStatusCode() + %22 instead%22);%0A            %7D%0A        %7D catch (IOException e) %7B%0A            throw new LimesurveyRestException(%22Exception while calling API : %22 + e.getMessage(), e);%0A        %7D%0A    %7D%0A%0A%7D%0A

Call API method