alcatrazbr
1/19/2017 - 11:10 AM

REST, json, gson

REST, json, gson

String webService;
String urlConfirmEmail;
Gson gson;
GenericResponseWebService grs;
AsyncHttpClient client;
webService = getResources().getString(R.string.host_webservice);
grs = gson.fromJson(responsestr, GenericResponseWebService.class);
gson = new Gson();

urlConfirmEmail = webService + "admin/webservice/confirm-code";
RequestParams params = new RequestParams();
params.put("Email", grs.getEmail());
params.put("ConfirmCode", grs.getConfirmCode());
client = new AsyncHttpClient();
client.post( LoginCadastrarActivity.this, urlConfirmEmail, params, new AsyncHttpResponseHandler() {
    @Override
    public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
        String responsestr = new String(responseBody);
        GenericResponseWebService grsConfirm = gson.fromJson(responsestr, GenericResponseWebService.class);
        Toast.makeText(LoginCadastrarActivity.this, grsConfirm.getStatusMsg(), Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
        String responsestr = new String(responseBody);
        GenericResponseWebService grsConfirm = gson.fromJson(responsestr, GenericResponseWebService.class);
        grsConfirm.getStatusMsg();
        Toast.makeText(LoginCadastrarActivity.this, grsConfirm.getStatusMsg(), Toast.LENGTH_SHORT).show();
        return;
    }
});
    private void logCliente() {
        String webService = getResources().getString(R.string.host_webservice);
        String url =  webService + getString(R.string.log_cliente);

        AsyncHttpClient client;


        RequestParams params = new RequestParams();
        params.put("idCliente", session.getCliente().getIdCliente());

        client = new AsyncHttpClient();
        client.post( SplashActivity.this, url, params, new AsyncHttpResponseHandler() {
            Gson gson = new Gson();
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                String responsestr = new String(responseBody);
                GenericResponseWebService grs = gson.fromJson(responsestr, GenericResponseWebService.class);
                session.setTesteUser(grs.getIsTesteUser() == 1);
                session.saveSession();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                String responsestr = new String(responseBody);
                GenericResponseWebService grs = gson.fromJson(responsestr, GenericResponseWebService.class);
                grs.getStatusMsg();
                return;
            }
        });
    }
// gradle
//     compile 'com.loopj.android:android-async-http:1.4.9'

package br.com.xqx.alcatraz.motokkascli.apoio;

/**
 * Created by alcatraz on 08/01/2017.
 */

public class GenericResponseWebService {

    /**
     * Status : 1
     * StatusMsg : Cadastrado com sucesso
     * Email : aalcatrazbr@gmail.com
     * Nome : Marcos
     * idCliente : 25
     * ConfirmCode : 900542
     */

    private int Status;
    private String StatusMsg;
    private String Email;
    private String Nome;
    private int idCliente;
    private String ConfirmCode;

    public int getStatus() {
        return Status;
    }

    public void setStatus(int Status) {
        this.Status = Status;
    }

    public String getStatusMsg() {
        return StatusMsg;
    }

    public void setStatusMsg(String StatusMsg) {
        this.StatusMsg = StatusMsg;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public String getNome() {
        return Nome;
    }

    public void setNome(String Nome) {
        this.Nome = Nome;
    }

    public int getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(int idCliente) {
        this.idCliente = idCliente;
    }

    public String getConfirmCode() {
        return ConfirmCode;
    }

    public void setConfirmCode(String ConfirmCode) {
        this.ConfirmCode = ConfirmCode;
    }
}