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();
}
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();
}
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;
}
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;
}
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;
}
Aggregations