Search in sources :

Example 16 with RestResponse

use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.

the class SyncUpTarget method updateOnServer.

/**
 * Save locally updated record back to server (original method)
 * Called by updateOnServer(SyncManager syncManager, JSONObject record, List<String> fieldlist)
 * @param syncManager
 * @param objectType
 * @param objectId
 * @param fields
 * @return true if successful
 * @throws IOException
 */
protected int updateOnServer(SyncManager syncManager, String objectType, String objectId, Map<String, Object> fields) throws IOException {
    RestRequest request = RestRequest.getRequestForUpdate(syncManager.apiVersion, objectType, objectId, fields);
    RestResponse response = syncManager.sendSyncWithMobileSyncUserAgent(request);
    if (!response.isSuccess()) {
        lastError = response.asString();
    }
    return response.getStatusCode();
}
Also used : RestRequest(com.salesforce.androidsdk.rest.RestRequest) RestResponse(com.salesforce.androidsdk.rest.RestResponse)

Example 17 with RestResponse

use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.

the class SyncUpTarget method deleteOnServer.

/**
 * Delete locally deleted record from server (original method)
 * Called by deleteOnServer(SyncManager syncManager, JSONObject record)
 * @param syncManager
 * @param objectType
 * @param objectId
 * @return server response status code
 * @throws IOException
 */
protected int deleteOnServer(SyncManager syncManager, String objectType, String objectId) throws IOException {
    RestRequest request = RestRequest.getRequestForDelete(syncManager.apiVersion, objectType, objectId);
    RestResponse response = syncManager.sendSyncWithMobileSyncUserAgent(request);
    if (!response.isSuccess()) {
        lastError = response.asString();
    }
    return response.getStatusCode();
}
Also used : RestRequest(com.salesforce.androidsdk.rest.RestRequest) RestResponse(com.salesforce.androidsdk.rest.RestResponse)

Example 18 with RestResponse

use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.

the class AuthConfigUtil method getMyDomainAuthConfig.

/**
 * Returns the auth config associated with a my domain login endpoint. This call
 * should be made from a background thread since it makes a network request.
 *
 * @param loginUrl Login URL.
 * @return Auth config.
 */
public static MyDomainAuthConfig getMyDomainAuthConfig(String loginUrl) {
    if (TextUtils.isEmpty(loginUrl)) {
        return null;
    }
    MyDomainAuthConfig authConfig = null;
    if (loginUrl.endsWith(FORWARD_SLASH)) {
        loginUrl = loginUrl.substring(0, loginUrl.length() - 1);
    }
    final String authConfigUrl = loginUrl + MY_DOMAIN_AUTH_CONFIG_ENDPOINT;
    final Request request = new Request.Builder().url(authConfigUrl).get().build();
    try {
        final Response response = HttpAccess.DEFAULT.getOkHttpClient().newCall(request).execute();
        if (response.isSuccessful()) {
            authConfig = new MyDomainAuthConfig((new RestResponse(response)).asJSONObject());
        }
    } catch (Exception e) {
        SalesforceSDKLogger.e(TAG, "Auth config request was not successful", e);
    }
    final Intent intent = new Intent(AUTH_CONFIG_COMPLETE_INTENT_ACTION);
    intent.putExtra(WAS_REQUEST_SUCCESSFUL_EXTRA, authConfig != null);
    SalesforceSDKManager.getInstance().getAppContext().sendBroadcast(intent);
    return authConfig;
}
Also used : RestResponse(com.salesforce.androidsdk.rest.RestResponse) Response(okhttp3.Response) RestResponse(com.salesforce.androidsdk.rest.RestResponse) Request(okhttp3.Request) Intent(android.content.Intent)

Example 19 with RestResponse

use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.

the class SoqlSyncDownTarget method startFetch.

protected JSONArray startFetch(SyncManager syncManager, String query) throws IOException, JSONException {
    RestRequest request = RestRequest.getRequestForQuery(syncManager.apiVersion, query, maxBatchSize);
    RestResponse response = syncManager.sendSyncWithMobileSyncUserAgent(request);
    JSONObject responseJson = getResponseJson(response);
    JSONArray records = getRecordsFromResponseJson(responseJson);
    // Records total size.
    totalSize = responseJson.getInt(Constants.TOTAL_SIZE);
    // Captures next records URL.
    nextRecordsUrl = JSONObjectHelper.optString(responseJson, Constants.NEXT_RECORDS_URL);
    return records;
}
Also used : RestRequest(com.salesforce.androidsdk.rest.RestRequest) JSONObject(org.json.JSONObject) RestResponse(com.salesforce.androidsdk.rest.RestResponse) JSONArray(org.json.JSONArray)

Example 20 with RestResponse

use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.

the class SoslSyncDownTarget method startFetch.

private JSONArray startFetch(SyncManager syncManager, long maxTimeStamp, String queryRun) throws IOException, JSONException {
    RestRequest request = RestRequest.getRequestForSearch(syncManager.apiVersion, queryRun);
    RestResponse response = syncManager.sendSyncWithMobileSyncUserAgent(request);
    JSONArray records = response.asJSONObject().getJSONArray(SEARCH_RECORDS);
    // Recording total size
    totalSize = records.length();
    return records;
}
Also used : RestRequest(com.salesforce.androidsdk.rest.RestRequest) RestResponse(com.salesforce.androidsdk.rest.RestResponse) JSONArray(org.json.JSONArray)

Aggregations

RestResponse (com.salesforce.androidsdk.rest.RestResponse)30 RestRequest (com.salesforce.androidsdk.rest.RestRequest)26 JSONArray (org.json.JSONArray)14 JSONObject (org.json.JSONObject)14 RestClient (com.salesforce.androidsdk.rest.RestClient)6 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 AsyncRequestCallback (com.salesforce.androidsdk.rest.RestClient.AsyncRequestCallback)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 JSONException (org.json.JSONException)3 NoNetworkException (com.salesforce.androidsdk.auth.HttpAccess.NoNetworkException)2 AccountInfoNotFoundException (com.salesforce.androidsdk.rest.ClientManager.AccountInfoNotFoundException)2 RestClientCallback (com.salesforce.androidsdk.rest.ClientManager.RestClientCallback)2 URISyntaxException (java.net.URISyntaxException)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Context (android.content.Context)1 Intent (android.content.Intent)1 ReactMethod (com.facebook.react.bridge.ReactMethod)1