diff --git a/Source/GlpiRequest.swift b/Source/GlpiRequest.swift index d5fc57e..ebad5cf 100644 --- a/Source/GlpiRequest.swift +++ b/Source/GlpiRequest.swift @@ -199,6 +199,27 @@ public class GlpiRequest { } } + /** + Request change active entities + */ + class public func changeActiveEntities(entitiesID: String, isRecursive: Bool = false, completion: @escaping (_ result: Any?) -> Void) { + + var dictionary = [String: AnyObject]() + dictionary["is_recursive"] = isRecursive as AnyObject + dictionary["entities_id"] = entitiesID as AnyObject + + Alamofire.request(Routers.changeActiveProfile(dictionary)) + .validate() + .responseData { response in + switch response.result { + case .success(let result): + completion(result) + case .failure(_ ): + completion(GlpiRequest.handlerError(response.data)) + } + } + } + /** Request get full session information */ diff --git a/Source/Routers.swift b/Source/Routers.swift index d9e02a0..0a35d9b 100644 --- a/Source/Routers.swift +++ b/Source/Routers.swift @@ -49,6 +49,8 @@ public enum Routers: URLRequestConvertible { case getMyEntities /// GET /getActiveEntities case getActiveEntities + /// POST /changeActiveEntities + case changeActiveEntities([String: AnyObject]) /// GET /getFullSession case getFullSession /// GET /getGlpiConfig @@ -62,7 +64,7 @@ public enum Routers: URLRequestConvertible { case .initSession, .initSessionByBasicAuth, .killSession, .getMyProfiles, .getActiveProfile, .getMyEntities, .getActiveEntities, .getFullSession, .getGlpiConfig, .getMultipleItems: return .get - case .changeActiveProfile: + case .changeActiveProfile, .changeActiveEntities: return .post } } @@ -85,6 +87,8 @@ public enum Routers: URLRequestConvertible { return "/getMyEntities" case .getActiveEntities: return "/getActiveEntities" + case .changeActiveEntities: + return "/changeActiveEntities" case .getFullSession: return "/getFullSession" case .getGlpiConfig: @@ -99,8 +103,8 @@ public enum Routers: URLRequestConvertible { switch self { case .initSession, .initSessionByBasicAuth, .killSession, .getMyProfiles, .getActiveProfile, - .changeActiveProfile, .getMyEntities, .getActiveEntities, .getFullSession, .getGlpiConfig, - .getMultipleItems: + .changeActiveProfile, .getMyEntities, .getActiveEntities, .changeActiveEntities, + .getFullSession, .getGlpiConfig, .getMultipleItems: return "" } } @@ -155,7 +159,7 @@ public enum Routers: URLRequestConvertible { } switch self { - case .changeActiveProfile(let parameters): + case .changeActiveProfile(let parameters), .changeActiveEntities(let parameters): return try Alamofire.JSONEncoding.default.encode(urlRequest, with: parameters) default: return urlRequest