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.
61 lines
1.4 KiB
61 lines
1.4 KiB
//
|
|
// AddressSearchService.swift
|
|
// GME Remit
|
|
//
|
|
// Created by InKwon Devik Kim on 22/04/2019.
|
|
//Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Alamofire
|
|
|
|
class SearchAddressService: SearchAddressServiceType {
|
|
|
|
// MARK: Properties
|
|
|
|
// MARK: Initialization
|
|
|
|
// MARK: Data management
|
|
|
|
func fetchAddress(
|
|
pageIndex: Int,
|
|
interval: Int,
|
|
keyword: String,
|
|
success: @escaping (JusoResult?) -> Void,
|
|
failure: @escaping (Error) -> Void
|
|
) {
|
|
|
|
let params = [
|
|
"confmKey":"U01TX0FVVEgyMDE5MDQyMjE2MzU1NzEwODY3MjA=",
|
|
"currentPage":"\(pageIndex)",
|
|
"countPerPage":"\(interval)",
|
|
"keyword":"\(keyword)",
|
|
"resultType": "json"
|
|
]
|
|
let url = "http://www.juso.go.kr/addrlink/addrEngApi.do"
|
|
|
|
Alamofire.request(
|
|
url,
|
|
method: .get,
|
|
parameters: params,
|
|
encoding: URLEncoding.default
|
|
)
|
|
.handle(
|
|
success: {(response: JusoContainer?) in
|
|
if (response?.results?.common?.errorCode ?? "") != "0" {
|
|
let error = NSError(
|
|
domain: "Search Address",
|
|
code: 0,
|
|
userInfo: [NSLocalizedDescriptionKey : response?.results?.common?.errorMessage ?? ""]
|
|
)
|
|
failure(error)
|
|
}
|
|
|
|
success(response?.results)
|
|
},
|
|
failure: {
|
|
failure($0)
|
|
}
|
|
)
|
|
}
|
|
}
|