You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.3 KiB

6 years ago
6 years ago
  1. //
  2. // ReciepientServcie.swift
  3. // GMERemittance
  4. //
  5. // Created by ccr on 26/08/2018.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import Alamofire
  10. protocol FetchRecipientList: ApiServiceType {
  11. func fetchReciepientList(username: String, success: @escaping ([Recipient]) -> (), failure: @escaping (Error) -> ())
  12. }
  13. //http://localhost:9500/api/v1/mobile/sisir@mailinator.com/receivers?search=
  14. extension FetchRecipientList {
  15. func fetchReciepientList(username: String, success: @escaping ([Recipient]) -> (), failure: @escaping (Error) -> ()) {
  16. let url = baseUrl + "mobile/" + username + "/receivers"
  17. let params = ["search": ""]
  18. auth.request(method: .get, url: url, params: params, encoding: URLEncoding.default, success: { (response: RecipientListContainer) in
  19. if (response.errorCode ?? "") == "1" {
  20. let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
  21. failure(error)
  22. }else {
  23. let model = response.data
  24. success(model)
  25. }
  26. }) { (error) in
  27. failure(error)
  28. }
  29. }
  30. }
  31. //http://localhost:9500/api/v1/mobile/receiver/remove/sisir@mailinator.com/?receiverId=143313
  32. protocol DeleteRecipientService: ApiServiceType {
  33. func deleteRecipient(username: String, reciepient: Recipient, success: @escaping (Recipient?) -> (), failure: @escaping (Error) -> ())
  34. }
  35. extension DeleteRecipientService {
  36. func deleteRecipient(username: String, reciepient: Recipient, success: @escaping (Recipient?) -> (), failure: @escaping (Error) -> ()) {
  37. let url = baseUrl + "mobile/receiver/remove/" + username + "/?receiverId=\(reciepient.recipientId ?? "")"
  38. auth.request(method: .post, url: url, params: nil, encoding: URLEncoding.default, success: { (response: RecipientContainer) in
  39. if (response.errorCode ?? "") == "1" {
  40. let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
  41. failure(error)
  42. }else {
  43. let model = response.data
  44. success(model)
  45. }
  46. }) { (error) in
  47. failure(error)
  48. }
  49. }
  50. }