Skip to content

Commit 10e5f7c

Browse files
committed
Added host option
Added the ability to specify a custom host for the server API.
1 parent bfc3ff5 commit 10e5f7c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

MapboxGeocoder/MBGeocoder.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@ public class MBGeocoder: NSObject {
1616

1717
private let configuration: MBGeocoderConfiguration
1818

19-
public init(accessToken: String) {
20-
configuration = MBGeocoderConfiguration(accessToken)
19+
/**
20+
Initializes a newly created geocoder with the given access token and an optional host.
21+
22+
- param accessToken: A Mapbox access token.
23+
- param host: An optional hostname to the server API. The Mapbox Geocoding API endpoint is used by default.
24+
*/
25+
public init(accessToken: String, host: String? = nil) {
26+
let baseURLComponents = NSURLComponents()
27+
baseURLComponents.scheme = "https"
28+
baseURLComponents.host = host
29+
configuration = MBGeocoderConfiguration(accessToken, apiEndpoint: baseURLComponents.string)
2130
}
2231

2332
private var task: NSURLSessionDataTask?

MapboxGeocoder/MBGeocoderConfiguration.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ internal struct MBGeocoderConfiguration: Configuration {
55
internal var apiEndpoint: String = "https://api.mapbox.com"
66
internal var accessToken: String?
77

8-
internal init(_ accessToken: String) {
8+
internal init(_ accessToken: String, apiEndpoint: String? = nil) {
99
self.accessToken = accessToken
10+
self.apiEndpoint = apiEndpoint ?? self.apiEndpoint
1011
}
1112
}

0 commit comments

Comments
 (0)