-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #406 from mapbox/jerrad/directions-calculate-inter…
…face Public Response Types
- Loading branch information
Showing
29 changed files
with
815 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
|
||
/// The Mapbox access token specified in the main application bundle’s Info.plist. | ||
let defaultAccessToken = Bundle.main.object(forInfoDictionaryKey: "MGLMapboxAccessToken") as? String | ||
let defaultApiEndPointURLString = Bundle.main.object(forInfoDictionaryKey: "MGLMapboxAPIBaseURL") as? String | ||
|
||
public struct DirectionsCredentials: Equatable { | ||
|
||
/** | ||
The mapbox access token. You can find this in your Mapbox account dashboard. | ||
*/ | ||
public let accessToken: String? | ||
|
||
/** | ||
The host to reach. defaults to `api.mapbox.com`. | ||
*/ | ||
public let host: URL | ||
|
||
/** | ||
The SKU Token associated with the request. Used for billing. | ||
*/ | ||
public var skuToken: String? { | ||
guard let mbx: AnyClass = NSClassFromString("MBXAccounts") else { return nil } | ||
guard mbx.responds(to: Selector(("serviceSkuToken"))) else { return nil } | ||
return mbx.value(forKeyPath: "serviceSkuToken") as? String | ||
} | ||
|
||
/** | ||
Intialize a new credential. | ||
- parameter accessToken: Optional. An access token to provide. If this value is nil, the SDK will attempt to find a token from your app's `info.plist`. | ||
- parameter host: Optional. A parameter to pass a custom host. If `nil` is provided, the SDK will attempt to find a host from your app's `info.plist`, and barring that will default to `https://api.mapbox.com`. | ||
*/ | ||
public init(accessToken: String? = nil, host: URL? = nil) { | ||
self.accessToken = accessToken ?? defaultAccessToken | ||
|
||
precondition(accessToken != nil && !accessToken!.isEmpty, "A Mapbox access token is required. Go to <https://account.mapbox.com/access-tokens/>. In Info.plist, set the MGLMapboxAccessToken key to your access token, or use the Directions(accessToken:host:) initializer.") | ||
|
||
if let host = host { | ||
self.host = host | ||
} else if let defaultHostString = defaultApiEndPointURLString, let defaultHost = URL(string: defaultHostString) { | ||
self.host = defaultHost | ||
} else { | ||
self.host = URL(string: "https://api.mapbox.com")! | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.