Browse Source

Init API Get User Profile

Marino Faggiana 8 years ago
parent
commit
3c42f6fd04

+ 19 - 1
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -29,6 +29,7 @@
 @class AFURLSessionManager;
 @class AFSecurityPolicy;
 @class OCCapabilities;
+@class OCUserProfile;
 
 @interface OCCommunication : NSObject
 
@@ -782,7 +783,7 @@ typedef enum {
 
 
 ///-----------------------------------
-/// @name set server Notification
+/// @name Set the server Notification
 ///-----------------------------------
 
 /**
@@ -796,6 +797,23 @@ typedef enum {
 
 - (void) setNotificationServer:(NSString*)serverPath type:(NSString *)type onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
+#pragma mark -  User Profile
+
+///-----------------------------------
+/// @name Get User Profile
+///-----------------------------------
+
+/**
+ * Method read the notification of the server
+ *
+ * @param serverPath            -> NSString server
+ * @param type                  -> NSString "GET"
+ * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
+ *
+ */
+
+- (void) getUserProfileOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+
 @end
 
 

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

@@ -1398,6 +1398,38 @@
     }];
 }
 
+#pragma mark - User Profile
+
+- (void) getUserProfileOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+    
+    serverPath = [serverPath stringByAppendingString:k_url_acces_remote_userprofile_api];
+    serverPath = [serverPath stringByAppendingString:self.user];
+    //serverPath = [NSString stringWithFormat:@"%@ -H \"%@\"",serverPath, @"OCS-APIRequest: true"];
+    //serverPath = [serverPath encodeString:NSUTF8StringEncoding];
+
+    OCWebDAVClient *request = [OCWebDAVClient new];
+    request = [self getRequestWithCredentials:request];
+    
+    [request getUserProfileOfServer: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] User Profile : %@",jsongParsed);
+        
+        OCUserProfile *userProfile;
+        
+        if (jsongParsed.allKeys > 0) {
+
+        }
+        
+    } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
+    
+        failureRequest(response, error, request.redirectedServer);
+    }];
+}
 
 #pragma mark - Clear Cache
 

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

@@ -56,6 +56,9 @@
 //Url to access to Remote Notification API
 #define k_url_acces_remote_notification_api @"ocs/v2.php/apps/notifications/api/v2/notifications"
 
+//Url to access to User Profile API
+#define k_url_acces_remote_userprofile_api @"ocs/v1.php/cloud/users/"
+
 //Version of the server that have share API
 #define k_version_support_shared [NSArray arrayWithObjects:  @"5", @"0", @"27", nil]
 

+ 25 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCUserProfile.h

@@ -0,0 +1,25 @@
+//
+//  OCUserProfile.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 16/02/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OCUserProfile : NSObject
+
+@property double quotaFree;
+@property double quotaUsed;
+@property double quotaTotal;
+@property double quotaRelative;
+@property double quota;
+@property (nonatomic, strong) NSString *email;
+@property (nonatomic, strong) NSString *displayName;
+@property (nonatomic, strong) NSString *phone;
+@property (nonatomic, strong) NSString *address;
+@property (nonatomic, strong) NSString *webpage;
+@property (nonatomic, strong) NSString *twitter;
+
+@end

+ 13 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCUserProfile.m

@@ -0,0 +1,13 @@
+//
+//  OCUserProfile.m
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 16/02/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import "OCUserProfile.h"
+
+@implementation OCUserProfile
+
+@end

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

@@ -499,4 +499,20 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
 
 - (void)setNotificationServer:(NSString * _Nonnull)serverPath type:(NSString * _Nonnull)type onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull))failure;
 
+///-----------------------------------
+/// @name Get User Profile
+///-----------------------------------
+
+/**
+ * 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 userProfile          -> OCUserProfile
+ *
+ */
+
+- (void) getUserProfileOfServer:(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;
+
 @end

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

@@ -653,6 +653,23 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
 }
 
+#pragma mark - Get User Profile
+
+- (void) getUserProfileOfServer:(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 - Manage Redirections
 
 - (void) setRedirectionBlockOnDatataskWithOCCommunication: (OCCommunication *) sharedOCCommunication andSessionManager:(AFURLSessionManager *) sessionManager{

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

@@ -51,6 +51,7 @@
 		F704980D1E369EF6008F5BB6 /* OCNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = F70498081E369EF6008F5BB6 /* OCNotifications.m */; };
 		F704980E1E369EF6008F5BB6 /* OCNotificationsAction.m in Sources */ = {isa = PBXBuildFile; fileRef = F704980A1E369EF6008F5BB6 /* OCNotificationsAction.m */; };
 		F704980F1E369EF6008F5BB6 /* OCRichObjectStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = F704980C1E369EF6008F5BB6 /* OCRichObjectStrings.m */; };
