Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13aa140d authored by Mario Danic's avatar Mario Danic
Browse files

Fix up stuff

parent ab227c69
Loading
Loading
Loading
Loading
+0 −45
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@
 */
package com.owncloud.android.lib.resources.notifications;

import android.util.Log;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -81,21 +79,11 @@ public class RegisterAccountDeviceForProxyOperation extends RemoteOperation {
            post = new PostMethod(uriToPost);
            post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

            /*StringRequestEntity requestEntity = new StringRequestEntity(
                    assembleJson(),
                    "application/json",
                    "UTF-8");

            Log.d("MARIO", assembleJson());

            post.setRequestEntity(requestEntity);*/
            post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

            status = client.executeMethod(post);
            String response = post.getResponseBodyAsString();

            Log.d("MARIO", response);

            if(isSuccess(status)) {
                result = new RemoteOperationResult(true, status, post.getResponseHeaders());
                Log_OC.d(TAG, "Successful response: " + response);
@@ -118,37 +106,4 @@ public class RegisterAccountDeviceForProxyOperation extends RemoteOperation {
    private boolean isSuccess(int status) {
        return (status == HttpStatus.SC_OK);
    }

    private String assembleJson() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("{");
        stringBuilder.append("\"");
        stringBuilder.append(PUSH_TOKEN);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(pushToken.trim());
        stringBuilder.append("\",");
        stringBuilder.append("\"");
        stringBuilder.append(DEVICE_IDENTIFIER);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(deviceIdentifier);
        stringBuilder.append("\",");
        stringBuilder.append("\"");
        stringBuilder.append(DEVICE_IDENTIFIER_SIGNATURE);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(deviceIdentifierSignature.trim());
        stringBuilder.append("\",");
        stringBuilder.append("\"");
        stringBuilder.append(USER_PUBLIC_KEY);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(userPublicKey.trim());
        stringBuilder.append("\"");
        stringBuilder.append("}");

        return stringBuilder.toString();
    }

}
+8 −34
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ import com.owncloud.android.lib.common.utils.HttpDeleteWithBody;
import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import java.net.URLEncoder;

public class UnregisterAccountDeviceForProxyOperation extends RemoteOperation {
    private static final String PROXY_ROUTE = "/devices";
@@ -41,7 +42,6 @@ public class UnregisterAccountDeviceForProxyOperation extends RemoteOperation {
    private static final String TAG = RegisterAccountDeviceForProxyOperation.class.getSimpleName();

    private String proxyUrl;
    private String pushToken;
    private String deviceIdentifier;
    private String deviceIdentifierSignature;
    private String userPublicKey;
@@ -67,14 +67,14 @@ public class UnregisterAccountDeviceForProxyOperation extends RemoteOperation {

        try {
            // Post Method
            delete = new HttpDeleteWithBody(proxyUrl + PROXY_ROUTE);
            StringRequestEntity requestEntity = new StringRequestEntity(
                    assembleJson(),
                    "application/json",
                    "UTF-8");
            String uriToPost = proxyUrl + PROXY_ROUTE;
            uriToPost += "?" + DEVICE_IDENTIFIER + "=" + URLEncoder.encode(deviceIdentifier) + "&";
            uriToPost += DEVICE_IDENTIFIER_SIGNATURE + "=" + URLEncoder.encode(deviceIdentifierSignature) + "&";
            uriToPost += USER_PUBLIC_KEY + "=" + URLEncoder.encode(userPublicKey);

            delete.setRequestEntity(requestEntity);
            delete = new HttpDeleteWithBody(uriToPost);
            delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
            delete.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

            status = client.executeMethod(delete);
            String response = delete.getResponseBodyAsString();
@@ -101,30 +101,4 @@ public class UnregisterAccountDeviceForProxyOperation extends RemoteOperation {
    private boolean isSuccess(int status) {
        return (status == HttpStatus.SC_OK);
    }

    private String assembleJson() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("{");
        stringBuilder.append("\"");
        stringBuilder.append(DEVICE_IDENTIFIER);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(deviceIdentifier.trim());
        stringBuilder.append("\",");
        stringBuilder.append("\"");
        stringBuilder.append(DEVICE_IDENTIFIER_SIGNATURE);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(deviceIdentifierSignature.trim());
        stringBuilder.append("\",");
        stringBuilder.append("\"");
        stringBuilder.append(USER_PUBLIC_KEY);
        stringBuilder.append("\"");
        stringBuilder.append(":\"");
        stringBuilder.append(userPublicKey.trim());
        stringBuilder.append("\"");
        stringBuilder.append("}");

        return stringBuilder.toString();
    }
}