use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.
the class SyncUpTarget method fetchLastModifiedDate.
/**
* Fetch last modified date for a given record
* @param syncManager
* @param record
* @return
*/
protected RecordModDate fetchLastModifiedDate(SyncManager syncManager, JSONObject record) throws JSONException, IOException {
final String objectType = (String) SmartStore.project(record, Constants.SOBJECT_TYPE);
final String objectId = record.getString(getIdFieldName());
RestRequest lastModRequest = RestRequest.getRequestForRetrieve(syncManager.apiVersion, objectType, objectId, Arrays.asList(getModificationDateFieldName()));
RestResponse lastModResponse = syncManager.sendSyncWithMobileSyncUserAgent(lastModRequest);
return new RecordModDate(lastModResponse.isSuccess() ? lastModResponse.asJSONObject().getString(getModificationDateFieldName()) : null, lastModResponse.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND);
}
use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.
the class IDPRequestHandler method getValidAccessToken.
/**
* Makes a simple REST call to and returns a valid access token or null if refresh failed.
* This method should NOT be called from the main thread since it makes a network request.
*
* @return Valid access token.
* @throws IDPRequestHandlerException
*/
public String getValidAccessToken() throws IDPRequestHandlerException {
/*
* Ensures the access token associated with this user account is valid and refreshes the
* token if it's not valid. Any request to 'frontdoor' must be made with a valid token.
*/
final Context context = SalesforceSDKManager.getInstance().getAppContext();
RestResponse restResponse = null;
Exception exception = null;
String accessToken = null;
try {
restResponse = restClient.sendSync(RestRequest.getRequestForUserInfo());
} catch (IOException e) {
exception = e;
} finally {
if (restResponse == null || !restResponse.isSuccess()) {
handleError("Invalid REST client", exception);
} else {
accessToken = restClient.getAuthToken();
}
}
return accessToken;
}
use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.
the class ContentSoqlSyncDownTarget method startFetch.
@Override
public JSONArray startFetch(SyncManager syncManager, long maxTimeStamp) throws IOException, JSONException {
String queryToRun = maxTimeStamp > 0 ? SoqlSyncDownTarget.addFilterForReSync(getQuery(maxTimeStamp), getModificationDateFieldName(), maxTimeStamp) : getQuery(maxTimeStamp);
// cheap call to refresh session
syncManager.getRestClient().sendSync(RestRequest.getRequestForUserInfo());
RestRequest request = buildQueryRequest(syncManager.getRestClient().getAuthToken(), queryToRun);
RestResponse response = syncManager.sendSyncWithMobileSyncUserAgent(request);
JSONArray records = parseSoapResponse(response);
return records;
}
use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.
the class ContentSoqlSyncDownTarget method continueFetch.
@Override
public JSONArray continueFetch(SyncManager syncManager) throws IOException, JSONException {
if (queryLocator == null) {
return null;
}
RestRequest request = buildQueryMoreRequest(syncManager.getRestClient().getAuthToken(), queryLocator);
RestResponse response = syncManager.sendSyncWithMobileSyncUserAgent(request);
JSONArray records = parseSoapResponse(response);
return records;
}
use of com.salesforce.androidsdk.rest.RestResponse in project SalesforceMobileSDK-Android by forcedotcom.
the class ManagerTestCase method updateRecordsOnServer.
/**
* Update records on server
* @param idToFieldsUpdated
* @param sObjectType
* @throws Exception
*/
protected void updateRecordsOnServer(Map<String, Map<String, Object>> idToFieldsUpdated, String sObjectType) throws Exception {
List<RestRequest> requests = new ArrayList<>();
for (String id : idToFieldsUpdated.keySet()) {
requests.add(RestRequest.getRequestForUpdate(apiVersion, sObjectType, id, idToFieldsUpdated.get(id)));
}
RestResponse response = restClient.sendSync(RestRequest.getBatchRequest(apiVersion, false, requests));
Assert.assertTrue("Updates failed", response.isSuccess() && !response.asJSONObject().getBoolean("hasErrors"));
}
Aggregations