Skip to content

Commit

Permalink
feat(api): request change active entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Hector Rondon authored and ajsb85 committed Oct 27, 2017
1 parent 73d31ec commit 901a22a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 21 additions & 0 deletions Source/GlpiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
12 changes: 8 additions & 4 deletions Source/Routers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -85,6 +87,8 @@ public enum Routers: URLRequestConvertible {
return "/getMyEntities"
case .getActiveEntities:
return "/getActiveEntities"
case .changeActiveEntities:
return "/changeActiveEntities"
case .getFullSession:
return "/getFullSession"
case .getGlpiConfig:
Expand All @@ -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 ""
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 901a22a

Please sign in to comment.