+		F73C00351E56098300EEEFA7 /* OCUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = F73C00341E56098300EEEFA7 /* OCUserProfile.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -144,6 +145,8 @@
 		F704980A1E369EF6008F5BB6 /* OCNotificationsAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCNotificationsAction.m; sourceTree = "<group>"; };
 		F704980B1E369EF6008F5BB6 /* OCRichObjectStrings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCRichObjectStrings.h; sourceTree = "<group>"; };
 		F704980C1E369EF6008F5BB6 /* OCRichObjectStrings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCRichObjectStrings.m; sourceTree = "<group>"; };
+		F73C00331E56098300EEEFA7 /* OCUserProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCUserProfile.h; sourceTree = "<group>"; };
+		F73C00341E56098300EEEFA7 /* OCUserProfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCUserProfile.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -227,6 +230,8 @@
 				EA913A701BE9FB0700D015B8 /* OCCapabilities.h */,
 				EA913A711BE9FB0700D015B8 /* OCCapabilities.m */,
 				EAABAA2F183E687000909831 /* OCFrameworkConstants.h */,
+				F73C00331E56098300EEEFA7 /* OCUserProfile.h */,
+				F73C00341E56098300EEEFA7 /* OCUserProfile.m */,
 				F70498071E369EF6008F5BB6 /* OCNotifications.h */,
 				F70498081E369EF6008F5BB6 /* OCNotifications.m */,
 				F70498091E369EF6008F5BB6 /* OCNotificationsAction.h */,
@@ -443,6 +448,7 @@
 				EAABAA32183E688900909831 /* OCFileDto.m in Sources */,
 				F704980F1E369EF6008F5BB6 /* OCRichObjectStrings.m in Sources */,
 				F704980D1E369EF6008F5BB6 /* OCNotifications.m in Sources */,
+				F73C00351E56098300EEEFA7 /* OCUserProfile.m in Sources */,
 				EA7CC934183E150000B6A4B4 /* OCCommunication.m in Sources */,
 				F704980E1E369EF6008F5BB6 /* OCNotificationsAction.m in Sources */,
 				131C67B9187C3E360009030E /* OCXMLSharedParser.m in Sources */,

+ 1 - 0
iOSClient/CCGlobal.h

@@ -205,6 +205,7 @@ extern NSString *const BKPasscodeKeychainServiceName;
 #define actionGetCapabilities                           @"getCapabilitiesOfServer"
 #define actionGetFeaturesSuppServer                     @"getFeaturesSupportedByServer"
 #define actionGetUserAndGroup                           @"getUserAndGroup"
+#define actionGetUserProfile                            @"getUserProfile"
 #define actionGetNotificationsOfServer                  @"getNotificationsOfServer"
 #define actionSetNotificationServer                     @"setNotificationServer"
 #define actionMoveFileOrFolder                          @"moveFileOrFolder"

+ 5 - 0
iOSClient/Main/CCMain.m

@@ -1159,10 +1159,15 @@
     metadataNet.action = actionGetNotificationsOfServer;
     [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
 
+    metadataNet.action = actionGetUserProfile;
+    [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+    
     metadataNet.action = actionReadFile;
     metadataNet.selector = selectorReadFileQuota;
     metadataNet.serverUrl = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
     [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+    
+    
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 4 - 0
iOSClient/Networking/OCNetworking.h

@@ -99,6 +99,10 @@
 - (void)setNotificationServerSuccess:(CCMetadataNet *)metadataNet;
 - (void)setNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
+// User Profile
+- (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile;
+- (void)getUserProfileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+
 // Search
 
 - (void)searchSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas;

+ 36 - 0
iOSClient/Networking/OCNetworking.m

@@ -1028,6 +1028,42 @@
     }];
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark =====  User Profile =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)getUserProfile
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    
+    [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+    
+    [communication getUserProfileOfServer:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer) {
+        
+        if ([self.delegate respondsToSelector:@selector(getUserProfileSuccess:userProfile:)])
+            [self.delegate getUserProfileSuccess:_metadataNet userProfile:userProfile];
+        
+        [self complete];
+        
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0)
+            errorCode = error.code;
+        
+        if([self.delegate respondsToSelector:@selector(getUserProfileFailure:message:errorCode:)])
+            [self.delegate getUserProfileFailure:_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 =====  Server =====
 #pragma --------------------------------------------------------------------------------------------