Parcourir la source

https://github.com/nextcloud/ios/issues/129

Marino Faggiana il y a 8 ans
Parent
commit
5a6b55000a

+ 18 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -862,6 +862,24 @@ typedef enum {
 
 - (void) getActivityServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfActivity, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
+#pragma mark -  External Sites
+
+///-----------------------------------
+/// @name Get the list of External sites
+///-----------------------------------
+
+/**
+ * Method read the notification of the server
+ *
+ * @param serverPath            -> NSString server
+ * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
+ *
+ * @return listOfExternalSites  -> OCExternalSites
+ *
+ */
+
+- (void) getExternalSitesServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfExternalSites, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+
 #pragma mark -  User Profile
 
 ///-----------------------------------

+ 73 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -48,6 +48,7 @@
 #import "AFURLSessionManager.h"
 #import "OCShareUser.h"
 #import "OCActivity.h"
+#import "OCExternalSites.h"
 #import "OCCapabilities.h"
 #import "OCNotifications.h"
 #import "OCNotificationsAction.h"
@@ -1631,6 +1632,78 @@
     }];
 }
 
+
+#pragma mark - External sites
+
+- (void) getExternalSitesServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfExternalSites, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+    serverPath = [serverPath encodeString:NSUTF8StringEncoding];
+    serverPath = [serverPath stringByAppendingString:k_url_acces_external_sites_api];
+    
+    OCWebDAVClient *request = [OCWebDAVClient new];
+    request = [self getRequestWithCredentials:request];
+    
+    [request getExternalSitesServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
+        
+        NSData *responseData = (NSData*) responseObject;
+        
+        //Parse
+        NSError *error;
+        NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
+        NSLog(@"[LOG] Activity : %@",jsongParsed);
+        
+        NSMutableArray *listOfExternalSites = [NSMutableArray new];
+        
+        if (jsongParsed.allKeys > 0) {
+            
+            NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
+            NSDictionary *meta = [ocs valueForKey:@"meta"];
+            NSDictionary *datas = [ocs valueForKey:@"data"];
+            
+            NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
+            
+            if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
+                
+                for (NSDictionary *data in datas) {
+                    
+                    OCActivity *activity = [OCActivity new];
+                    
+                    activity.idActivity = [[data valueForKey:@"id"] integerValue];
+                    
+                    NSString *dateString = [data valueForKey:@"date"];
+                    NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init];
+                    activity.date = [formatter dateFromString:dateString];
+                    
+                    if ([data valueForKey:@"file"]    && ![[data valueForKey:@"file"]    isEqual:[NSNull null]]) activity.file    = [data valueForKey:@"file"];
+                    if ([data valueForKey:@"link"]    && ![[data valueForKey:@"link"]    isEqual:[NSNull null]]) activity.link    = [data valueForKey:@"link"];
+                    if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]]) activity.message = [data valueForKey:@"message"];
+                    if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]]) activity.subject = [data valueForKey:@"subject"];
+                    
+                    [listOfExternalSites addObject:activity];
+                }
+                
+            } else {
+                
+                NSString *message = (NSString*)[meta objectForKey:@"message"];
+                
+                if ([message isKindOfClass:[NSNull class]]) {
+                    message = @"";
+                }
+                
+                NSError *error = [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message];
+                failureRequest(response, error, request.redirectedServer);
+            }
+        }
+        
+        //Return success
+        successRequest(response, listOfExternalSites, request.redirectedServer);
+        
+    } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
+        failureRequest(response, error, request.redirectedServer);
+    }];
+}
+
+
+
 #pragma mark - User Profile
 
 - (void) getUserProfileServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {

+ 34 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCExternalSites.h

@@ -0,0 +1,34 @@
+//
+//  OCExternalSites.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 22/03/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OCExternalSites : NSObject
+
+@property NSInteger idExternalSites;
+@property (nonatomic, strong) NSString *name;
+@property (nonatomic, strong) NSString *url;
+@property (nonatomic, strong) NSString *lang;
+@property (nonatomic, strong) NSString *icon;
+
+@end

+ 44 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCExternalSites.m

@@ -0,0 +1,44 @@
+//
+//  OCExternalSites.m
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 22/03/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#import "OCExternalSites.h"
+
+@implementation OCExternalSites
+
+- (id)init {
+    
+    self = [super init];
+    
+    if (self) {
+        
+        self.idExternalSites = 0;
+        self.name = @"";
+        self.url = @"";
+        self.lang = @"";
+        self.icon = @"";
+    }
+    
+    return self;
+}
+
+@end

+ 3 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCFrameworkConstants.h

@@ -62,6 +62,9 @@
 //Url to access to Remote Activity API
 #define k_url_acces_remote_activity_api @"ocs/v2.php/cloud/activity"
 
+//Url to access to External sites API
+#define k_url_acces_external_sites_api @"ocs/v2.php/apps/external/api/v1"
+
 //Url to access to User Profile API
 #define k_url_acces_remote_userprofile_api @"ocs/v1.php/cloud/users/"
 

+ 16 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -561,6 +561,22 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
 
 - (void) getActivityServer:(NSString * _Nonnull)serverPath onCommunication:(OCCommunication * _Nonnull)sharedOCComunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id  _Nullable responseObject, NSError * _Nonnull error))failure;
 
