package com.kfb.kfbv1.model;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.ResponseHandlerInterface;
import com.loopj.android.http.SyncHttpClient;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

import cz.msebera.android.httpclient.Header;

public class KfbHttpRequest {
    private  KfbGate mGate;
    public  String outS;
    private SyncHttpClient client;

    public String getTest(String aUrl)
    {
        client = new SyncHttpClient();
        try {
            String uri = aUrl;
             client.get(uri, new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    outS = new String(responseBody);
                    KfbModel.getData().tekser =outS;
                    KfbModel.getData().error = false;
                    //KfbModel.getData().progresok=true;

                  //  KfbModel.getData().textViewout.setText(outS);
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                    outS = "ERROR"+ error.getMessage();
                    KfbModel.getData().tekser =outS;
                    KfbModel.getData().error = true;
                   // KfbModel.getData().progresok=true;

                  // KfbModel.getData().textViewout.setText(outS);

                }
            });
            return  outS;
        }catch (Exception e)
        {
            Log.e("HttpClient",e.getMessage());
            return "";
        }
    }
    public void getRequest(KfbGate aGate) {
        mGate = aGate;

        client = new SyncHttpClient();
        try {
            String uri = aGate.getmAdres();
         client.get(uri, new AsyncHttpResponseHandler() {
             @Override
             public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                 outS = new String(responseBody);
                 KfbModel.getData().tekser =outS;
                 KfbModel.getData().error = false;
             }

             @Override
             public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                 outS = "ERROR"+ error.getMessage();
                 KfbModel.getData().tekser =outS;
                 KfbModel.getData().error = true;
             }
         });


        }catch (Exception e)
        {
            Log.e("HttpClient",e.getMessage());
        }
    }
}


