Skip to content

Commit

Permalink
Feat: Implement fetching base url from firebase #94
Browse files Browse the repository at this point in the history
  • Loading branch information
jinios committed Oct 13, 2019
1 parent eabdcb7 commit 951ce2c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
51 changes: 51 additions & 0 deletions MartHoliday/MartHoliday/Model/DataSetter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,56 @@ class DataSetter<T: URLHolder, U: Codable> {
}
}.resume()
}


static func request(url: URL?, handler: @escaping(() -> ())) {
guard let url = url else { return }

let configure = URLSessionConfiguration.default
configure.timeoutIntervalForRequest = 15
let session = URLSession(configuration: configure)

session.dataTask(with: url) { (data, response, error) in

var branches = [BranchRawData]()
if let response = response as? HTTPURLResponse, 200...299 ~= response.statusCode, let data = data {
do {
branches = try JSONDecoder().decode([BranchRawData].self, from: data, keyPath: "data") as! [BranchRawData]
handler()
} catch {
handler()
}
} else {
handler()
}
}.resume()

}
}

struct APIHelper {

enum RequestType {
case martType
case branches(Mart)
case allMarts

var componentText: String {
switch self {
case .martType: return "marts/types"
case .allMarts: return "marts"
case .branches(let mart):
return "marts/types/\(mart.pathComponent)"
}
}

}

static func url(path: RequestType, parameters: [String:String]?) -> URL? {
guard let baseUrl = RemoteConfigManager.shared().baseURL else { return nil }
let requestUrl = baseUrl.appendingPathComponent(path.componentText)

return requestUrl
}

}
2 changes: 1 addition & 1 deletion MartHoliday/MartHoliday/Model/RemoteConfigManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RemoteConfigManager: NSObject {

let appConfig = AppConfig(status: updateStatus, min: min, latest: latest)
let configResult = appConfig.compare()
self.setBaseURL(url: remoteConfig[RemoteConfigKey.baseURL.rawValue].stringValue)
// self.setBaseURL(url: remoteConfig[RemoteConfigKey.baseURL.rawValue].stringValue)
handler(configResult)
} else {
// fetch 실패시 앱 실행
Expand Down
12 changes: 8 additions & 4 deletions MartHoliday/MartHoliday/Model/StorageAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ class StorageAPI {
let pathReference = storage.reference(forURL: urlStr)

// Download in memory with a maximum allowed size of 1KB (1 * 1024 bytes)
pathReference.getData(maxSize: 100 * 1024) { data, _ in
guard let data = data else { return }
guard let content = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return }
handler(content)
pathReference.getData(maxSize: 100 * 1024) { data, err in
if let err = err {
print(err)
} else {
guard let data = data else { return }
guard let content = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return }
handler(content)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MainViewController: RechabilityDetectViewController, FavoriteConvertible,
slideMenu.dataSource = slideMenuManager
slideOpenFlag = false
tableView.delaysContentTouches = false
setNaviBarButton()
// setNaviBarButton()

addGestures()
NotificationCenter.default.addObserver(self, selector: #selector(detectSelectedMenu(_:)), name: .slideMenuTapped, object: nil)
Expand Down Expand Up @@ -101,6 +101,7 @@ class MainViewController: RechabilityDetectViewController, FavoriteConvertible,
navigationItem.leftBarButtonItem = searhButton
}

// 상단 편집버튼
private func setNaviBarButton() {
let settingButton = UIButton(type: .custom)

Expand Down

0 comments on commit 951ce2c

Please sign in to comment.