mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Refactor uri builds in shares
This commit is contained in:
parent
8e357d7811
commit
7bed924ff8
@ -1,7 +1,8 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* @author David González Verdugo
|
||||||
|
* Copyright (C) 2018 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -26,14 +27,16 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import android.net.Uri;
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -187,14 +190,18 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result;
|
||||||
int status = -1;
|
int status;
|
||||||
|
|
||||||
PostMethod post = null;
|
PostMethod post = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Uri requestUri = client.getBaseUri();
|
||||||
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
||||||
|
|
||||||
// Post Method
|
// Post Method
|
||||||
post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
post = new PostMethod(uriBuilder.build().toString());
|
||||||
|
|
||||||
post.setRequestHeader("Content-Type",
|
post.setRequestHeader("Content-Type",
|
||||||
"application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
|
"application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* @author David González Verdugo
|
||||||
|
* Copyright (C) 2018 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -25,6 +26,8 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
@ -59,7 +62,12 @@ public class GetRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
// Get the response
|
// Get the response
|
||||||
try {
|
try {
|
||||||
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId));
|
Uri requestUri = client.getBaseUri();
|
||||||
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
||||||
|
uriBuilder.appendEncodedPath(Long.toString(mRemoteId));
|
||||||
|
|
||||||
|
get = new GetMethod(uriBuilder.build().toString());
|
||||||
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
||||||
|
|
||||||
status = client.executeMethod(get);
|
status = client.executeMethod(get);
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
*
|
*
|
||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* @author David González Verdugo
|
||||||
|
* Copyright (C) 2018 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -112,7 +113,7 @@ public class GetRemoteShareesOperation extends RemoteOperation{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result;
|
||||||
int status;
|
int status;
|
||||||
GetMethod get = null;
|
GetMethod get = null;
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* @author David González Verdugo
|
||||||
|
* Copyright (C) 2018 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -26,15 +27,17 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import android.net.Uri;
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a list shares for a specific file.
|
* Provide a list shares for a specific file.
|
||||||
* The input is the full path of the desired file.
|
* The input is the full path of the desired file.
|
||||||
@ -77,8 +80,12 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
|||||||
GetMethod get = null;
|
GetMethod get = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Uri requestUri = client.getBaseUri();
|
||||||
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
||||||
|
|
||||||
// Get Method
|
// Get Method
|
||||||
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
get = new GetMethod(uriBuilder.build().toString());
|
||||||
|
|
||||||
// Add Parameters to Get Method
|
// Add Parameters to Get Method
|
||||||
get.setQueryString(new NameValuePair[]{
|
get.setQueryString(new NameValuePair[]{
|
||||||
|
@ -26,14 +26,16 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import android.net.Uri;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data from the server about ALL the known shares owned by the requester.
|
* Get the data from the server about ALL the known shares owned by the requester.
|
||||||
*/
|
*/
|
||||||
@ -56,7 +58,11 @@ public class GetRemoteSharesOperation extends RemoteOperation {
|
|||||||
|
|
||||||
// Get the response
|
// Get the response
|
||||||
try {
|
try {
|
||||||
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
|
Uri requestUri = client.getBaseUri();
|
||||||
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
||||||
|
|
||||||
|
get = new GetMethod(uriBuilder.build().toString());
|
||||||
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
||||||
status = client.executeMethod(get);
|
status = client.executeMethod(get);
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* @author David González Verdugo
|
||||||
|
* Copyright (C) 2018 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -26,14 +27,16 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import android.net.Uri;
|
||||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a share
|
* Remove a share
|
||||||
*/
|
*/
|
||||||
@ -57,14 +60,18 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result;
|
||||||
int status = -1;
|
int status;
|
||||||
|
|
||||||
DeleteMethod delete = null;
|
DeleteMethod delete = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String id = "/" + String.valueOf(mRemoteShareId);
|
Uri requestUri = client.getBaseUri();
|
||||||
delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id);
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
||||||
|
uriBuilder.appendEncodedPath(String.valueOf(mRemoteShareId));
|
||||||
|
|
||||||
|
delete = new DeleteMethod(uriBuilder.build().toString());
|
||||||
|
|
||||||
delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
||||||
|
|
||||||
@ -79,7 +86,7 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
|
|||||||
);
|
);
|
||||||
result = parser.parse(response);
|
result = parser.parse(response);
|
||||||
|
|
||||||
Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage());
|
Log_OC.d(TAG, "Unshare " + mRemoteShareId + ": " + result.getLogMessage());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(false, delete);
|
result = new RemoteOperationResult(false, delete);
|
||||||
|
@ -36,7 +36,7 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|||||||
public class ShareUtils {
|
public class ShareUtils {
|
||||||
|
|
||||||
// OCS Route
|
// OCS Route
|
||||||
public static final String SHARING_API_PATH ="/ocs/v1.php/apps/files_sharing/api/v1/shares";
|
public static final String SHARING_API_PATH ="ocs/v1.php/apps/files_sharing/api/v1/shares";
|
||||||
|
|
||||||
// String to build the link with the token of a share:
|
// String to build the link with the token of a share:
|
||||||
public static final String SHARING_LINK_PATH_BEFORE_VERSION_8 = "/public.php?service=files&t=";
|
public static final String SHARING_LINK_PATH_BEFORE_VERSION_8 = "/public.php?service=files&t=";
|
||||||
|
@ -208,7 +208,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
try {
|
try {
|
||||||
Uri requestUri = client.getBaseUri();
|
Uri requestUri = client.getBaseUri();
|
||||||
Uri.Builder uriBuilder = requestUri.buildUpon();
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1));
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
||||||
uriBuilder.appendEncodedPath(Long.toString(mRemoteId));
|
uriBuilder.appendEncodedPath(Long.toString(mRemoteId));
|
||||||
uriString = uriBuilder.build().toString();
|
uriString = uriBuilder.build().toString();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user