package com.hc.webapp.web;

import android.os.AsyncTask;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class GetRuquest {
    OkHttpClient client = new OkHttpClient();
    GetRequestListener listener;
    private String RequestSynchro(String url) throws Exception{
        Request request = new Request.Builder()
                .url(url)
                .build();

        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    public void RequestAsync(String url,GetRequestListener listener){
        this.listener =listener;
        new RequestAsyncTask().execute(url);
    }

    class RequestAsyncTask extends AsyncTask<String,Integer,String>{

        @Override
        protected String doInBackground(String... strings) {
            try{
                String response = RequestSynchro(strings[0]);
                listener.onResult(response);
            }catch (Exception e){
                e.printStackTrace();
            }
            return "";
        }
    }
}
