package com.ysnows.base.utils;


import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class OkNetUtils {

    public static void get(String url, SuccessCallBack successCallBack) {
        get(url, null, successCallBack);
    }

    public static void get(String url, HashMap<String, String> params, SuccessCallBack successCallBack) {
        GetBuilder builder = OkHttpUtils
                .get()
                .url(url);
        if (params != null) {
            for (Map.Entry<String, String> stringObjectEntry : params.entrySet()) {
                builder.addParams(stringObjectEntry.getKey(), stringObjectEntry.getValue());
            }
        }


        builder.build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        if (successCallBack != null) {
                            successCallBack.onSuccess(response);
                        }

                    }
                });

    }

}
