package io.apptik.comm.jus.okhttp;


import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.RequestBody;

import java.util.Collections;
import java.util.Map;

import io.apptik.comm.jus.NetworkRequest;
import io.apptik.comm.jus.http.Headers;

public class JusOk {

    private JusOk() {
    }

    public static Headers jusHeaders(com.squareup.okhttp.Headers okHeaders) {
        return new Headers.Builder().addMMap(okHeaders.toMultimap()).build();
    }

    public static com.squareup.okhttp.Headers okHeaders(Headers jusHeaders, Headers
            additionalHeaders) {

        Map<String, String> headers;
        if (jusHeaders == null) {
            headers = Collections.emptyMap();
        } else {
            //check if we have content type in Jus headers ad remove it if yes
            headers = jusHeaders.toMap();
            headers.remove("Content-Type");
        }

        if (additionalHeaders != null)
        {
            headers.putAll(additionalHeaders.toMap());
        }
        return com.squareup.okhttp.Headers.of(headers);
    }

    public static RequestBody okBody(NetworkRequest request) {
        if (request == null)
            return null;
        return RequestBody.create(MediaType.parse(request.contentType.toString()), request.data);
    }
}

@@ -925,24 +925,16 @@
 != null)
-%0A       
  %7B%0A     
@@ -1185,81 +1185,205 @@
     
-return RequestBody.create(MediaType.parse(request.contentType.toString())
+MediaType mediaType = null;%0A        if (request.contentType != null) %7B%0A            mediaType = MediaType.parse(request.contentType.toString());%0A        %7D%0A        return RequestBody.create(mediaType
 , re

fix npe okhttp