Search in sources :

Example 1 with BasicHandle

use of com.androidquery.auth.BasicHandle 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 2 with BasicHandle

use of com.androidquery.auth.BasicHandle in project androidquery by androidquery.

the class AjaxAuthActivity method auth_basic.

public void auth_basic() {
    BasicHandle handle = new BasicHandle("tinyeeliu@gmail.com", "password");
    String url = "http://xpenser.com/api/v1.0/reports/";
    aq.auth(handle).progress(R.id.progress).ajax(url, JSONArray.class, this, "basicCb");
}
Also used : BasicHandle(com.androidquery.auth.BasicHandle)

Example 3 with BasicHandle

use of com.androidquery.auth.BasicHandle in project androidquery by androidquery.

the class AQueryAuthTest method testBasicAuthHandle.

/*
	public void testBasicAuth() {
		
		//BasicHandle handle = new BasicHandle("tinyeeliu@gmail.com", "password");
		
		String url = "http://xpenser.com/api/v1.0/reports/";
		
		
		AjaxCallback<JSONArray> cb = new AjaxCallback<JSONArray>();
		
		String cred = "tinyeeliu@gmail.com:password";
		
		String auth = "Basic " + Base64.encodeToString(cred.getBytes(), Base64.DEFAULT);
		
		AQUtility.debug("auth", auth);
		
		cb.header("Authorization", auth);
		cb.header("Host", "xpenser.com");
		//cb.header("User-Agent", MOBILE_AGENT);
		
		cb.url(url).type(JSONArray.class).weakHandler(this, "basicCb").async(getActivity());
		
        waitAsync();
        
        JSONArray jo = (JSONArray) result;
        
        AQUtility.debug(jo);
        
        assertNotNull(jo);       
        
    }
	*/
public void testBasicAuthHandle() {
    BasicHandle handle = new BasicHandle("tinyeeliu@gmail.com", "password");
    String url = "http://xpenser.com/api/v1.0/reports/";
    aq.auth(handle).ajax(url, JSONArray.class, this, "basicCb");
    waitAsync();
    JSONArray jo = (JSONArray) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
}
Also used : BasicHandle(com.androidquery.auth.BasicHandle) JSONArray(org.json.JSONArray)

Aggregations

BasicHandle (com.androidquery.auth.BasicHandle)3 AjaxStatus (com.androidquery.callback.AjaxStatus)1 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1