/** * Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as * setBasicAuth('username','password',AuthScope.ANY) * @param username * @param password */ public void setBasicAuth(String user, String pass){ AuthScope scope = AuthScope.ANY; setBasicAuth(user, pass, scope); }
/** * Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as * setBasicAuth('username','password',AuthScope.ANY) * * @param username Basic Auth username * @param password Basic Auth password */ public void setBasicAuth(String username, String password) { setBasicAuth(username, password, false); }
/** * Sets basic authentication for the request. You should pass in your AuthScope for security. It * should be like this setBasicAuth("username","password", new AuthScope("host",port,AuthScope.ANY_REALM)) * * @param username Basic Auth username * @param password Basic Auth password * @param scope - an AuthScope object */ public void setBasicAuth(String username, String password, AuthScope scope) { setBasicAuth(username, password, scope, false); }
/** * Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as * setBasicAuth('username','password',AuthScope.ANY) * * @param username Basic Auth username * @param password Basic Auth password * @param preemtive sets authorization in preemtive manner */ public void setBasicAuth(String username, String password, boolean preemtive) { setBasicAuth(username, password, null, preemtive); }
public static void importVideo(String videoUrl, String title, final NewVideoCallback callback){ String url = String.format(STREAMABLE_BASE_URL + STREAMABLE_IMPORT_VIDEO_ENDPOINT, videoUrl, title); if(AndroidStreamableUtil.isNotEmpty(username) && AndroidStreamableUtil.isNotEmpty(password)) { REST_CLIENT.setBasicAuth(username, password); } REST_CLIENT.setTimeout(timeout); REST_CLIENT.get(url, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { JSONObject json = new JSONObject(new String(responseBody)); NewVideo newVideo = NewVideo.fromJson(json); callback.onSuccess(statusCode, newVideo); } catch (JSONException e){ callback.onFailure(statusCode, e); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { callback.onFailure(statusCode, error); } }); }
private static void uploadVideo(RequestParams params, final NewVideoCallback callback) { String url = STREAMABLE_BASE_URL + STREAMABLE_UPLOAD_VIDEO_ENDPOINT; if(AndroidStreamableUtil.isNotEmpty(username) && AndroidStreamableUtil.isNotEmpty(password)) { REST_CLIENT.setBasicAuth(username, password); } REST_CLIENT.setTimeout(timeout); REST_CLIENT.post(url, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { JSONObject json = new JSONObject(new String(responseBody)); NewVideo newVideo = NewVideo.fromJson(json); callback.onSuccess(statusCode, newVideo); } catch (JSONException e){ callback.onFailure(statusCode, e); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { callback.onFailure(statusCode, error); } }); }
public static void getVideo(String shortCode, final VideoCallback callback){ String url = STREAMABLE_BASE_URL + STREAMABLE_RETRIEVE_VIDEO_ENDPOINT + shortCode; if(AndroidStreamableUtil.isNotEmpty(username) && AndroidStreamableUtil.isNotEmpty(password)) { REST_CLIENT.setBasicAuth(username, password); } REST_CLIENT.setTimeout(timeout); REST_CLIENT.get(url, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { JSONObject json = new JSONObject(new String(responseBody)); Video newVideo = Video.fromJson(json); callback.onSuccess(statusCode, newVideo); } catch (JSONException e){ callback.onFailure(statusCode, e); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { callback.onFailure(statusCode, error); } }); }
public static void getAuthUser(final UserCallback callback){ String url = STREAMABLE_BASE_URL + STREAMABLE_RETRIEVE_AUTH_USER_ENDPOINT; if(AndroidStreamableUtil.isNotEmpty(username) && AndroidStreamableUtil.isNotEmpty(password)) { REST_CLIENT.setBasicAuth(username, password); } REST_CLIENT.setTimeout(timeout); REST_CLIENT.get(url, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { JSONObject json = new JSONObject(new String(responseBody)); User user = User.fromJson(json); callback.onSuccess(statusCode, user); } catch (JSONException e){ callback.onFailure(statusCode, e); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { callback.onFailure(statusCode, error); } }); }
public static void getUser(String username, final UserCallback callback){ String url = STREAMABLE_BASE_URL + STREAMABLE_RETRIEVE_USER_ENDPOINT + username; if(AndroidStreamableUtil.isNotEmpty(username) && AndroidStreamableUtil.isNotEmpty(password)) { REST_CLIENT.setBasicAuth(username, password); } REST_CLIENT.setTimeout(timeout); REST_CLIENT.get(url, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { JSONObject json = new JSONObject(new String(responseBody)); User user = User.fromJson(json); callback.onSuccess(statusCode, user); } catch (JSONException e){ callback.onFailure(statusCode, e); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { callback.onFailure(statusCode, error); } }); } }