InKwon James Kim
5 years ago
22 changed files with 514 additions and 168 deletions
-
16GME Remit.xcodeproj/project.pbxproj
-
39GME Remit/APIs/CommonServiceType.swift
-
63GME Remit/APIs/ExchangeRateApiService.swift
-
266GME Remit/APIs/Router/APIRouter.swift
-
2GME Remit/AppDelegate.swift
-
19GME Remit/Models/ExchangeRateRequestModel.swift
-
16GME Remit/Modules/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift
-
28GME Remit/Modules/ForgotPassword/Application Logic/Service/ForgotPasswordServiceType.swift
-
36GME Remit/Modules/Home/Application Logic/Interactor/HomeInteractor.swift
-
40GME Remit/Modules/Home/Application Logic/Service/HomeServiceType.swift
-
45GME Remit/Modules/Login/Application Logic/Service/LoginService.swift
-
4GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientService.swift
-
2GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientServiceType.swift
-
12GME Remit/Modules/RegisterModules/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift
-
11GME Remit/Modules/RegisterModules/Register/Application Logic/Interactor/RegisterInteractor.swift
-
41GME Remit/Modules/RegisterModules/Register/Application Logic/Service/RegisterServiceType.swift
-
14GME Remit/Modules/RewardModules/Redeem/Application Logic/Service/RedeemService.swift
-
4GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractor.swift
-
2GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractorIO.swift
-
2GME Remit/Modules/SplashScreen/Module Interface/SplashScreenModuleInterface.swift
-
4GME Remit/Modules/SplashScreen/User Interface/Presenter/SplashScreenPresenter.swift
-
14GME Remit/Modules/SplashScreen/User Interface/View/SplashScreenViewController.swift
@ -0,0 +1,266 @@ |
|||
// |
|||
// APIRouter.swift |
|||
// GME Remit |
|||
// |
|||
// Created by InKwon James Kim on 09/08/2019. |
|||
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved. |
|||
// |
|||
|
|||
import Foundation |
|||
import Alamofire |
|||
import Localize_Swift |
|||
import ObjectMapper |
|||
|
|||
enum APIRouter: ApiServiceType { |
|||
case accesscode(username: String, password: String) |
|||
case customerProfile(firebaseToken: String) |
|||
case customerRegister(registerModel: RegisterRequestModel, firebaseToken: String) |
|||
case passwordReset(userName: String) |
|||
case validation(userName: String, idNumber: String, idType: String) |
|||
case countriesServices |
|||
case calculateDefExRate(model: ExchangeRateRequestModel) |
|||
case recipientRequirement(country: String) |
|||
} |
|||
|
|||
extension APIRouter { |
|||
private var manager: SessionManager { |
|||
let manager = Alamofire.SessionManager.default |
|||
manager.session.configuration.timeoutIntervalForRequest = 150 |
|||
|
|||
return manager |
|||
} |
|||
|
|||
private var uuid: String { |
|||
guard let uuid = GMEDB.shared.app.string(.uuid) else { |
|||
let uuid = UUID().uuidString |
|||
GMEDB.shared.app.set(uuid, .uuid) |
|||
return uuid |
|||
} |
|||
|
|||
return uuid |
|||
} |
|||
|
|||
private var beforeLoginHeader: [String: String] { |
|||
let currentLanguage = Localize.currentLanguage() |
|||
let lang = Utility.getLanguageHeader(for: currentLanguage) |
|||
let authValue = "172017F9EC11222E8107142733:QRK2UM0Q:\(uuid)".toBase64() |
|||
|
|||
return [ |
|||
"Authorization": "Basic \(authValue)", |
|||
"GME-TOKEN" : "39587YT398@FBQOW8RY3#948R7GB@CNEQW987GF87$TD18$1981..919@@##joghndvberteiru", |
|||
"Content-Type": "application/json", |
|||
"lang" : lang |
|||
] |
|||
} |
|||
|
|||
private var afterLoginHeader: [String: String] { |
|||
let accessCode = GMEDB.shared.user.string(.accessCode) ?? "" |
|||
let currentLanguage = Localize.currentLanguage() |
|||
let lang = Utility.getLanguageHeader(for: currentLanguage) |
|||
|
|||
return [ |
|||
"Authorization": "Bearer " + accessCode, |
|||
"GME-TOKEN" : "39587YT398@FBQOW8RY3#948R7GB@CNEQW987GF87$TD18$1981..919@@##joghndvberteiru", |
|||
"Content-Type": "application/json", |
|||
"clientId": Utility.getMyKftcClientId(), |
|||
"lang" : lang |
|||
] |
|||
} |
|||
|
|||
func request<T: Mappable>( |
|||
encoding: ParameterEncoding = JSONEncoding.default, |
|||
needsAuthorization: Bool = true, |
|||
success: @escaping (T) -> Void, |
|||
failure: @escaping (Error) -> Void |
|||
) { |
|||
guard |
|||
let isReachable = NetworkReachabilityManager()?.isReachable, |
|||
isReachable else { |
|||
let error = NSError( |
|||
domain: "NETWORK_REACHABILITY_DOMAIN", |
|||
code: -99, |
|||
message: "No Internet connection found. Check your connection." |
|||
) |
|||
return failure(error) |
|||
} |
|||
|
|||
manager.request( |
|||
self.endpoint, |
|||
method: self.method, |
|||
parameters: self.parameters, |
|||
encoding: encoding, |
|||
headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader |
|||
).handle(success: success, failure: failure) |
|||
} |
|||
|
|||
func kftcRequest<T: Mappable>( |
|||
method: HTTPMethod, |
|||
header: [String: String], |
|||
url: String, |
|||
params: [String: Any]?, |
|||
encoding: ParameterEncoding = JSONEncoding.default, |
|||
needsAuthorization: Bool = true, |
|||
success: @escaping (T) -> Void, |
|||
failure: @escaping (Error) -> Void |
|||
) { |
|||
guard |
|||
let isReachable = NetworkReachabilityManager()?.isReachable, |
|||
isReachable else { |
|||
let error = NSError( |
|||
domain: "NETWORK_REACHABILITY_DOMAIN", |
|||
code: -99, |
|||
message: "No Internet connection found. Check your connection." |
|||
) |
|||
return failure(error) |
|||
} |
|||
|
|||
manager.request( |
|||
url, |
|||
method: method, |
|||
parameters: params, |
|||
encoding: encoding, |
|||
headers: header |
|||
).handle(success: success, failure: failure) |
|||
|
|||
} |
|||
|
|||
func requestMultipart<T: Mappable>( |
|||
method: HTTPMethod, |
|||
_ URLString: URLConvertible, |
|||
parameters: [String: String]? = nil, |
|||
images: [String: Data], |
|||
encoding: Alamofire.ParameterEncoding = URLEncoding.default, |
|||
needsAuthorization: Bool = true, |
|||
success: @escaping (T)-> Void, |
|||
failure: @escaping (Error) -> Void |
|||
) { |
|||
guard |
|||
let isReachable = NetworkReachabilityManager()?.isReachable, |
|||
isReachable else { |
|||
let error = NSError( |
|||
domain: "NETWORK_REACHABILITY_DOMAIN", |
|||
code: -99, |
|||
message: "No Internet connection found. Check your connection." |
|||
) |
|||
return failure(error) |
|||
} |
|||
|
|||
manager.upload( |
|||
multipartFormData: { multipartFormData in |
|||
if !images.isEmpty { |
|||
images.forEach({ (data) in |
|||
multipartFormData.append(data.value, withName: data.key, fileName: data.key + ".jpeg", mimeType: "image/jpeg") |
|||
}) |
|||
|
|||
} |
|||
parameters?.forEach { (params) in |
|||
multipartFormData.append(params.value.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: params.key) |
|||
} |
|||
}, |
|||
to: URLString, |
|||
method: method, |
|||
headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader, |
|||
encodingCompletion: { encodingResult in |
|||
switch encodingResult { |
|||
case .success(let upload, _, _): |
|||
upload.handle(success: success, failure: failure) |
|||
case .failure: |
|||
let error = NSError( |
|||
domain: "NETWORK_REACHABILITY_DOMAIN", |
|||
code: -99, |
|||
message: "No Internet connection found. Check your connection." |
|||
) |
|||
failure(error) |
|||
} |
|||
} |
|||
) |
|||
} |
|||
} |
|||
|
|||
extension APIRouter { |
|||
private var endpoint: String { |
|||
switch self { |
|||
case .accesscode: return "\(baseUrl)/users/access-code" |
|||
case .customerProfile: return "\(baseUrl)/mobile/CustomerProfile" |
|||
case .customerRegister: return "\(baseUrlWithoutVersion)/v3/mobile/customerRegister" |
|||
case .passwordReset: return "\(baseUrl)/mobile/passwordReset" |
|||
case .validation: return "\(baseUrlWithoutVersion)/v3/validation" |
|||
case .countriesServices: return "\(baseUrl)/mobile/countriesServices" |
|||
case .calculateDefExRate: return "\(baseUrl)/mobile/calculateDefExRate" |
|||
case .recipientRequirement(let country): return "\(country)" |
|||
} |
|||
} |
|||
|
|||
private var method: HTTPMethod { |
|||
switch self { |
|||
case .accesscode: return .post |
|||
case .customerProfile: return .post |
|||
case .customerRegister: return .post |
|||
case .passwordReset: return .post |
|||
case .validation: return .post |
|||
case .countriesServices: return .get |
|||
case .calculateDefExRate: return .post |
|||
case .recipientRequirement: return .get |
|||
} |
|||
} |
|||
|
|||
private var parameters: Parameters? { |
|||
switch self { |
|||
case .accesscode(let username, let password): |
|||
return [ |
|||
"userId": username, |
|||
"password": password |
|||
] |
|||
|
|||
case .customerProfile(let firebaseToken): |
|||
return [ |
|||
"userId" : Utility.getMyUserName(), |
|||
"uuid": self.uuid, |
|||
"appVersion": Utility.getAppVersion() ?? "", |
|||
"phoneBrand": Utility.getPhoneBrand(), |
|||
"phoneOs": Utility.getPhoneOs(), |
|||
"fcmId": firebaseToken, |
|||
"osVersion": Utility.getOsVersion() |
|||
] |
|||
|
|||
case .customerRegister(let registerModel, let firebaseToken): |
|||
return [ |
|||
"username": registerModel.username ?? "", |
|||
"password": registerModel.encryptedPassword ?? "", |
|||
"nativecountry": registerModel.nativeCountry ?? "", |
|||
"mobilenumber": registerModel.mobileNumber ?? "", |
|||
"clientId": Utility.getCliendId(), |
|||
"uuid": self.uuid, |
|||
"appVersion": Utility.getAppVersion() ?? "", |
|||
"phoneBrand": Utility.getPhoneBrand(), |
|||
"phoneOs": Utility.getPhoneOs(), |
|||
"fcmId": firebaseToken, |
|||
"osVersion": Utility.getOsVersion() |
|||
] |
|||
|
|||
case .passwordReset(let userName): |
|||
return ["username": userName] |
|||
|
|||
case .validation(let userName, let idNumber, let idType): |
|||
return [ |
|||
"Username": userName, |
|||
"IdNumber": idNumber, |
|||
"IdType": idType |
|||
] |
|||
case .countriesServices: return nil |
|||
case .calculateDefExRate(let model): |
|||
return [ |
|||
"cAmount" : model.senderAmount, |
|||
"sCurrency" : model.senderCurrency, |
|||
"pAmount" : model.recipientAmount, |
|||
"pCurrency" : model.recipientCurrency, |
|||
"pCountry" : model.recipientCountryID, |
|||
"serviceType": model.serviceType, |
|||
"calcBy" : model.calcBy, |
|||
"sCountry" : model.senderCountryID, |
|||
"pCountryName": model.recipientCountry |
|||
] |
|||
case .recipientRequirement: return nil |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
// |
|||
// ExchangeRateRequestModel.swift |
|||
// GME Remit |
|||
// |
|||
// Created by InKwon James Kim on 12/08/2019. |
|||
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved. |
|||
// |
|||
|
|||
struct ExchangeRateRequestModel { |
|||
let senderAmount: String |
|||
let senderCurrency: String |
|||
let senderCountryID: String |
|||
let recipientAmount: String |
|||
let recipientCurrency: String |
|||
let recipientCountryID: String |
|||
let recipientCountry: String |
|||
let serviceType: String |
|||
let calcBy: String |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue