From 1d992464f542c8e9c55543e64002be52c49ad186 Mon Sep 17 00:00:00 2001 From: gme_2 Date: Wed, 22 Aug 2018 16:02:56 +0900 Subject: [PATCH] adding protocol --- GMERemittance.xcodeproj/project.pbxproj | 20 ++++++++++++++++ GMERemittance/Api/ApiServiceType.swift | 11 +++++++++ .../Api/ExchangeRateApiService.swift | 21 ++++++++++++++++ GMERemittance/Extension/ExtensionJSON.swift | 24 +++++++++++++++++++ .../Module/ExchangeRateViewControllerV2.swift | 6 ++++- GMERemittance/RestApiManager.swift | 11 +++++---- 6 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 GMERemittance/Api/ApiServiceType.swift create mode 100644 GMERemittance/Api/ExchangeRateApiService.swift create mode 100644 GMERemittance/Extension/ExtensionJSON.swift diff --git a/GMERemittance.xcodeproj/project.pbxproj b/GMERemittance.xcodeproj/project.pbxproj index 69bc66ed..c89992d3 100644 --- a/GMERemittance.xcodeproj/project.pbxproj +++ b/GMERemittance.xcodeproj/project.pbxproj @@ -232,6 +232,9 @@ D962231E212C126500B7A115 /* ExchangeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D962231D212C126500B7A115 /* ExchangeModel.swift */; }; D9638A02212CF30C00B48742 /* CountryFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9638A01212CF30C00B48742 /* CountryFlag.swift */; }; D96848C7212D3A7400EF12B1 /* DataRequestExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D96848C6212D3A7400EF12B1 /* DataRequestExtension.swift */; }; + D96848C9212D3AEB00EF12B1 /* ExtensionJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = D96848C8212D3AEB00EF12B1 /* ExtensionJSON.swift */; }; + D96848CC212D3F2300EF12B1 /* ExchangeRateApiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D96848CB212D3F2300EF12B1 /* ExchangeRateApiService.swift */; }; + D96848CE212D419400EF12B1 /* ApiServiceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D96848CD212D419400EF12B1 /* ApiServiceType.swift */; }; EBFC1719B80F43F88EB01F69 /* Pods_GMERemittanceTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0380AEB198AADC0BC4394515 /* Pods_GMERemittanceTests.framework */; }; FF29296C212B8DFE00FF5BAC /* ExchangeRateCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF29296B212B8DFE00FF5BAC /* ExchangeRateCollectionViewCell.swift */; }; FFD19C7C2112E8F20073689F /* Pods_GMERemittance.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FFD19C7B2112E8F20073689F /* Pods_GMERemittance.framework */; }; @@ -495,6 +498,9 @@ D962231D212C126500B7A115 /* ExchangeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeModel.swift; sourceTree = ""; }; D9638A01212CF30C00B48742 /* CountryFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryFlag.swift; sourceTree = ""; }; D96848C6212D3A7400EF12B1 /* DataRequestExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataRequestExtension.swift; sourceTree = ""; }; + D96848C8212D3AEB00EF12B1 /* ExtensionJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionJSON.swift; sourceTree = ""; }; + D96848CB212D3F2300EF12B1 /* ExchangeRateApiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeRateApiService.swift; sourceTree = ""; }; + D96848CD212D419400EF12B1 /* ApiServiceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiServiceType.swift; sourceTree = ""; }; E4028C5A57499BB54764190C /* Pods_GMERemittanceUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GMERemittanceUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FF29296B212B8DFE00FF5BAC /* ExchangeRateCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeRateCollectionViewCell.swift; sourceTree = ""; }; FFD19C7B2112E8F20073689F /* Pods_GMERemittance.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_GMERemittance.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -631,6 +637,7 @@ 0477E2A420492EDA00B02377 /* LabelExtension.swift */, D962230B212BD7A100B7A115 /* ArrayExtension.swift */, D96848C6212D3A7400EF12B1 /* DataRequestExtension.swift */, + D96848C8212D3AEB00EF12B1 /* ExtensionJSON.swift */, ); path = Extension; sourceTree = ""; @@ -888,6 +895,7 @@ 9FD260F61FD00458007A511D /* GMERemittance */ = { isa = PBXGroup; children = ( + D96848CA212D3F1200EF12B1 /* Api */, D962231C212C123600B7A115 /* Model */, D96222FF212BD5E700B7A115 /* Library */, D907AB96212AA8A300915A87 /* Module */, @@ -1065,6 +1073,15 @@ path = Model; sourceTree = ""; }; + D96848CA212D3F1200EF12B1 /* Api */ = { + isa = PBXGroup; + children = ( + D96848CB212D3F2300EF12B1 /* ExchangeRateApiService.swift */, + D96848CD212D419400EF12B1 /* ApiServiceType.swift */, + ); + path = Api; + sourceTree = ""; + }; FF29296A212B8DE600FF5BAC /* Cell */ = { isa = PBXGroup; children = ( @@ -1533,6 +1550,8 @@ D962230C212BD7A100B7A115 /* ArrayExtension.swift in Sources */, 04B67E922046CA7A000A4248 /* WalletReviewViewController.swift in Sources */, 04B232DF2003732E00736B89 /* RequestNewCodeViewController.swift in Sources */, + D96848CE212D419400EF12B1 /* ApiServiceType.swift in Sources */, + D96848C9212D3AEB00EF12B1 /* ExtensionJSON.swift in Sources */, A24B44FA204CF108009BF491 /* InviteeModel.swift in Sources */, 9FB54C1320088EF7003454E2 /* WithdrawViewController.swift in Sources */, 0496B84E1FE7DFCD0044810E /* UIViewControllerExtension.swift in Sources */, @@ -1634,6 +1653,7 @@ 04CD5395208F0765008F0971 /* UploadImageViewModel.swift in Sources */, A2CB8E592027002E00008EEE /* ExchangeRateViewModel.swift in Sources */, A2B9D7592020C616007C1049 /* MyStoryViewController.swift in Sources */, + D96848CC212D3F2300EF12B1 /* ExchangeRateApiService.swift in Sources */, A2B0DD8E2085AC690074A5BA /* PaymentMethodId.swift in Sources */, 047635AE200B3F1B00E6F4E5 /* MobileRechargeViewModel.swift in Sources */, A2E337992048451E002DB015 /* EarnedViewController.swift in Sources */, diff --git a/GMERemittance/Api/ApiServiceType.swift b/GMERemittance/Api/ApiServiceType.swift new file mode 100644 index 00000000..d93565ea --- /dev/null +++ b/GMERemittance/Api/ApiServiceType.swift @@ -0,0 +1,11 @@ +// +// BaseApi.swift +// GMERemittance +// +// Created by gme_2 on 22/08/2018. +// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. +// + +import Foundation + + diff --git a/GMERemittance/Api/ExchangeRateApiService.swift b/GMERemittance/Api/ExchangeRateApiService.swift new file mode 100644 index 00000000..4132eca4 --- /dev/null +++ b/GMERemittance/Api/ExchangeRateApiService.swift @@ -0,0 +1,21 @@ +// +// ExchangeRateApiService.swift +// GMERemittance +// +// Created by gme_2 on 22/08/2018. +// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. +// + +import Foundation + + +protocol FetchCountryCurrencyInformation { + func fetchCountryCurrencyInfo(success: @escaping ([ExchangeRateData]) -> (), failure: @escaping (Error) -> ()) +} + + +extension FetchCountryCurrencyInformation { + func fetchCountryCurrencyInfo(success: @escaping ([ExchangeRateData]) -> (), failure: @escaping (Error) -> ()) { + + } +} diff --git a/GMERemittance/Extension/ExtensionJSON.swift b/GMERemittance/Extension/ExtensionJSON.swift new file mode 100644 index 00000000..2b98fc95 --- /dev/null +++ b/GMERemittance/Extension/ExtensionJSON.swift @@ -0,0 +1,24 @@ +// +// ExtensionJSON.swift +// GMERemittance +// +// Created by gme_2 on 22/08/2018. +// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. +// + +import Foundation +import SwiftyJSON +import ObjectMapper + +extension JSON { + func map() -> [T]? { + let json = self.array + let mapped: [T]? = json?.compactMap({$0.map()}) + return mapped + } + + func map() -> T? { + let obj: T? = Mapper().map(JSONObject: self.object) + return obj + } +} diff --git a/GMERemittance/Module/ExchangeRateViewControllerV2.swift b/GMERemittance/Module/ExchangeRateViewControllerV2.swift index 26defbb5..6f8f8c0d 100644 --- a/GMERemittance/Module/ExchangeRateViewControllerV2.swift +++ b/GMERemittance/Module/ExchangeRateViewControllerV2.swift @@ -63,6 +63,7 @@ class ExchangeRateViewControllerV2: UIViewController { createTestModel() // todo: show default native country and falg // Do any additional setup after loading the view. + fetchExchangeRateInformation() } @@ -105,13 +106,16 @@ class ExchangeRateViewControllerV2: UIViewController { } - // function + // other function func countrySelected(model: [ExchangeRateModel]) { self.selectedExchageRateModel = model.first print(model.first?.country) // show country with flag. } + private func fetchExchangeRateInformation() { + + } private func setupTargets() { let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(self.showCountryList(_:))) diff --git a/GMERemittance/RestApiManager.swift b/GMERemittance/RestApiManager.swift index 64f8306d..aa709d7e 100644 --- a/GMERemittance/RestApiManager.swift +++ b/GMERemittance/RestApiManager.swift @@ -21,14 +21,15 @@ enum ApiResult { class RestApiMananger { - let manager = Alamofire.SessionManager.default - manager.session.configuration.timeoutIntervalForRequest = 60 - manager.session.configuration.timeoutIntervalForResource = 60 + let manager: SessionManager + static let sharedInstance = RestApiMananger() - private init() { - + init() { + self.manager = Alamofire.SessionManager.default + manager.session.configuration.timeoutIntervalForRequest = 60 + manager.session.configuration.timeoutIntervalForResource = 60 } func getUUID() -> String {