From 8b7ac85eb84da614d98484f0db50e11707d32af3 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 5 Dec 2014 10:17:35 +0100 Subject: [PATCH] SyncAdaptr.doUploadSync(): Add "interface" param to mark it as from the app. Add: interface: murrayc.com-android-galaxyzoo to the parameters in the content of the POST to make it easier for the server to identify the app as the source of the classifications. See https://github.com/murraycu/android-galaxyzoo/issues/11 --- .../app/provider/test/ZooniverseClientTest.java | 2 ++ .../murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java b/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java index 417134a8..88e2d2db 100644 --- a/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java +++ b/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java @@ -216,6 +216,8 @@ public void testUploadWithSuccess() throws IOException, InterruptedException { final URL mockUrl = server.getUrl("/"); final ZooniverseClient client = new ZooniverseClient(getContext(), mockUrl.toString()); + //SyncAdapter.doUploadSync() adds an "interface" parameter too, + //but we are testing a more generic API here: List values = new ArrayList<>(); values.add(new BasicNameValuePair("classification[subject_ids][]", "504e4a38c499611ea6010c6a")); values.add(new BasicNameValuePair("classification[favorite][]", "true")); diff --git a/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java b/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java index b5a532af..5b26d8e1 100644 --- a/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java +++ b/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java @@ -322,11 +322,18 @@ private void removeItem(final String itemId) { private boolean doUploadSync(final String itemId, final String subjectId, final String authName, final String authApiKey) { - final String PARAM_PART_CLASSIFICATION = "classification"; //Note: I tried using HttpPost.getParams().setParameter() instead of the NameValuePairs, //but that did not allow multiple parameters with the same name, which we need. final List nameValuePairs = new ArrayList<>(); + + //Help the server know that the classification is from this Android app, + //by reusing the User-Agent string as a parameter value. + //See https://github.com/murraycu/android-galaxyzoo/issues/11 + nameValuePairs.add(new BasicNameValuePair("interface", + HttpUtils.USER_AGENT_MURRAYC)); + + final String PARAM_PART_CLASSIFICATION = "classification"; nameValuePairs.add(new BasicNameValuePair(PARAM_PART_CLASSIFICATION + "[subject_ids][]", subjectId));