Search in sources :

Example 21 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testWaitBlock.

public void testWaitBlock() {
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
    cb.url(url).type(JSONObject.class);
    aq.sync(cb);
    String u = cb.getUrl();
    JSONObject jo = cb.getResult();
    AjaxStatus status = cb.getStatus();
    assertNotNull(jo);
    assertNotNull(jo.opt("responseData"));
    checkStatus(status);
}
Also used : JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 22 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPostMultiAuth.

public void testAjaxPostMultiAuth() {
    String url = "http://www.androidquery.com/p/multipart";
    BasicHandle handle = new BasicHandle("username", "1234");
    Map<String, Object> params = new HashMap<String, Object>();
    byte[] data = new byte[1234];
    byte[] data2 = new byte[2345];
    params.put("data", data);
    params.put("data2", data2);
    aq.auth(handle).ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            AQUtility.debug(status.getCode(), status.getError());
            AQueryAsyncTest.this.result = jo;
        }
    });
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals(1234, jo.optInt("data"));
    assertEquals(2345, jo.optInt("data2"));
    JSONObject headers = jo.optJSONObject("headers");
    assertNotNull(headers.optString("Authorization"));
}
Also used : JSONObject(org.json.JSONObject) BasicHandle(com.androidquery.auth.BasicHandle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 23 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPostMultiError.

public void testAjaxPostMultiError() {
    String url = "http://www.androidquery.com/p/multipart2";
    Map<String, Object> params = new HashMap<String, Object>();
    byte[] data = new byte[1234];
    byte[] data2 = new byte[2345];
    params.put("data", data);
    params.put("data2", data2);
    aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            AQUtility.debug(status.getCode(), status.getError());
            AQueryAsyncTest.this.result = jo;
            AQueryAsyncTest.this.status = status;
        }
    });
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug("error code", status.getCode());
    assertNull(jo);
    assertEquals(404, status.getCode());
    String error = status.getError();
    assertNotNull(error);
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 24 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPostMultiInputStream.

public void testAjaxPostMultiInputStream() {
    String url = "http://www.androidquery.com/p/multipart";
    Map<String, Object> params = new HashMap<String, Object>();
    byte[] data = new byte[1234];
    byte[] data2 = new byte[2345];
    params.put("data", new ByteArrayInputStream(data));
    params.put("data2", new ByteArrayInputStream(data2));
    aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            AQUtility.debug(status.getCode(), status.getError());
            AQueryAsyncTest.this.result = jo;
        }
    });
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals(1234, jo.optInt("data"));
    assertEquals(2345, jo.optInt("data2"));
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 25 with AjaxStatus

use of com.androidquery.callback.AjaxStatus in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxHeadersGet.

public void testAjaxHeadersGet() {
    String url = "http://www.google.com";
    aq.ajax(url, String.class, new AjaxCallback<String>() {

        @Override
        public void callback(String url, String json, AjaxStatus status) {
            done(url, json, status);
        }
    });
    waitAsync();
    assertNotNull(result);
    List<Header> headers = status.getHeaders();
    assertTrue(headers.size() > 0);
    Header c = headers.get(0);
    AQUtility.debug(c.getName(), c.getValue());
}
Also used : Header(org.apache.http.Header) AjaxStatus(com.androidquery.callback.AjaxStatus)

Aggregations

AjaxStatus (com.androidquery.callback.AjaxStatus)55 BitmapAjaxCallback (com.androidquery.callback.BitmapAjaxCallback)33 AjaxCallback (com.androidquery.callback.AjaxCallback)28 AbstractAjaxCallback (com.androidquery.callback.AbstractAjaxCallback)27 JSONObject (org.json.JSONObject)27 File (java.io.File)15 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)10 JsonObject (com.google.gson.JsonObject)8 Bitmap (android.graphics.Bitmap)7 Location (android.location.Location)4 ImageView (android.widget.ImageView)4 LocationAjaxCallback (com.androidquery.callback.LocationAjaxCallback)4 ArrayList (java.util.ArrayList)3 NameValuePair (org.apache.http.NameValuePair)3 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 ProxyHandle (com.androidquery.callback.ProxyHandle)2 Gson (com.google.gson.Gson)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2