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.

74 lines
2.0 KiB

6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // ExchangeRateApiService.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 22/08/2018.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import Alamofire
  10. protocol FetchCountryCurrencyInformation: ApiServiceType {
  11. func fetchCountryCurrencyInfo(
  12. isAuth: Bool,
  13. success: @escaping ([ExchangeRateModel]?) -> Void,
  14. failure: @escaping (Error) -> Void
  15. )
  16. }
  17. extension FetchCountryCurrencyInformation {
  18. func fetchCountryCurrencyInfo(
  19. isAuth: Bool = true,
  20. success: @escaping ([ExchangeRateModel]?) -> Void,
  21. failure: @escaping (Error) -> Void
  22. ) {
  23. APIRouter
  24. .countriesServices
  25. .request(
  26. needsAuthorization: isAuth,
  27. success: { (response: ExchangeRateContainer) in
  28. if (response.errorCode ?? "") == "1" {
  29. let error = NSError(domain: "Network", code: 0, message: response.message ?? "")
  30. failure(error)
  31. } else {
  32. let model = response.data
  33. success(model)
  34. }
  35. },
  36. failure: {failure($0)}
  37. )
  38. }
  39. }
  40. protocol getExchangeRateInformation: ApiServiceType {
  41. func getExchangeRateInformation(
  42. isAuth: Bool,
  43. model: ExchangeRateRequestModel,
  44. success: @escaping (ExchangeRateDetailModel?) -> Void,
  45. failure: @escaping (Error) -> Void
  46. )
  47. }
  48. extension getExchangeRateInformation {
  49. func getExchangeRateInformation(
  50. isAuth: Bool = true,
  51. model: ExchangeRateRequestModel,
  52. success: @escaping (ExchangeRateDetailModel?) -> Void,
  53. failure: @escaping (Error) -> Void
  54. ) {
  55. APIRouter.calculateDefExRate(model: model)
  56. .request(
  57. needsAuthorization: isAuth,
  58. success: { (response: ExchangeRateDetailContainer) in
  59. if (response.errorCode ?? "") == "1" {
  60. let error = NSError(domain: "Network", code: 0, message: response.message ?? "")
  61. failure(error)
  62. } else {
  63. let model = response.data
  64. success(model)
  65. }
  66. },
  67. failure: failure
  68. )
  69. }
  70. }