@Test public void currentInstallation_newLocalFile() throws Exception { NCMBInstallationService installationService = (NCMBInstallationService) NCMB.factory(NCMB.ServiceType.INSTALLATION); JSONObject json = installationService.createInstallation("xxxxxxxxxxxxxxxxxxx", new JSONObject("{key:value}")); Assert.assertEquals("7FrmPTBKSNtVjajm", json.getString("objectId")); Assert.assertEquals("2014-06-03T11:28:30.348Z", json.getString("createDate")); File localFile = new File(NCMB.getCurrentContext().context.getDir("NCMB", Context.MODE_PRIVATE), "currentInstallation"); if (!localFile.exists()) { Assert.fail("currentInstallationFile is not created."); } JSONObject localData = new JSONObject(); try { BufferedReader br = new BufferedReader(new FileReader(localFile)); String information = br.readLine(); br.close(); localData = new JSONObject(information); } catch (IOException | JSONException e) { Assert.fail(e.getMessage()); } Assert.assertEquals("7FrmPTBKSNtVjajm", localData.getString("objectId")); Assert.assertEquals("value", localData.getString("key")); Assert.assertEquals("xxxxxxxxxxxxxxxxxxx", localData.getString("deviceToken")); DateFormat format = NCMBDateFormat.getIso8601(); Assert.assertEquals("2014-06-03T11:28:30.348Z", localData.getString("createDate")); }
public JSONObject createInstallation(String registrationId, JSONObject params) throws NCMBException { params = argumentNullCheckForPOST(registrationId, params); try { params.put("deviceToken", registrationId); setInstallationBasicData(params); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid json format."); } catch (PackageManager.NameNotFoundException e) { throw new NCMBException(NCMBException.DATA_NOT_FOUND, "PackageManager not found."); } RequestParams request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST); NCMBResponse response = sendRequest(request); if (response.statusCode != HTTP_STATUS_INSTALLATION_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Created failed."); } writeCurrentInstallation(params, response.responseData); return response.responseData; }
NCMBInstallationService extends NCMBService { public JSONObject createInstallation(String registrationId, JSONObject params) throws NCMBException { params = argumentNullCheckForPOST(registrationId, params); try { params.put("deviceToken", registrationId); setInstallationBasicData(params); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid json format."); } catch (PackageManager.NameNotFoundException e) { throw new NCMBException(NCMBException.DATA_NOT_FOUND, "PackageManager not found."); } RequestParams request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST); NCMBResponse response = sendRequest(request); if (response.statusCode != HTTP_STATUS_INSTALLATION_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Created failed."); } writeCurrentInstallation(params, response.responseData); return response.responseData; } }
NCMBInstallationService extends NCMBService { public JSONObject createInstallation(String registrationId, JSONObject params) throws NCMBException { params = argumentNullCheckForPOST(registrationId, params); try { params.put("deviceToken", registrationId); setInstallationBasicData(params); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid json format."); } catch (PackageManager.NameNotFoundException e) { throw new NCMBException(NCMBException.DATA_NOT_FOUND, "PackageManager not found."); } RequestParams request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST); NCMBResponse response = sendRequest(request); if (response.statusCode != HTTP_STATUS_INSTALLATION_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Created failed."); } writeCurrentInstallation(params, response.responseData); return response.responseData; } NCMBInstallationService(NCMBContext context); }
NCMBInstallationService extends NCMBService { public JSONObject createInstallation(String registrationId, JSONObject params) throws NCMBException { params = argumentNullCheckForPOST(registrationId, params); try { params.put("deviceToken", registrationId); setInstallationBasicData(params); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid json format."); } catch (PackageManager.NameNotFoundException e) { throw new NCMBException(NCMBException.DATA_NOT_FOUND, "PackageManager not found."); } RequestParams request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST); NCMBResponse response = sendRequest(request); if (response.statusCode != HTTP_STATUS_INSTALLATION_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Created failed."); } writeCurrentInstallation(params, response.responseData); return response.responseData; } NCMBInstallationService(NCMBContext context); JSONObject createInstallation(String registrationId, JSONObject params); void createInstallationInBackground(String registrationId, JSONObject params, final ExecuteServiceCallback callback); JSONObject updateInstallation(String objectId, JSONObject params); void updateInstallationInBackground(final String objectId, JSONObject params, final ExecuteServiceCallback callback); void deleteInstallation(String objectId); void deleteInstallationInBackground(final String objectId, DoneCallback callback); NCMBInstallation fetchInstallation(String objectId); void fetchInstallationInBackground(String objectId, final FetchCallback callback); List searchInstallation(JSONObject conditions); void searchInstallationInBackground(JSONObject conditions, final SearchInstallationCallback callback); }
NCMBInstallationService extends NCMBService { public JSONObject createInstallation(String registrationId, JSONObject params) throws NCMBException { params = argumentNullCheckForPOST(registrationId, params); try { params.put("deviceToken", registrationId); setInstallationBasicData(params); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid json format."); } catch (PackageManager.NameNotFoundException e) { throw new NCMBException(NCMBException.DATA_NOT_FOUND, "PackageManager not found."); } RequestParams request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST); NCMBResponse response = sendRequest(request); if (response.statusCode != HTTP_STATUS_INSTALLATION_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Created failed."); } writeCurrentInstallation(params, response.responseData); return response.responseData; } NCMBInstallationService(NCMBContext context); JSONObject createInstallation(String registrationId, JSONObject params); void createInstallationInBackground(String registrationId, JSONObject params, final ExecuteServiceCallback callback); JSONObject updateInstallation(String objectId, JSONObject params); void updateInstallationInBackground(final String objectId, JSONObject params, final ExecuteServiceCallback callback); void deleteInstallation(String objectId); void deleteInstallationInBackground(final String objectId, DoneCallback callback); NCMBInstallation fetchInstallation(String objectId); void fetchInstallationInBackground(String objectId, final FetchCallback callback); List searchInstallation(JSONObject conditions); void searchInstallationInBackground(JSONObject conditions, final SearchInstallationCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_INSTALLATION_CREATED; static final int HTTP_STATUS_INSTALLATION_UPDATED; static final int HTTP_STATUS_INSTALLATION_DELETED; static final int HTTP_STATUS_INSTALLATION_GOTTEN; }