Skip to content

Commit 901a22a

Browse files
Hector Rondonajsb85
authored andcommitted
feat(api): request change active entities
1 parent 73d31ec commit 901a22a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

Source/GlpiRequest.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,27 @@ public class GlpiRequest {
199199
}
200200
}
201201

202+
/**
203+
Request change active entities
204+
*/
205+
class public func changeActiveEntities(entitiesID: String, isRecursive: Bool = false, completion: @escaping (_ result: Any?) -> Void) {
206+
207+
var dictionary = [String: AnyObject]()
208+
dictionary["is_recursive"] = isRecursive as AnyObject
209+
dictionary["entities_id"] = entitiesID as AnyObject
210+
211+
Alamofire.request(Routers.changeActiveProfile(dictionary))
212+
.validate()
213+
.responseData { response in
214+
switch response.result {
215+
case .success(let result):
216+
completion(result)
217+
case .failure(_ ):
218+
completion(GlpiRequest.handlerError(response.data))
219+
}
220+
}
221+
}
222+
202223
/**
203224
Request get full session information
204225
*/

Source/Routers.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public enum Routers: URLRequestConvertible {
4949
case getMyEntities
5050
/// GET /getActiveEntities
5151
case getActiveEntities
52+
/// POST /changeActiveEntities
53+
case changeActiveEntities([String: AnyObject])
5254
/// GET /getFullSession
5355
case getFullSession
5456
/// GET /getGlpiConfig
@@ -62,7 +64,7 @@ public enum Routers: URLRequestConvertible {
6264
case .initSession, .initSessionByBasicAuth, .killSession, .getMyProfiles, .getActiveProfile,
6365
.getMyEntities, .getActiveEntities, .getFullSession, .getGlpiConfig, .getMultipleItems:
6466
return .get
65-
case .changeActiveProfile:
67+
case .changeActiveProfile, .changeActiveEntities:
6668
return .post
6769
}
6870
}
@@ -85,6 +87,8 @@ public enum Routers: URLRequestConvertible {
8587
return "/getMyEntities"
8688
case .getActiveEntities:
8789
return "/getActiveEntities"
90+
case .changeActiveEntities:
91+
return "/changeActiveEntities"
8892
case .getFullSession:
8993
return "/getFullSession"
9094
case .getGlpiConfig:
@@ -99,8 +103,8 @@ public enum Routers: URLRequestConvertible {
99103

100104
switch self {
101105
case .initSession, .initSessionByBasicAuth, .killSession, .getMyProfiles, .getActiveProfile,
102-
.changeActiveProfile, .getMyEntities, .getActiveEntities, .getFullSession, .getGlpiConfig,
103-
.getMultipleItems:
106+
.changeActiveProfile, .getMyEntities, .getActiveEntities, .changeActiveEntities,
107+
.getFullSession, .getGlpiConfig, .getMultipleItems:
104108
return ""
105109
}
106110
}
@@ -155,7 +159,7 @@ public enum Routers: URLRequestConvertible {
155159
}
156160

157161
switch self {
158-
case .changeActiveProfile(let parameters):
162+
case .changeActiveProfile(let parameters), .changeActiveEntities(let parameters):
159163
return try Alamofire.JSONEncoding.default.encode(urlRequest, with: parameters)
160164
default:
161165
return urlRequest

0 commit comments

Comments
 (0)