NCMBObjectService extends NCMBService { public JSONObject saveObject(String className, JSONObject params) throws NCMBException { if (!validateClassName(className)){ throw new NCMBException(NCMBException.REQUIRED, "className is must not be null or empty"); } validateClassName(className); String url = mContext.baseUrl + mServicePath + className; String type = NCMBRequest.HTTP_METHOD_POST; NCMBResponse response = sendRequest(url, type, params.toString()); if (response.statusCode != NCMBResponse.HTTP_STATUS_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Invalid status code"); } return response.responseData; } NCMBObjectService(NCMBContext context); JSONObject saveObject(String className, JSONObject params); void saveObjectInBackground(String className, JSONObject params, ExecuteServiceCallback callback); NCMBObject fetchObject(String className,String objectId); void fetchObjectInBackground(final String className, String objectId, final FetchCallback callback); JSONObject updateObject(String className, String objectId, JSONObject params); void updateObjectInBackground(String className, String objectId, JSONObject params, ExecuteServiceCallback callback); JSONObject deleteObject(String className,String objectId); void deleteObjectInBackground(String className, String objectId, ExecuteServiceCallback callback); List searchObject(String className, JSONObject conditions); void searchObjectInBackground(final String className, JSONObject conditions, SearchObjectCallback callback); int countObject(String className, JSONObject conditions); void countObjectInBackground(final String className, JSONObject conditions, CountCallback callback); static final String SERVICE_PATH; }
@Test public void saveObjectToNcmb_valid_class() throws Exception { NCMBObjectService objServ = (NCMBObjectService) NCMB.factory(NCMB.ServiceType.OBJECT); JSONObject response = objServ.saveObject("TestClass", new JSONObject("{\"key\":\"value\"}")); Assert.assertEquals("7FrmPTBKSNtVjajm", response.getString("objectId")); Assert.assertEquals("2014-06-03T11:28:30.348Z", response.getString("createDate")); }