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

//
// ExchangeRateApiService.swift
// GMERemittance
//
// Created by gme_2 on 22/08/2018.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
import Alamofire
protocol FetchCountryCurrencyInformation: ApiServiceType {
func fetchCountryCurrencyInfo(
isAuth: Bool,
success: @escaping ([ExchangeRateModel]?) -> Void,
failure: @escaping (Error) -> Void
)
}
extension FetchCountryCurrencyInformation {
func fetchCountryCurrencyInfo(
isAuth: Bool = true,
success: @escaping ([ExchangeRateModel]?) -> Void,
failure: @escaping (Error) -> Void
) {
APIRouter
.countriesServices
.request(
needsAuthorization: isAuth,
success: { (response: ExchangeRateContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError(domain: "Network", code: 0, message: response.message ?? "")
failure(error)
} else {
let model = response.data
success(model)
}
},
failure: {failure($0)}
)
}
}
protocol getExchangeRateInformation: ApiServiceType {
func getExchangeRateInformation(
isAuth: Bool,
model: ExchangeRateRequestModel,
success: @escaping (ExchangeRateDetailModel?) -> Void,
failure: @escaping (Error) -> Void
)
}
extension getExchangeRateInformation {
func getExchangeRateInformation(
isAuth: Bool = true,
model: ExchangeRateRequestModel,
success: @escaping (ExchangeRateDetailModel?) -> Void,
failure: @escaping (Error) -> Void
) {
APIRouter.calculateDefExRate(model: model)
.request(
needsAuthorization: isAuth,
success: { (response: ExchangeRateDetailContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError(domain: "Network", code: 0, message: response.message ?? "")
failure(error)
} else {
let model = response.data
success(model)
}
},
failure: failure
)
}
}