Skip to content

Commit

Permalink
feat(api): request search endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Hector Rondon <hrondon@teclib.com>
  • Loading branch information
Hector Rondon authored and ajsb85 committed Oct 4, 2018
1 parent f1e8a22 commit 0ca4af5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Source/GlpiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions Source/Routers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,6 +138,8 @@ public enum Routers: URLRequestDelegate {
return "/lostPassword"
case .listSearchOptions(let itemType):
return "/listSearchOptions/\(itemType)"
case .search(let itemType):
return "/search/\(itemType)"
}
}

Expand All @@ -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 {
Expand Down

0 comments on commit 0ca4af5

Please sign in to comment.