Browse Source

Search API

Marino Faggiana 8 years ago
parent
commit
55d73ef1d9

+ 2 - 24
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -464,33 +464,11 @@ typedef enum {
 /// @name Search
 ///-----------------------------------
 
-/**
- * Block to get the list of files/folders for a path
- *
- * @param path -> NSString with the url of the path
- * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
- *
- * @param token -> User Session token. To get this token you should be use "getUserSessionToken" method of UtilsFramework class
- *  We use this token to be sure that the callbacks of the request are for the correct user. We need that when we use multiaccount.
- *  if not you can leave as nil.
- *
- * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
- *
- * @warning the "path" must not be on URL Encoding.
- * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other Folder/Music
- * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other%20Folder/Music
- *
- * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
- *
- */
-
-- (void) search: (NSString *) path fileName:(NSString *)fileName depth:(NSString *)depth withUserSessionToken:(NSString *)token
-    onCommunication:(OCCommunication *)sharedOCCommunication
-     successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
-     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
+- (void)search:(NSString *)path fileName:(NSString *)fileName depth:(NSString *)depth withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
 
 
 #pragma mark - OC API Calls
+
 ///-----------------------------------
 /// @name getCurrentServerVersion
 ///-----------------------------------

+ 1 - 5
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -617,10 +617,7 @@
 ///-----------------------------------
 /// @name search
 ///-----------------------------------
-- (void) search: (NSString *) path fileName:(NSString *)fileName depth:(NSString *)depth withUserSessionToken:(NSString *)token
-    onCommunication:(OCCommunication *)sharedOCCommunication
-     successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
-     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
+- (void)search:(NSString *)path fileName:(NSString *)fileName depth:(NSString *)depth withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
     
     if (!token){
         token = @"no token";
@@ -649,7 +646,6 @@
         
         NSLog(@"Failure");
         failureRequest(response, error, token, request.redirectedServer);
-        
     }];
 }
 

+ 4 - 5
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -180,12 +180,11 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
          success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nonnull, NSString * _Nonnull token))success
          failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull, NSString * _Nonnull token))failure;
 
+/**
+ 
+*/ 
 
-
-- (void)search:(NSString * _Nonnull)path fileName:(NSString * _Nonnull)fileName depth:(NSString * _Nonnull)depth user:(NSString * _Nonnull)user
- onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication withUserSessionToken:(NSString * _Nonnull)token
-         success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nonnull, NSString * _Nonnull token))success
-         failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull, NSString * _Nonnull token))failure;
+- (void)search:(NSString * _Nonnull)path fileName:(NSString * _Nonnull)fileName depth:(NSString * _Nonnull)depth user:(NSString * _Nonnull)user onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication withUserSessionToken:(NSString * _Nonnull)token success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nonnull, NSString * _Nonnull token))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull, NSString * _Nonnull token))failure;
 
 /**
  Creates an `NSURLSessionDownloadTask` with the specified request for a local file.

+ 17 - 25
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -258,26 +258,6 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
 }
 
-- (void)mr_search:(NSString *)path fileName:(NSString *)fileName depth:(NSString *)depth user:(NSString *)user withUserSessionToken:(NSString*)token onCommunication:
-(OCCommunication *)sharedOCCommunication
-            success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success
-            failure:(void(^)(NSHTTPURLResponse *response, id  _Nullable responseObject, NSError *, NSString *token))failure {
-    NSParameterAssert(success);
-    
-    _requestMethod = @"SEARCH";
-    NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil];
-    
-    NSString *body = [NSString stringWithFormat:@"<?xml version=\"1.0\"?><d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\"><d:basicsearch><d:select><d:prop><d:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/%@</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:like><d:prop><d:displayname/></d:prop><d:literal>%@</d:literal></d:like></d:where></d:basicsearch></d:searchrequest>", user, fileName];
-    
-    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
-    
-    [request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
-    
-    OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
-    [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-    [operation resume];
-}
-
 - (void)propertiesOfPath:(NSString *)path
          onCommunication: (OCCommunication *)sharedOCCommunication
                  success:(void(^)(NSHTTPURLResponse *, id ))success
@@ -299,11 +279,23 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [self mr_listPath:path depth:1 withUserSessionToken:token onCommunication:sharedOCCommunication success:success failure:failure];
 }
 
-- (void)search:(NSString *)path fileName:(NSString *)fileName depth:(NSString *)depth user:(NSString *)user
- onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token
-         success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success
-         failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *, NSString *token))failure {
-    [self mr_search:path fileName:fileName depth:depth user:user withUserSessionToken:token onCommunication:sharedOCCommunication success:success failure:failure];
+- (void)search:(NSString *)path fileName:(NSString *)fileName depth:(NSString *)depth user:(NSString *)user onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *, NSString *token))failure {
+    
+    NSParameterAssert(success);
+    
+    _requestMethod = @"SEARCH";
+    
+    NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil];
+    
+    NSString *body = [NSString stringWithFormat:@"<?xml version=\"1.0\"?><d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\"><d:basicsearch><d:select><d:prop><d:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/%@</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:like><d:prop><d:displayname/></d:prop><d:literal>%@</d:literal></d:like></d:where></d:basicsearch></d:searchrequest>", user, fileName];
+    
+    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
+    
+    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
+    
+    OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
+    [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
+    [operation resume];
 }
 
 - (NSURLSessionDownloadTask *)downloadWithSessionPath:(NSString *)remoteSource toPath:(NSString *)localDestination defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress success:(void(^)(NSURLResponse *response, NSURL *filePath))success failure:(void(^)(NSURLResponse *response, NSError *error))failure{