diff --git a/Source/GlpiRequest.swift b/Source/GlpiRequest.swift index 641e2c5..f258e1d 100644 --- a/Source/GlpiRequest.swift +++ b/Source/GlpiRequest.swift @@ -257,6 +257,16 @@ public class GlpiRequest { } } + /** + Request list search option + */ + class public func search(itemType: ItemType, completion: @escaping (_ data: AnyObject?, _ response: HTTPURLResponse?, _ error: Error?) -> Void) { + + GlpiRequest.httpRequest(Routers.search(itemType)) { data, response, error in + completion(data, response, error) + } + } + class func httpRequest(_ router: Routers, completion: @escaping (_ data: AnyObject?, _ response: HTTPURLResponse?, _ error: Error?) -> Void) { let task:URLSessionDataTask = URLSession.shared.dataTask(with: router.request()) { (data, response, error) in diff --git a/Source/Routers.swift b/Source/Routers.swift index bb84bca..acf65de 100644 --- a/Source/Routers.swift +++ b/Source/Routers.swift @@ -67,17 +67,19 @@ public enum Routers: URLRequestDelegate { case deleteItems(ItemType, Int?, QueryString.DeleteItems?, [String: AnyObject]) /// PUT /lostPassword case lostPassword([String: AnyObject]) - /// GET /listSearchOptions + /// GET /listSearchOptions/:itemtype case listSearchOptions(ItemType) + /// GET /search/:itemtype + case search(ItemType) /// get HTTP Method var method: HTTPMethod { switch self { case .initSessionByUserToken, .initSessionByCredentials, .killSession, .getMyProfiles, .getActiveProfile, .getMyEntities, .getActiveEntities, .getFullSession, .getGlpiConfig, - .getMultipleItems, .getAllItems, .getItem, .getSubItems: + .getMultipleItems, .getAllItems, .getItem, .getSubItems, .listSearchOptions, .search: return .get - case .changeActiveProfile, .changeActiveEntities, .addItems, .listSearchOptions: + case .changeActiveProfile, .changeActiveEntities, .addItems: return .post case .updateItems, .lostPassword: return .put @@ -136,6 +138,8 @@ public enum Routers: URLRequestDelegate { return "/lostPassword" case .listSearchOptions(let itemType): return "/listSearchOptions/\(itemType)" + case .search(let itemType): + return "/search/\(itemType)" } } @@ -145,7 +149,7 @@ public enum Routers: URLRequestDelegate { switch self { case .initSessionByUserToken, .initSessionByCredentials, .killSession, .getMyProfiles, .getActiveProfile, .changeActiveProfile, .getMyEntities, .getActiveEntities, .changeActiveEntities, - .getFullSession, .getGlpiConfig, .getMultipleItems, .addItems, .updateItems, .lostPassword, .listSearchOptions: + .getFullSession, .getGlpiConfig, .getMultipleItems, .addItems, .updateItems, .lostPassword, .listSearchOptions, .search: return nil case .getAllItems(_, let queryString): if queryString != nil {