1 /* ownCloud Android Library is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package com.owncloud.android.oc_framework.operations.remote;
27 import java.io.IOException;
28 import java.util.ArrayList;
30 import org.apache.commons.httpclient.HttpException;
31 import org.apache.commons.httpclient.methods.GetMethod;
32 import org.apache.http.HttpStatus;
34 import android.util.Log;
36 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
37 import com.owncloud.android.oc_framework.operations.RemoteOperation;
38 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
39 import com.owncloud.android.oc_framework.operations.ShareRemoteFile;
42 * Get the data from the server to know shared files/folders
48 public class GetRemoteSharedFilesOperation extends RemoteOperation {
50 private static final String TAG = GetRemoteSharedFilesOperation.class.getSimpleName();
53 private static final String SHAREAPI_ROUTE ="/ocs/v1.php/apps/files/files_sharing/api/v1/shares";
55 private ArrayList<ShareRemoteFile> mSharedFiles; // List of files for result
57 public GetRemoteSharedFilesOperation() {
58 // TODO Auto-generated constructor stub
62 protected RemoteOperationResult run(WebdavClient client) {
63 RemoteOperationResult result = null;
67 GetMethod get = new GetMethod(client.getBaseUri() + SHAREAPI_ROUTE);
68 Log.d(TAG, "URL ------> " + client.getBaseUri() + SHAREAPI_ROUTE);
72 status = client.executeMethod(get);
73 if(isSuccess(status)) {
74 Log.d(TAG, "Obtain RESPONSE");
75 String response = get.getResponseBodyAsString();
78 } catch (HttpException e) {
79 result = new RemoteOperationResult(e);
81 } catch (IOException e) {
82 result = new RemoteOperationResult(e);
85 get.releaseConnection();
90 private boolean isSuccess(int status) {
91 return (status == HttpStatus.SC_OK);