br.com.vrbsm.fillup.controller.FillUpController.java Source code

Java tutorial

Introduction

Here is the source code for br.com.vrbsm.fillup.controller.FillUpController.java

Source

package br.com.vrbsm.fillup.controller;

import android.net.Uri;
import android.util.Log;

import com.google.gson.JsonObject;

import org.apache.http.client.utils.URLEncodedUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import br.com.vrbsm.fillup.listener.ResultListener;
import br.com.vrbsm.fillup.util.FillUpConstants;
import br.com.vrbsm.fillup.listener.DialogListener;

public class FillUpController extends SalunhasController {

    public FillUpController(DialogListener progressListener, ResultListener resultListener) {
        super(progressListener, resultListener);
    }

    public void getFillUp() {

        Uri.Builder url = Uri.parse(FillUpConstants.BASE_URL + "FillUp").buildUpon();
        String className = "Vehicle";
        String __type = "Pointer";
        String objectId = "LvyRdtxUDl";
        url.appendQueryParameter("where", "{\"vehicle\":{\"objectId\":\"" + objectId + "\",\"__type\":\"" + __type
                + "\",\"className\":\"" + className + "\" }}");

        doWebRequest(0, url.toString());
    }

    public void insertVehicle() throws JSONException {
        String url = FillUpConstants.BASE_URL + "Vehicle";

        JSONObject jsonObject = new JSONObject();
        JSONObject user = new JSONObject();

        jsonObject.put("license_plate", "NOWiiii");
        jsonObject.put("name", "Fiat - UNO");

        user.put("__type", "Pointer");
        user.put("className", "_User");
        user.put("objectId", "BGaZSsRjCN");

        jsonObject.put("user", user);

        doWebRequestPost(100, url.toString(), jsonObject);

    }

    @Override
    public Object parse(int operationCode, String json) throws Exception {
        Log.d("***_Result_****", "CODE - " + operationCode);
        Log.d("***_Result_****", json);
        if (!json.equals("200"))
            throw new Exception(json);
        return json.toString();

    }

}