41402559aa56a2f1bd18f6565b791a4c65732966
[pub/Android/ownCloud.git] /
1 /* ownCloud Android Library is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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
21 * THE SOFTWARE.
22 *
23 */
24
25 package com.owncloud.android.oc_framework.operations.remote;
26
27 import java.io.IOException;
28 import java.util.ArrayList;
29
30 import org.apache.commons.httpclient.HttpException;
31 import org.apache.commons.httpclient.methods.GetMethod;
32 import org.apache.http.HttpStatus;
33
34 import android.util.Log;
35
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;
40
41 /**
42 * Get the data from the server to know shared files/folders
43 *
44 * @author masensio
45 *
46 */
47
48 public class GetRemoteSharedFilesOperation extends RemoteOperation {
49
50 private static final String TAG = GetRemoteSharedFilesOperation.class.getSimpleName();
51
52 // OCS Route
53 private static final String SHAREAPI_ROUTE ="/ocs/v1.php/apps/files/files_sharing/api/v1/shares";
54
55 private ArrayList<ShareRemoteFile> mSharedFiles; // List of files for result
56
57 public GetRemoteSharedFilesOperation() {
58 // TODO Auto-generated constructor stub
59 }
60
61 @Override
62 protected RemoteOperationResult run(WebdavClient client) {
63 RemoteOperationResult result = null;
64 int status = -1;
65
66 // Get Method
67 GetMethod get = new GetMethod(client.getBaseUri() + SHAREAPI_ROUTE);
68 Log.d(TAG, "URL ------> " + client.getBaseUri() + SHAREAPI_ROUTE);
69
70 // Get the response
71 try{
72 status = client.executeMethod(get);
73 if(isSuccess(status)) {
74 Log.d(TAG, "Obtain RESPONSE");
75 String response = get.getResponseBodyAsString();
76 Log.d(TAG, response);
77 }
78 } catch (HttpException e) {
79 result = new RemoteOperationResult(e);
80 e.printStackTrace();
81 } catch (IOException e) {
82 result = new RemoteOperationResult(e);
83 e.printStackTrace();
84 } finally {
85 get.releaseConnection();
86 }
87 return result;
88 }
89
90 private boolean isSuccess(int status) {
91 return (status == HttpStatus.SC_OK);
92 }
93 }