+///-----------------------------------
+/// @name Get the list of External sites
+///-----------------------------------
+
+/**
+ * Method read the notification of the server
+ *
+ * @param serverPath            -> NSString server
+ * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
+ *
+ * @return listOfExternalSites  -> OCExternalSites
+ *
+ */
+
+- (void) getExternalSitesServer:(NSString * _Nonnull)serverPath onCommunication:(OCCommunication * _Nonnull)sharedOCComunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id  _Nullable responseObject, NSError * _Nonnull error))failure;
+
 ///-----------------------------------
 /// @name Get User Profile
 ///-----------------------------------

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

@@ -800,6 +800,23 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
 }
 
+#pragma mark - Get External sites
+
+- (void) getExternalSitesServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success
+                   failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure{
+    
+    _requestMethod = @"GET";
+    
+    NSString *jsonQuery = [NSString stringWithFormat:@"?format=json"];    
+    serverPath = [serverPath stringByAppendingString:jsonQuery];
+    
+    NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];
+    
+    OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
+    [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
+    [operation resume];
+}
+
 #pragma mark - Get User Profile
 
 - (void) getUserProfileServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success

+ 6 - 0
Libraries external/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj

@@ -49,6 +49,7 @@
 		F704980F1E369EF6008F5BB6 /* OCRichObjectStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = F704980C1E369EF6008F5BB6 /* OCRichObjectStrings.m */; };
 		F73C00351E56098300EEEFA7 /* OCUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = F73C00341E56098300EEEFA7 /* OCUserProfile.m */; };
 		F785C1341E6316A500469BAC /* OCXMLListParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F785C1331E6316A500469BAC /* OCXMLListParser.m */; };
+		F7E7D4B61E826FA000315A90 /* OCExternalSites.m in Sources */ = {isa = PBXBuildFile; fileRef = F7E7D4B51E826FA000315A90 /* OCExternalSites.m */; };
 		F7FB5F171E66E63B00389481 /* OCActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = F7FB5F161E66E63B00389481 /* OCActivity.m */; };
 /* End PBXBuildFile section */
 
