package com.kodcu.rapid.util;

import org.eclipse.jetty.http.MimeTypes;

import javax.json.JsonStructure;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.concurrent.ExecutionException;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;

/**
 * Created by hakan on 07/01/2017.
 */
public final class Networking {

    private Networking() {
    }

    public static Response getResponse(WebTarget target) {
        return target.request(String.valueOf(MimeTypes.Type.APPLICATION_JSON_UTF_8)).get();
    }

    public static Response postResponse(WebTarget target, JsonStructure content) {
        return target.request(String.valueOf(MimeTypes.Type.APPLICATION_JSON_UTF_8)).post(Entity.entity(content, MediaType.APPLICATION_JSON));
    }

    public static Response postResponse(WebTarget target, String content) {
        return target.request(String.valueOf(MimeTypes.Type.APPLICATION_JSON_UTF_8)).post(Entity.entity(content, MediaType.APPLICATION_JSON));
    }

    public static Response postResponse(WebTarget target) {
        return target.request(String.valueOf(MimeTypes.Type.APPLICATION_JSON_UTF_8)).method("POST");
    }

    public static Response deleteResponse(WebTarget target){
        return target.request().delete();
    }

    public static Response getAsycResponse(WebTarget target) throws ExecutionException, InterruptedException {
        return target.request(APPLICATION_JSON_TYPE).async().get().get();
    }

    public static Response postAsycResponse(WebTarget target, String content) throws ExecutionException, InterruptedException {
        return target.request(APPLICATION_JSON_TYPE).async().post(Entity.entity(content, MediaType.APPLICATION_JSON)).get();
    }

    public static Response postAsycResponse(WebTarget target) throws ExecutionException, InterruptedException {
        return target.request(APPLICATION_JSON_TYPE).async().method("POST").get();
    }

    public static Response deleteAsycResponse(WebTarget target) throws ExecutionException, InterruptedException {
        return target.request().async().delete().get();
    }
}

@@ -28,50 +28,8 @@
 l;%0A%0A
-import org.eclipse.jetty.http.MimeTypes;%0A%0A
 impo
@@ -132,43 +132,8 @@
 et;%0A
-import javax.ws.rs.core.MediaType;%0A
 impo
@@ -211,16 +211,75 @@
 ption;%0A%0A
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;%0A
 import s
@@ -538,38 +538,8 @@
 est(
-String.valueOf(MimeTypes.Type.
 APPL
@@ -550,23 +550,16 @@
 ION_JSON
-_UTF_8)
 ).get();
@@ -683,38 +683,8 @@
 est(
-String.valueOf(MimeTypes.Type.
 APPL
@@ -687,39 +687,32 @@
 APPLICATION_JSON
-_UTF_8)
 ).post(Entity.en
@@ -721,34 +721,24 @@
 ty(content, 
-MediaType.
 APPLICATION_
@@ -862,38 +862,8 @@
 est(
-String.valueOf(MimeTypes.Type.
 APPL
@@ -874,23 +874,16 @@
 ION_JSON
-_UTF_8)
 ).post(E
@@ -900,34 +900,24 @@
 ty(content, 
-MediaType.
 APPLICATION_
@@ -1025,38 +1025,8 @@
 est(
-String.valueOf(MimeTypes.Type.
 APPL
@@ -1041,15 +1041,8 @@
 JSON
-_UTF_8)
 ).me
@@ -1581,26 +1581,16 @@
 ontent, 
-MediaType.
 APPLICAT

update mimetypes