Skip to content

Commit 429145b

Browse files
committed
Merge pull request #35 from mapbox/1ec5-host-582
Add host option
2 parents 4c54039 + 23e438d commit 429145b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

MapboxGeocoder/MBGeocoder.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ 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+
configuration = MBGeocoderConfiguration(accessToken, host: host)
2127
}
2228

2329
private var task: NSURLSessionDataTask?

MapboxGeocoder/MBGeocoderConfiguration.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ 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, host: String? = nil) {
99
self.accessToken = accessToken
10+
if let host = host {
11+
let baseURLComponents = NSURLComponents()
12+
baseURLComponents.scheme = "https"
13+
baseURLComponents.host = host
14+
apiEndpoint = baseURLComponents.string ?? apiEndpoint
15+
}
1016
}
1117
}

0 commit comments

Comments
 (0)