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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // AddressSearchService.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon Devik Kim on 22/04/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import Alamofire
  10. class SearchAddressService: SearchAddressServiceType {
  11. // MARK: Properties
  12. // MARK: Initialization
  13. // MARK: Data management
  14. func fetchAddress(
  15. pageIndex: Int,
  16. interval: Int,
  17. keyword: String,
  18. success: @escaping (JusoResult?) -> Void,
  19. failure: @escaping (Error) -> Void
  20. ) {
  21. let params = [
  22. "confmKey":"U01TX0FVVEgyMDE5MDQyMjE2MzU1NzEwODY3MjA=",
  23. "currentPage":"\(pageIndex)",
  24. "countPerPage":"\(interval)",
  25. "keyword":"\(keyword)",
  26. "resultType": "json"
  27. ]
  28. let url = "http://www.juso.go.kr/addrlink/addrEngApi.do"
  29. Alamofire.request(
  30. url,
  31. method: .get,
  32. parameters: params,
  33. encoding: URLEncoding.default
  34. )
  35. .handle(
  36. success: {(response: JusoContainer?) in
  37. if (response?.results?.common?.errorCode ?? "") != "0" {
  38. let error = NSError(
  39. domain: "Search Address",
  40. code: 0,
  41. userInfo: [NSLocalizedDescriptionKey : response?.results?.common?.errorMessage ?? ""]
  42. )
  43. failure(error)
  44. }
  45. success(response?.results)
  46. },
  47. failure: {
  48. failure($0)
  49. }
  50. )
  51. }
  52. }