package com.xty.common.weight.areaselector;

import com.google.gson.Gson;

import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class RetrofitUtil {
    private Retrofit retrofit;
    private Gson gson = new Gson();
    private API api;

    RetrofitUtil() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl("https://apis.map.qq.com")
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
    }

    API getApiInstance(){
        if(api == null){
            synchronized (RetrofitUtil.class){
                if(api == null) {
                    api = retrofit.create(API.class);
                }
            }
        }
        return api;
    }

    public RequestBody getRequestBody(Object o) {
        String jsonString = gson.toJson(o);
        RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), jsonString);
        return requestBody;
    }
}