@@ -140,6 +141,8 @@
 		F73C00341E56098300EEEFA7 /* OCUserProfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCUserProfile.m; sourceTree = "<group>"; };
 		F785C1321E6316A500469BAC /* OCXMLListParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OCXMLListParser.h; path = OCWebDavClient/Parsers/OCXMLListParser.h; sourceTree = "<group>"; };
 		F785C1331E6316A500469BAC /* OCXMLListParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OCXMLListParser.m; path = OCWebDavClient/Parsers/OCXMLListParser.m; sourceTree = "<group>"; };
+		F7E7D4B41E826FA000315A90 /* OCExternalSites.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCExternalSites.h; sourceTree = "<group>"; };
+		F7E7D4B51E826FA000315A90 /* OCExternalSites.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCExternalSites.m; sourceTree = "<group>"; };
 		F7FB5F151E66E63B00389481 /* OCActivity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCActivity.h; sourceTree = "<group>"; };
 		F7FB5F161E66E63B00389481 /* OCActivity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCActivity.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -219,6 +222,8 @@
 			children = (
 				F7FB5F151E66E63B00389481 /* OCActivity.h */,
 				F7FB5F161E66E63B00389481 /* OCActivity.m */,
+				F7E7D4B41E826FA000315A90 /* OCExternalSites.h */,
+				F7E7D4B51E826FA000315A90 /* OCExternalSites.m */,
 				EAABAA30183E688900909831 /* OCFileDto.h */,
 				EAABAA31183E688900909831 /* OCFileDto.m */,
 				EA0599981BB96D14002C2864 /* OCShareUser.h */,
@@ -422,6 +427,7 @@
 				F704980D1E369EF6008F5BB6 /* OCNotifications.m in Sources */,
 				F73C00351E56098300EEEFA7 /* OCUserProfile.m in Sources */,
 				EA7CC934183E150000B6A4B4 /* OCCommunication.m in Sources */,
+				F7E7D4B61E826FA000315A90 /* OCExternalSites.m in Sources */,
 				F704980E1E369EF6008F5BB6 /* OCNotificationsAction.m in Sources */,
 				131C67B9187C3E360009030E /* OCXMLSharedParser.m in Sources */,
 				13AA8640187C3B9700A10927 /* OCXMLParser.m in Sources */,

+ 1 - 0
iOSClient/CCGlobal.h

@@ -186,6 +186,7 @@ extern NSString *const urlBaseUploadDB;
 #define actionGetUserProfile                            @"getUserProfile"
 #define actionGetNotificationServer                     @"getNotificationServer"
 #define actionSetNotificationServer                     @"setNotificationServer"
+#define actionGetExternalSitesServer                    @"getExternalSitesServer"
 #define actionListingFavorites                          @"listingFavorites"
 #define actionMoveFileOrFolder                          @"moveFileOrFolder"
 #define actionReadFile                                  @"readFile"

+ 4 - 0
iOSClient/Networking/OCNetworking.h

@@ -95,6 +95,10 @@
 - (void)getActivityServerSuccess:(NSArray *)listOfActivity;
 - (void)getActivityServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
+// External Sites
+- (void)getExternalSitesServerSuccess:(NSArray *)listOfExternalSites;
+- (void)getExternalSitesServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+
 // Notification
 - (void)getNotificationServerSuccess:(NSArray *)listOfNotifications;
 - (void)getNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;

+ 36 - 0
iOSClient/Networking/OCNetworking.m

@@ -1137,6 +1137,42 @@
     }];
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== External Sites =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)getExternalSitesServer
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    
+    [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+    
+    [communication getExternalSitesServer:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *listOfExternalSites, NSString *redirectedServer) {
+        
+        if ([self.delegate respondsToSelector:@selector(getExternalSitesServerSuccess:)])
+            [self.delegate getExternalSitesServerSuccess:listOfExternalSites];
+        
+        [self complete];
+        
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0)
+            errorCode = error.code;
+        
+        if([self.delegate respondsToSelector:@selector(getExternalSitesServerFailure:message:errorCode:)])
+            [self.delegate getExternalSitesServerFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+        
+        // Request trusted certificated
+        if ([error code] == NSURLErrorServerCertificateUntrusted)
+            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
+        
+        [self complete];
+    }];
+
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Notification =====
 #pragma --------------------------------------------------------------------------------------------