Guest User

Untitled

a guest
Nov 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. import Foundation
  2. import Alamofire
  3. import MapKit
  4. import CoreLocation
  5.  
  6. enum DoctorRouter: AuthorizedRouter {
  7.  
  8. case list(query: String?, country : Country?, state : State?, city : City?, batch : Batch)
  9. case map ( georegion : CLCircularRegion, query: String?)
  10.  
  11. case details (doctor : Doctor)
  12. case rate (doctor : Doctor, rate: Double)
  13.  
  14. case top (batch : Batch?)
  15.  
  16. /// Locations
  17. case countryList
  18. case stateList(country : Country)
  19. case cityList(country: Country, state: State)
  20. }
  21.  
  22. extension DoctorRouter {
  23.  
  24. func asURLRequest() throws -> URLRequest {
  25.  
  26. switch self {
  27.  
  28. case .list(let query, let country, let state, let city, let batch):
  29.  
  30. let params : [String : Any?] = ["key" : query,
  31. "type" : "doctor",
  32. "country_id" : country?.id,
  33. "state_id" : state?.id,
  34. "city_id" : city?.id,
  35. "count" : batch.limit,
  36. "offset" : batch.offset]
  37.  
  38. return self.authorizedRequest(method: .get,
  39. path: "/commercial/search",
  40. params: params.nullKeyRemoval(),
  41. encoding: URLEncoding.default)
  42.  
  43.  
  44. case .map( let georegion, let query):
  45.  
  46. let params : [String : Any?] = ["latitude" : georegion.center.latitude,
  47. "longitude" : georegion.center.longitude,
  48. "radius" : georegion.radius / 1000,
  49. "key" : query]
  50.  
  51. return self.authorizedRequest(method: .get,
  52. path: "/commercial/doctor/map",
  53. params: params.nullKeyRemoval(),
  54. encoding: URLEncoding.default)
  55.  
  56. case .details (let doctor) :
  57.  
  58. return self.authorizedRequest(method: .get,
  59. path: "/commercial/doctor/\(doctor.id)")
  60.  
  61.  
  62. case .rate (let doctor, let rate) :
  63.  
  64. let params : [String : Any?] = ["rate" : rate]
  65.  
  66. return self.authorizedRequest(method: .post,
  67. path: "/commercial/doctor/like/\(doctor.id)",
  68. params: params.nullKeyRemoval(),
  69. encoding: URLEncoding.default)
  70.  
  71. case .top (let batch):
  72.  
  73. let b = batch ?? Batch(offset: 0, limit: 10)
  74.  
  75. return self.authorizedRequest(method: .get,
  76. path: "/commercial/doctor/top",
  77. params: ["count" : b.limit,
  78. "offset" : b.offset])
  79.  
  80. case .countryList:
  81.  
  82. return self.authorizedRequest(method: .get,
  83. path: "/commercial/country/doctor")
  84. case .stateList(let country):
  85.  
  86. return self.authorizedRequest(method: .get,
  87. path: "/commercial/doctor/state/\(country.id)")
  88.  
  89. case .cityList(let country, let state):
  90.  
  91. return self.authorizedRequest(method: .get,
  92. path: "/commercial/doctor/city/\(country.id)/\(state.id)")
  93.  
  94.  
  95. }
  96. }
  97.  
  98. }
Add Comment
Please, Sign In to add comment