Skip to content

Commit

Permalink
feat(api): request lost passwords
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 45f797f commit 8f7fdb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Source/GlpiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,25 @@ public class GlpiRequest {
}
}

/**
Request Lost password
*/
class public func lostPassword(email: String, completion: @escaping (_ result: Any?) -> Void) {

var dictionary = [String: AnyObject]()
dictionary["email"] = email as AnyObject

Alamofire.request(Routers.lostPassword(dictionary))
.validate()
.responseJSON { response in
switch response.result {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response.data))
}
}
}

/**
Request get multiple items
Expand Down
10 changes: 7 additions & 3 deletions Source/Routers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public enum Routers: URLRequestConvertible {
case updateItems(ItemType, Int?, [String: AnyObject])
/// DELETE /:itemtype/:id
case deleteItems(ItemType, Int?, QueryString.DeleteItems?, [String: AnyObject])
/// PUT /lostPassword
case lostPassword([String: AnyObject])

/// get HTTP Method
var method: Alamofire.HTTPMethod {
Expand All @@ -79,7 +81,7 @@ public enum Routers: URLRequestConvertible {
return .get
case .changeActiveProfile, .changeActiveEntities, .addItems:
return .post
case .updateItems:
case .updateItems, .lostPassword:
return .put
case .deleteItems:
return .delete
Expand Down Expand Up @@ -132,6 +134,8 @@ public enum Routers: URLRequestConvertible {
} else {
return "/\(itemType)"
}
case .lostPassword:
return "/lostPassword"
}
}

Expand All @@ -141,7 +145,7 @@ public enum Routers: URLRequestConvertible {
switch self {
case .initSession, .initSessionByBasicAuth, .killSession, .getMyProfiles, .getActiveProfile,
.changeActiveProfile, .getMyEntities, .getActiveEntities, .changeActiveEntities,
.getFullSession, .getGlpiConfig, .getMultipleItems, .addItems, .updateItems:
.getFullSession, .getGlpiConfig, .getMultipleItems, .addItems, .updateItems, .lostPassword:
return nil
case .getAllItems(_, let queryString):
if queryString != nil {
Expand Down Expand Up @@ -219,7 +223,7 @@ public enum Routers: URLRequestConvertible {
}

switch self {
case .changeActiveProfile(let parameters), .changeActiveEntities(let parameters), .addItems(_, let parameters), .updateItems(_, _, let parameters):
case .changeActiveProfile(let parameters), .changeActiveEntities(let parameters), .addItems(_, let parameters), .updateItems(_, _, let parameters), .lostPassword(let parameters):
return try Alamofire.JSONEncoding.default.encode(urlRequest, with: parameters)
case .getAllItems, .getAnItem, .getSubItems:
return try URLEncoding.init(destination: .queryString).encode(urlRequest, with: query ?? [String: AnyObject]())
Expand Down

0 comments on commit 8f7fdb0

Please sign in to comment.