-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate UberRides and UberAuth configurations
- Loading branch information
1 parent
455f578
commit b39135a
Showing
26 changed files
with
267 additions
and
500 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
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
This file was deleted.
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
|
||
import AuthenticationServices | ||
import UberCore | ||
import Foundation | ||
|
||
public enum UberAuthError: Error { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// Copyright © Uber Technologies, Inc. All rights reserved. | ||
// | ||
|
||
|
||
import Foundation | ||
import UIKit | ||
import UberCore | ||
|
||
/// @mockable | ||
public protocol ConfigurationProviding { | ||
var clientID: String { get } | ||
var redirectURI: String { get } | ||
var sdkVersion: String { get } | ||
var serverToken: String? { get } | ||
static var isSandbox: Bool { get } | ||
|
||
func isInstalled(app: UberApp, defaultIfUnregistered: Bool) -> Bool | ||
} | ||
|
||
public struct ConfigurationProvider: ConfigurationProviding { | ||
|
||
// MARK: Private Properties | ||
|
||
private let parser: PlistParser | ||
|
||
// MARK: Initializers | ||
|
||
public init() { | ||
let parser = PlistParser(plistName: "Info") | ||
self.parser = parser | ||
|
||
guard let contents: [String: String] = parser[ConfigurationKey.base] else { | ||
preconditionFailure("Configuration item not found: \(ConfigurationKey.base)") | ||
} | ||
|
||
guard let clientID = contents[ConfigurationKey.clientID] as? String else { | ||
preconditionFailure("Configuration item not found: \(ConfigurationKey.base)/\(ConfigurationKey.clientID)") | ||
} | ||
|
||
guard let redirectURI = contents[ConfigurationKey.redirectURI] as? String else { | ||
preconditionFailure("Configuration item not found: \(ConfigurationKey.base)/\(ConfigurationKey.clientID)") | ||
} | ||
|
||
self.clientID = clientID | ||
self.redirectURI = redirectURI | ||
Self.isSandbox = Bool(contents[ConfigurationKey.sandbox] ?? "") ?? false | ||
self.serverToken = contents[ConfigurationKey.serverToken] | ||
} | ||
|
||
// MARK: ConfigurationProviding | ||
|
||
public let clientID: String | ||
|
||
public let redirectURI: String | ||
|
||
public let serverToken: String? | ||
|
||
public static var isSandbox: Bool = false | ||
|
||
/// Attempts to determine if the provided `UberApp` is installed on the current device. | ||
/// First checks the Info.plist to see if the required url schemes are registered. If not registered, | ||
/// returns `defaultIfUnregistered`. | ||
/// If registered, returns whether the scheme can be opened, indicating if the app is installed. | ||
/// | ||
/// - Parameters: | ||
/// - app: The Uber application to check | ||
/// - defaultIfUnregistered: The boolean value to return if the app's url scheme is not registered in the Info.plist | ||
/// - Returns: A boolean indicating if the app is installed | ||
public func isInstalled(app: UberApp, defaultIfUnregistered: Bool) -> Bool { | ||
guard let registeredSchemes: [String] = parser["LSApplicationQueriesSchemes"], | ||
registeredSchemes.contains(where: { $0 == app.deeplinkScheme }), | ||
let url = URL(string: "\(app.deeplinkScheme)://") else { | ||
return defaultIfUnregistered | ||
} | ||
return UIApplication.shared.canOpenURL(url) | ||
} | ||
|
||
/// The current version of the SDK as a string | ||
public var sdkVersion: String { | ||
guard let version = Bundle(for: UberButton.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else { | ||
return "Unknown" | ||
} | ||
return version | ||
} | ||
|
||
// MARK: Constants | ||
|
||
private enum ConfigurationKey { | ||
static let base = "Uber" | ||
static let clientID = "ClientID" | ||
static let redirectURI = "RedirectURI" | ||
static let serverToken = "RedirectURI" | ||
static let sandbox = "Sandbox" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Copyright © Uber Technologies, Inc. All rights reserved. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
/// An enum corresponding to each Uber client application | ||
public enum UberApp: CaseIterable { | ||
|
||
// Uber Eats | ||
case eats | ||
|
||
// Uber Driver | ||
case driver | ||
|
||
// Uber | ||
case rides | ||
|
||
public var deeplinkScheme: String { | ||
switch self { | ||
case .eats: | ||
return "ubereats" | ||
case .driver: | ||
return "uberdriver" | ||
case .rides: | ||
return "uber" | ||
} | ||
} | ||
|
||
public var urlIdentifier: String { | ||
switch self { | ||
case .eats: | ||
return "eats" | ||
case .driver: | ||
return "drivers" | ||
case .rides: | ||
return "riders" | ||
} | ||
} | ||
} |
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.