diff --git a/source/TestAppShim/Info.plist b/source/TestAppShim/Info.plist
index 38e98af2..cbe5af07 100644
--- a/source/TestAppShim/Info.plist
+++ b/source/TestAppShim/Info.plist
@@ -33,6 +33,10 @@
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
-
+
+ UberClientID
+ UberTestClientID
+ UberDisplayName
+ UberTestDisplayName
diff --git a/source/UberRides/AppStoreDeeplink.swift b/source/UberRides/AppStoreDeeplink.swift
index 1155753c..e5a903fd 100644
--- a/source/UberRides/AppStoreDeeplink.swift
+++ b/source/UberRides/AppStoreDeeplink.swift
@@ -39,9 +39,9 @@ import Foundation
let domain = "m.uber.com"
let path = "/sign-up"
- let clientIDQueryItem = URLQueryItem(name: "client_id", value: Configuration.getClientID())
+ let clientIDQueryItem = URLQueryItem(name: "client_id", value: Configuration.shared.clientID)
- let userAgent = userAgent ?? "rides-ios-v\(Configuration.sdkVersion)"
+ let userAgent = userAgent ?? "rides-ios-v\(Configuration.shared.sdkVersion)"
let userAgentQueryItem = URLQueryItem(name: "user-agent", value: userAgent)
diff --git a/source/UberRides/BaseDeeplink.swift b/source/UberRides/BaseDeeplink.swift
index e4035c38..418a8b0d 100644
--- a/source/UberRides/BaseDeeplink.swift
+++ b/source/UberRides/BaseDeeplink.swift
@@ -74,8 +74,8 @@ import Foundation
- parameter completion: The completion block to execute once the deeplink has
executed. Passes in True if the url was successfully opened, false otherwise.
*/
- @objc open func execute(_ completion: ((NSError?) -> ())? = nil) {
-
+ @objc open func execute(completion: ((NSError?) -> ())? = nil) {
+
let usingIOS9 = ProcessInfo().isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0))
if usingIOS9 {
diff --git a/source/UberRides/Configuration.swift b/source/UberRides/Configuration.swift
index a4e0154f..16e17456 100644
--- a/source/UberRides/Configuration.swift
+++ b/source/UberRides/Configuration.swift
@@ -25,16 +25,13 @@
import Foundation
import WebKit
-/**
- An enum to represent the region that the SDK should use for making requests
-
- - Default: The default region
- - China: China, for apps that are based in China
- */
-@objc public enum Region : Int {
- case `default`
- case china
-}
+private let clientIDKey = "UberClientID"
+private let appNameKey = "UberDisplayName"
+private let serverTokenKey = "UberServerToken"
+private let callbackURIKey = "UberCallbackURI"
+private let callbackURIsKey = "UberCallbackURIs"
+private let callbackURIsTypeKey = "UberCallbackURIType"
+private let callbackURIStringKey = "URIString"
/**
An enum to represent the possible callback URI types. Each form of authorization
@@ -87,6 +84,7 @@ import WebKit
*/
@objc(UBSDKConfiguration) open class Configuration : NSObject {
// MARK : Variables
+ open static var shared: Configuration = Configuration()
/// The .plist file to use, default is Info.plist
open static var plistName = "Info"
@@ -94,41 +92,90 @@ import WebKit
/// The bundle that contains the .plist file. Default is the mainBundle()
open static var bundle = Bundle.main
- static var processPool = WKProcessPool()
-
- private static let clientIDKey = "UberClientID"
- private static let appNameKey = "UberDisplayName"
- private static let serverTokenKey = "UberServerToken"
- private static let callbackURIKey = "UberCallbackURI"
- private static let callbackURIsKey = "UberCallbackURIs"
- private static let callbackURIsTypeKey = "UberCallbackURIType"
- private static let callbackURIStringKey = "URIString"
- private static let accessTokenIdentifier = "RidesAccessTokenKey"
-
- private static var clientID : String?
- private static var callbackURIString : String?
- private static var callbackURIs = [CallbackURIType : String]()
- private static var appDisplayName: String?
- private static var serverToken: String?
- private static var defaultKeychainAccessGroup: String?
- private static var defaultAccessTokenIdentifier: String?
- private static var region : Region = .default
- private static var isSandbox : Bool = false
- private static var useFallback: Bool = true
-
- /// The string value of the current region setting
- open static var regionString: String {
- switch region {
- case .china:
- return "china"
- case .default:
- return "default"
+ open var processPool = WKProcessPool()
+
+ /**
+ Gets the client ID of this app. Defaults to the value stored in your Application's
+ plist if not set (UberClientID)
+
+ - returns: The string to use for the Client ID
+ */
+ open var clientID: String
+
+ private var callbackURIs = [CallbackURIType: String]()
+
+ /**
+ Gets the display name of this app. Defaults to the value stored in your Appication's
+ plist if not set (UberClientID)
+
+ - returns: The app's name
+ */
+ open var appDisplayName: String
+
+ /**
+ Gets the Server Token of this app. Defaults to the value stored in your Appication's
+ plist if not set (UberServerToken)
+ Optional. Used by the Request Button to get time estimates without requiring
+ login
+
+ - returns: The string Representing your app's server token
+ */
+ open var serverToken: String?
+
+ /**
+ Gets the default keychain access group to save access tokens to. Advanced setting
+ for sharing access tokens between multiple of your apps. Defaults an empty string
+
+ - returns: The default keychain access group to use
+ */
+ open var defaultKeychainAccessGroup: String = ""
+
+ /**
+ Gets the default key to use when saving access tokens to the keychain. Defaults
+ to using "RidesAccessTokenKey"
+
+ - returns: The default access token identifier to use
+ */
+ open var defaultAccessTokenIdentifier: String = "RidesAccessTokenKey"
+
+ /**
+ Returns if sandbox is enabled or not
+
+ - returns: true if Sandbox is enabled, false otherwise
+ */
+ open var isSandbox: Bool = false
+
+ /**
+ Returns if the fallback to use Authorization Code Grant is enabled. If true,
+ a failed SSO attempt will follow up with an attempt to do Authorization Code Grant
+ (if requesting priveleged scopes). If false, the user will be redirected to the app store
+
+ - returns: true if fallback enabled, false otherwise
+ */
+ open var useFallback: Bool = true
+
+ public override init() {
+ self.clientID = ""
+ self.appDisplayName = ""
+
+ super.init()
+
+ if let defaultValue = getDefaultValue(clientIDKey) {
+ self.clientID = defaultValue
+ } else {
+ fatalConfigurationError("ClientID", key: clientIDKey)
}
+ if let defaultValue = getDefaultValue(appNameKey) {
+ self.appDisplayName = defaultValue
+ } else {
+ fatalConfigurationError("appDisplayName", key: appNameKey)
+ }
+ serverToken = getDefaultValue(serverTokenKey)
}
/// The current version of the SDK as a string
- open static var sdkVersion: String {
- guard let version = Bundle(for: self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else {
+ open var sdkVersion: String {
+ guard let version = Bundle(for: Configuration.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else {
return "Unknown"
}
return version
@@ -138,48 +185,19 @@ import WebKit
Resets all of the Configuration's values to default
*/
open static func restoreDefaults() {
- plistName = "Info"
- bundle = Bundle.main
- setClientID(nil)
- setCallbackURIString(nil)
- callbackURIs = parseCallbackURIs()
- setAppDisplayName(nil)
- setServerToken(nil)
- setDefaultAccessTokenIdentifier(nil)
- setDefaultKeychainAccessGroup(nil)
- setRegion(Region.default)
- setSandboxEnabled(false)
- setFallbackEnabled(true)
- resetProcessPool()
+ shared = Configuration()
}
// MARK: Getters
- /**
- Gets the client ID of this app. Defaults to the value stored in your Application's
- plist if not set (UberClientID)
-
- - returns: The string to use for the Client ID
- */
- open static func getClientID() -> String {
- if clientID == nil {
- guard let defaultValue = getDefaultValue(clientIDKey) else {
- fatalConfigurationError("ClientID", key: clientIDKey)
- }
- clientID = defaultValue
- }
-
- return clientID!
- }
-
/**
Gets the callback URIString of this app. Defaults to the value stored in your Application's
plist if not set (UberCallbackURI)
- returns: The string to use for the Callback URI
*/
- open static func getCallbackURIString() -> String {
- return getCallbackURIString(.general)
+ open func getCallbackURIString() -> String {
+ return getCallbackURIString(for: .general)
}
/**
@@ -193,7 +211,7 @@ import WebKit
- returns: The callbackURIString for the the requested type
*/
- open static func getCallbackURIString(_ type: CallbackURIType) -> String {
+ open func getCallbackURIString(for type: CallbackURIType) -> String {
if callbackURIs[type] == nil {
let defaultCallbacks = parseCallbackURIs()
var fallback = defaultCallbacks[type] ?? callbackURIs[.general]
@@ -207,108 +225,8 @@ import WebKit
return callbackURIs[type]!
}
- /**
- Gets the display name of this app. Defaults to the value stored in your Appication's
- plist if not set (UberClientID)
-
- - returns: The app's name
- */
- open static func getAppDisplayName() -> String {
- if appDisplayName == nil {
- guard let defaultValue = getDefaultValue(appNameKey) else {
- fatalConfigurationError("appDisplayName", key: appNameKey)
- }
- appDisplayName = defaultValue
- }
-
- return appDisplayName!
- }
-
- /**
- Gets the Server Token of this app. Defaults to the value stored in your Appication's
- plist if not set (UberServerToken)
- Optional. Used by the Request Button to get time estimates without requiring
- login
-
- - returns: The string Representing your app's server token
- */
- open static func getServerToken() -> String? {
- if serverToken == nil {
- serverToken = getDefaultValue(serverTokenKey)
- }
-
- return serverToken
- }
-
- /**
- Gets the default keychain access group to save access tokens to. Advanced setting
- for sharing access tokens between multiple of your apps. Defaults an empty string
-
- - returns: The default keychain access group to use
- */
- open static func getDefaultKeychainAccessGroup() -> String {
- guard let defaultKeychainAccessGroup = defaultKeychainAccessGroup else {
- return ""
- }
-
- return defaultKeychainAccessGroup
- }
-
- /**
- Gets the default key to use when saving access tokens to the keychain. Defaults
- to using "RidesAccessTokenKey"
-
- - returns: The default access token identifier to use
- */
- open static func getDefaultAccessTokenIdentifier() -> String {
- guard let defaultAccessTokenIdentifier = defaultAccessTokenIdentifier else {
- return accessTokenIdentifier
- }
-
- return defaultAccessTokenIdentifier
- }
-
- /**
- Gets the current region the SDK is using. Defaults to Region.Default
-
- - returns: The Region the SDK is using
- */
- open static func getRegion() -> Region {
- return region
- }
-
- /**
- Returns if sandbox is enabled or not
-
- - returns: true if Sandbox is enabled, false otherwise
- */
- open static func getSandboxEnabled() -> Bool {
- return isSandbox
- }
-
- /**
- Returns if the fallback to use Authorization Code Grant is enabled. If true,
- a failed SSO attempt will follow up with an attempt to do Authorization Code Grant
- (if requesting priveleged scopes). If false, the user will be redirected to the app store
-
- - returns: true if fallback enabled, false otherwise
- */
- open static func getFallbackEnabled() -> Bool {
- return useFallback
- }
-
//MARK: Setters
- /**
- Sets a string to use as the Client ID. Overwrites the default value provided by
- the plist. Setting clientID to nil will result in using the default value
-
- - parameter clientID: The client ID String to use
- */
- open static func setClientID(_ clientID: String?) {
- self.clientID = clientID
- }
-
/**
Sets a string to use as the Callback URI String. Overwrites the default value provided by
the plist. Setting to nil will result in using the default value.
@@ -317,7 +235,7 @@ import WebKit
- parameter callbackURIString: The callback URI String to use
*/
- open static func setCallbackURIString(_ callbackURIString: String?) {
+ open func setCallbackURIString(_ callbackURIString: String?) {
setCallbackURIString(callbackURIString, type: .general)
}
@@ -331,110 +249,19 @@ import WebKit
- parameter callbackURIString: The callback URI String to use
- parameter type: The Callback URI Type to use
*/
- open static func setCallbackURIString(_ callbackURIString: String?, type: CallbackURIType) {
+ open func setCallbackURIString(_ callbackURIString: String?, type: CallbackURIType) {
var callbackURIs = self.callbackURIs
callbackURIs[type] = callbackURIString
self.callbackURIs = callbackURIs
}
-
- /**
- Sets a string to use as the app display name in Uber. Overwrites the default
- value provided by the plist. Setting to nil will result in using the
- default value
-
- - parameter appDisplayName: The display name String to use
- */
- open static func setAppDisplayName(_ appDisplayName: String?) {
- self.appDisplayName = appDisplayName
- }
-
- /**
- Sets a string to use as the Server Token. Overwrites the default value provided by
- the plist. Setting to nil will result in using the default value
-
- - parameter serverToken: The Server Token String to use
- */
- open static func setServerToken(_ serverToken: String?) {
- self.serverToken = serverToken
- }
-
- /**
- Sets the default keychain access group to use. Access tokens will be saved
- here by default, unless otherwise specified at the time of login
-
- - parameter keychainAccessGroup: The client ID String to use
- */
- open static func setDefaultKeychainAccessGroup(_ keychainAccessGroup: String?) {
- self.defaultKeychainAccessGroup = keychainAccessGroup
- }
-
- /**
- Sets the default key to use when saving access tokens to the keychain. Setting
- to nil will result in using the default value
-
- - parameter accessTokenIdentifier: The access token identifier to use
- */
- open static func setDefaultAccessTokenIdentifier(_ accessTokenIdentifier: String?) {
- self.defaultAccessTokenIdentifier = accessTokenIdentifier
- }
-
- /**
- Set the region your app is registered in. Used to determine what endpoints to
- send requests to.
-
- - parameter region: The region the SDK should use
- */
- open static func setRegion(_ region: Region) {
- self.region = region
- }
-
- /**
- Enables / Disables Sandbox mode. When the SDK is in sandbox mode, all requests
- will go to the sandbox environment.
-
- - parameter enabled: Whether or not sandbox should be enabled
- */
- open static func setSandboxEnabled(_ enabled: Bool) {
- isSandbox = enabled
- }
-
- /**
- Enables / Disables the Authorization Code fallback for SSO. If enabled, the SDK
- will attempt to do Authorization Code Flow if SSO is unavailable. Otherwise, a
- user will be directed to the appstore
-
- - parameter enabled: Whether or not fallback should be enabled
- */
- open static func setFallbackEnabled(_ enabled: Bool) {
- useFallback = enabled
- }
-
- // MARK: Internal
-
- static func resetProcessPool() {
+
+ func resetProcessPool() {
processPool = WKProcessPool()
}
// MARK: Private
- private static func getPlistDictionary() -> [String : AnyObject]? {
- guard let path = bundle.path(forResource: plistName, ofType: "plist"),
- let dictionary = NSDictionary(contentsOfFile: path) as? [String: AnyObject] else {
- return nil
- }
- return dictionary
- }
-
- private static func getDefaultValue(_ key: String) -> String? {
- guard let dictionary = getPlistDictionary(),
- let defaultValue = dictionary[key] as? String else {
- return nil
- }
-
- return defaultValue
- }
-
- private static func parseCallbackURIs() -> [CallbackURIType : String] {
+ private func parseCallbackURIs() -> [CallbackURIType : String] {
guard let plist = getPlistDictionary(), let callbacks = plist[callbackURIsKey] as? [[String : AnyObject]] else {
return [CallbackURIType : String]()
}
@@ -449,9 +276,25 @@ import WebKit
}
return callbackURIs
}
-
- private static func fatalConfigurationError(_ variableName: String, key: String ) -> Never {
- fatalError("Unable to get your \(variableName). Did you forget to set it in your \(plistName).plist? (Should be under \(key) key)")
+
+ private func fatalConfigurationError(_ variableName: String, key: String ) -> Never {
+ fatalError("Unable to get your \(variableName). Did you forget to set it in your \(Configuration.plistName).plist? (Should be under \(key) key)")
+ }
+
+ private func getPlistDictionary() -> [String : AnyObject]? {
+ guard let path = Configuration.bundle.path(forResource: Configuration.plistName, ofType: "plist"),
+ let dictionary = NSDictionary(contentsOfFile: path) as? [String: AnyObject] else {
+ return nil
+ }
+ return dictionary
+ }
+
+ private func getDefaultValue(_ key: String) -> String? {
+ guard let dictionary = getPlistDictionary(),
+ let defaultValue = dictionary[key] as? String else {
+ return nil
+ }
+
+ return defaultValue
}
-
}
diff --git a/source/UberRides/DeeplinkRequestingBehavior.swift b/source/UberRides/DeeplinkRequestingBehavior.swift
index 55c85b36..24e95c51 100644
--- a/source/UberRides/DeeplinkRequestingBehavior.swift
+++ b/source/UberRides/DeeplinkRequestingBehavior.swift
@@ -26,30 +26,30 @@
/**
Requests a ride using a RequestDeeplink that is constructed using the provided
rideParameters
-
+
- parameter rideParameters: The RideParameters to use for building and executing
the deeplink
*/
- @objc open func requestRide(_ rideParameters: RideParameters?) {
+ @objc open func requestRide(parameters rideParameters: RideParameters?) {
guard let rideParameters = rideParameters else {
return
}
- let deeplink = createDeeplink(rideParameters)
+ let deeplink = createDeeplink(rideParameters: rideParameters)
let deeplinkCompletion: (NSError?) -> () = { error in
if let error = error, error.code != DeeplinkErrorType.deeplinkNotFollowed.rawValue {
- self.createAppStoreDeeplink(rideParameters).execute(nil)
+ self.createAppStoreDeeplink(rideParameters: rideParameters).execute(completion: nil)
}
}
- deeplink.execute(deeplinkCompletion)
+ deeplink.execute(completion: deeplinkCompletion)
}
- func createDeeplink(_ rideParameters: RideParameters) -> RequestDeeplink {
+ func createDeeplink(rideParameters: RideParameters) -> RequestDeeplink {
return RequestDeeplink(rideParameters: rideParameters)
}
- func createAppStoreDeeplink(_ rideParameters: RideParameters) -> Deeplinking {
+ func createAppStoreDeeplink(rideParameters: RideParameters) -> Deeplinking {
return AppStoreDeeplink(userAgent: rideParameters.userAgent)
}
}
diff --git a/source/UberRides/DeeplinkingProtocol.swift b/source/UberRides/DeeplinkingProtocol.swift
index 60f91523..549d363b 100644
--- a/source/UberRides/DeeplinkingProtocol.swift
+++ b/source/UberRides/DeeplinkingProtocol.swift
@@ -54,5 +54,5 @@
- parameter completion: The completion block to execute once the deeplink has
executed. Passes in True if the url was successfully opened, false otherwise.
*/
- @objc func execute(_ completion: ((NSError?) -> ())?)
+ @objc func execute(completion: ((NSError?) -> ())?)
}
diff --git a/source/UberRides/EndpointsManager.swift b/source/UberRides/EndpointsManager.swift
index 857451c0..81c3f162 100644
--- a/source/UberRides/EndpointsManager.swift
+++ b/source/UberRides/EndpointsManager.swift
@@ -46,7 +46,7 @@ extension UberAPI {
}
var host: String {
- if Configuration.getSandboxEnabled() {
+ if Configuration.shared.isSandbox {
return "https://sandbox-api.uber.com"
} else {
return "https://api.uber.com"
@@ -145,7 +145,7 @@ enum Components: UberAPI {
var query: [URLQueryItem] {
switch self {
case .rideRequestWidget(let rideParameters):
- let environment = Configuration.getSandboxEnabled() ? "sandbox" : "production"
+ let environment = Configuration.shared.isSandbox ? "sandbox" : "production"
var queryItems = queryBuilder( ("env", "\(environment)") )
if let rideParameters = rideParameters {
@@ -181,7 +181,7 @@ enum OAuth: UberAPI {
}
var host: String {
- return OAuth.regionHostString()
+ return OAuth.regionHost
}
var body: Data? {
@@ -198,8 +198,8 @@ enum OAuth: UberAPI {
return nil
}
}
-
- static func regionHostString(_ region: Region = Configuration.getRegion()) -> String {
+
+ static var regionHost: String {
return "https://login.uber.com"
}
diff --git a/source/UberRides/LoginButton.swift b/source/UberRides/LoginButton.swift
index 24b2a14e..a484a6f9 100644
--- a/source/UberRides/LoginButton.swift
+++ b/source/UberRides/LoginButton.swift
@@ -77,7 +77,7 @@ import UIKit
/// The current LoginButtonState of this button (signed in / signed out)
open var buttonState: LoginButtonState {
- if let _ = TokenManager.fetchToken(accessTokenIdentifier, accessGroup: keychainAccessGroup) {
+ if let _ = TokenManager.fetchToken(identifier: accessTokenIdentifier, accessGroup: keychainAccessGroup) {
return .signedIn
} else {
return .signedOut
@@ -119,8 +119,8 @@ import UIKit
*/
override open func setup() {
super.setup()
- NotificationCenter.default.addObserver(self, selector: #selector(refreshContent), name: Notification.Name(rawValue: TokenManager.TokenManagerDidSaveTokenNotification), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(refreshContent), name: Notification.Name(rawValue: TokenManager.TokenManagerDidDeleteTokenNotification), object: nil)
+ NotificationCenter.default.addObserver(self, selector: #selector(refreshContent), name: Notification.Name(rawValue: TokenManager.tokenManagerDidSaveTokenNotification), object: nil)
+ NotificationCenter.default.addObserver(self, selector: #selector(refreshContent), name: Notification.Name(rawValue: TokenManager.tokenManagerDidDeleteTokenNotification), object: nil)
addTarget(self, action: #selector(uberButtonTapped), for: .touchUpInside)
loginCompletion = { token, error in
self.delegate?.loginButton(self, didCompleteLoginWithToken: token, error: error)
@@ -201,7 +201,7 @@ import UIKit
func uberButtonTapped(_ button: UIButton) {
switch buttonState {
case .signedIn:
- let success = TokenManager.deleteToken(accessTokenIdentifier, accessGroup: keychainAccessGroup)
+ let success = TokenManager.deleteToken(identifier: accessTokenIdentifier, accessGroup: keychainAccessGroup)
delegate?.loginButton(self, didLogoutWithSuccess: success)
refreshContent()
case .signedOut:
diff --git a/source/UberRides/Model/RideStatus.swift b/source/UberRides/Model/RideStatus.swift
index ae30c451..4c2fd663 100644
--- a/source/UberRides/Model/RideStatus.swift
+++ b/source/UberRides/Model/RideStatus.swift
@@ -52,14 +52,14 @@
// MARK: Objective-C Compatibility
private enum RideStatusString: String {
- case Accepted = "accepted"
- case Arriving = "arriving"
- case Completed = "completed"
- case DriverCanceled = "driver_canceled"
- case InProgress = "in_progress"
- case NoDriversAvailable = "no_drivers_available"
- case Processing = "processing"
- case RiderCanceled = "rider_canceled"
+ case accepted = "accepted"
+ case arriving = "arriving"
+ case completed = "completed"
+ case driverCanceled = "driver_canceled"
+ case inProgress = "in_progress"
+ case noDriversAvailable = "no_drivers_available"
+ case processing = "processing"
+ case riderCanceled = "rider_canceled"
}
class RideStatusFactory: NSObject {
@@ -69,21 +69,21 @@ class RideStatusFactory: NSObject {
}
switch status {
- case .Accepted:
+ case .accepted:
return .accepted
- case .Arriving:
+ case .arriving:
return .arriving
- case .Completed:
+ case .completed:
return .completed
- case .DriverCanceled:
+ case .driverCanceled:
return .driverCanceled
- case .InProgress:
+ case .inProgress:
return .inProgress
- case .NoDriversAvailable:
+ case .noDriversAvailable:
return .noDriversAvailable
- case .Processing:
+ case .processing:
return .processing
- case .RiderCanceled:
+ case .riderCanceled:
return .riderCanceled
}
}
diff --git a/source/UberRides/OAuth/AccessTokenFactory.swift b/source/UberRides/OAuth/AccessTokenFactory.swift
index f603b072..b0c69152 100644
--- a/source/UberRides/OAuth/AccessTokenFactory.swift
+++ b/source/UberRides/OAuth/AccessTokenFactory.swift
@@ -30,8 +30,8 @@ Factory class to build access tokens
*/
@objc(UBSDKAccessTokenFactory) public class AccessTokenFactory: NSObject {
- @objc public static func createAccessTokenFromJSONString(string: String) -> AccessToken? {
- return ModelMapper().mapFromJSON(string)
+ @objc public static func createAccessToken(fromJSONString jsonString: String) -> AccessToken? {
+ return ModelMapper().mapFromJSON(jsonString)
}
/**
@@ -41,8 +41,8 @@ Factory class to build access tokens
- parameter url: The URL to parse the token from
- returns: An initialized AccessToken, or nil if one couldn't be created
*/
- static func createAccessTokenFromRedirectURL(_ url : URL) throws -> AccessToken {
- guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
+ static func createAccessToken(fromRedirectURL redirectURL: URL) throws -> AccessToken {
+ guard var components = URLComponents(url: redirectURL, resolvingAgainstBaseURL: false) else {
throw RidesAuthenticationErrorFactory.errorForType(ridesAuthenticationErrorType: .invalidResponse)
}
diff --git a/source/UberRides/OAuth/AuthorizationCodeGrantAuthenticator.swift b/source/UberRides/OAuth/AuthorizationCodeGrantAuthenticator.swift
index 82ade166..50cd5045 100644
--- a/source/UberRides/OAuth/AuthorizationCodeGrantAuthenticator.swift
+++ b/source/UberRides/OAuth/AuthorizationCodeGrantAuthenticator.swift
@@ -34,14 +34,14 @@ import UIKit
}
override var endpoint: UberAPI {
- return OAuth.authorizationCodeLogin(clientID: Configuration.getClientID(), redirect: Configuration.getCallbackURIString(.authorizationCode), scopes: scopes, state: state)
+ return OAuth.authorizationCodeLogin(clientID: Configuration.shared.clientID, redirect: Configuration.shared.getCallbackURIString(for: .authorizationCode), scopes: scopes, state: state)
}
override public convenience init(presentingViewController: UIViewController, scopes: [RidesScope]) {
self.init(presentingViewController: presentingViewController, scopes: scopes, state: nil)
}
- override func handleRedirectRequest(_ request: URLRequest) -> Bool {
+ override func handleRedirect(for request: URLRequest) -> Bool {
var shouldHandle = false
if let url = request.url, AuthenticationURLUtility.shouldHandleRedirectURL(url, type: callbackURIType) {
if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false),
@@ -56,7 +56,7 @@ import UIKit
executeRedirect(request)
loginCompletion?(nil, nil)
} else {
- shouldHandle = super.handleRedirectRequest(request)
+ shouldHandle = super.handleRedirect(for: request)
}
return shouldHandle
}
diff --git a/source/UberRides/OAuth/BaseAuthenticator.swift b/source/UberRides/OAuth/BaseAuthenticator.swift
index becb4412..2e8fc2ca 100644
--- a/source/UberRides/OAuth/BaseAuthenticator.swift
+++ b/source/UberRides/OAuth/BaseAuthenticator.swift
@@ -47,16 +47,16 @@ import UIKit
super.init()
}
- func handleRedirectRequest(_ request: URLRequest) -> Bool {
+ func handleRedirect(for request: URLRequest) -> Bool {
var didHandleRedirect = false
if let url = request.url, AuthenticationURLUtility.shouldHandleRedirectURL(url, type: callbackURIType) {
do {
- let accessToken = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ let accessToken = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
- let tokenIdentifier = accessTokenIdentifier ?? Configuration.getDefaultAccessTokenIdentifier()
- let accessGroup = keychainAccessGroup ?? Configuration.getDefaultKeychainAccessGroup()
+ let tokenIdentifier = accessTokenIdentifier ?? Configuration.shared.defaultAccessTokenIdentifier
+ let accessGroup = keychainAccessGroup ?? Configuration.shared.defaultKeychainAccessGroup
var error: NSError?
- let success = TokenManager.saveToken(accessToken, tokenIdentifier: tokenIdentifier, accessGroup: accessGroup)
+ let success = TokenManager.save(accessToken: accessToken, tokenIdentifier: tokenIdentifier, accessGroup: accessGroup)
if !success {
error = RidesAuthenticationErrorFactory.errorForType(ridesAuthenticationErrorType: .unableToSaveAccessToken)
print("Error: access token failed to save to keychain")
diff --git a/source/UberRides/OAuth/ImplicitGrantAuthenticator.swift b/source/UberRides/OAuth/ImplicitGrantAuthenticator.swift
index 8dd6c004..0d3e72c0 100644
--- a/source/UberRides/OAuth/ImplicitGrantAuthenticator.swift
+++ b/source/UberRides/OAuth/ImplicitGrantAuthenticator.swift
@@ -30,7 +30,7 @@ import UIKit
@objc(UBSDKImplicitGrantAuthenticator) open class ImplicitGrantAuthenticator: LoginViewAuthenticator {
override var endpoint: UberAPI {
- return OAuth.implicitLogin(clientID: Configuration.getClientID(), scopes: self.scopes, redirect: Configuration.getCallbackURIString(.implicit))
+ return OAuth.implicitLogin(clientID: Configuration.shared.clientID, scopes: self.scopes, redirect: Configuration.shared.getCallbackURIString(for: .implicit))
}
override public init(presentingViewController: UIViewController, scopes: [RidesScope]) {
diff --git a/source/UberRides/OAuth/LoginManager.swift b/source/UberRides/OAuth/LoginManager.swift
index 10688b21..6741652b 100644
--- a/source/UberRides/OAuth/LoginManager.swift
+++ b/source/UberRides/OAuth/LoginManager.swift
@@ -40,8 +40,8 @@
/**
Create instance of login manager to authenticate user and retreive access token.
- - parameter accessTokenIdentifier: The access token identifier to use for saving the Access Token, defaults to Configuration.getDefaultAccessTokenIdentifier()
- - parameter keychainAccessGroup: The keychain access group to use for saving the Access Token, defaults to Configuration.getDefaultKeychainAccessGroup()
+ - parameter accessTokenIdentifier: The access token identifier to use for saving the Access Token, defaults to Configuration.shared.defaultAccessTokenIdentifier
+ - parameter keychainAccessGroup: The keychain access group to use for saving the Access Token, defaults to Configuration.shared.defaultKeychainAccessGroup
- parameter loginType: The login type to use for logging in, defaults to Implicit
- returns: An initialized LoginManager
@@ -49,62 +49,61 @@
@objc public init(accessTokenIdentifier: String, keychainAccessGroup: String?, loginType: LoginType) {
self.accessTokenIdentifier = accessTokenIdentifier
- self.keychainAccessGroup = keychainAccessGroup ?? Configuration.getDefaultKeychainAccessGroup()
+ self.keychainAccessGroup = keychainAccessGroup ?? Configuration.shared.defaultKeychainAccessGroup
self.loginType = loginType
super.init()
}
-
+
/**
Create instance of login manager to authenticate user and retreive access token.
Uses the Implicit Login Behavior
-
+
- parameter accessTokenIdentifier: The access token identifier to use for saving the Access Token, defaults to Configuration.getDefaultAccessTokenIdentifier()
- parameter keychainAccessGroup: The keychain access group to use for saving the Access Token, defaults to Configuration.getDefaultKeychainAccessGroup()
-
+
- returns: An initialized LoginManager
*/
@objc public convenience init(accessTokenIdentifier: String, keychainAccessGroup: String?) {
- let accessGroup = keychainAccessGroup ?? Configuration.getDefaultKeychainAccessGroup()
- self.init(accessTokenIdentifier: accessTokenIdentifier, keychainAccessGroup: accessGroup, loginType: LoginType.implicit)
+ self.init(accessTokenIdentifier: accessTokenIdentifier, keychainAccessGroup: keychainAccessGroup, loginType: LoginType.implicit)
}
-
+
/**
Create instance of login manager to authenticate user and retreive access token.
Uses the Implicit Login Behavior & your Configuration's keychain access group
-
+
- parameter accessTokenIdentifier: The access token identifier to use for saving the Access Token, defaults to Configuration.getDefaultAccessTokenIdentifier()
-
+
- returns: An initialized LoginManager
*/
@objc public convenience init(accessTokenIdentifier: String) {
self.init(accessTokenIdentifier: accessTokenIdentifier, keychainAccessGroup: nil)
}
-
+
/**
Create instance of login manager to authenticate user and retreive access token.
Uses the provided LoginType, with the accessTokenIdentifier & keychainAccessGroup defined
in your Configuration
-
+
- parameter loginType: The login behavior to use for logging in
-
+
- returns: An initialized LoginManager
*/
@objc public convenience init(loginType: LoginType) {
- self.init(accessTokenIdentifier: Configuration.getDefaultAccessTokenIdentifier(), keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: loginType)
+ self.init(accessTokenIdentifier: Configuration.shared.defaultAccessTokenIdentifier, keychainAccessGroup: nil, loginType: loginType)
}
-
+
/**
Create instance of login manager to authenticate user and retreive access token.
Uses the Native LoginType, with the accessTokenIdentifier & keychainAccessGroup defined
in your Configuration
-
+
- returns: An initialized LoginManager
*/
@objc public convenience override init() {
- self.init(accessTokenIdentifier: Configuration.getDefaultAccessTokenIdentifier(), keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: LoginType.native)
+ self.init(accessTokenIdentifier: Configuration.shared.defaultAccessTokenIdentifier, keychainAccessGroup: nil, loginType: LoginType.native)
}
-
+
// Mark: LoginManaging
/**
@@ -140,7 +139,7 @@
let nativeAuthenticator = NativeAuthenticator(scopes: scopes)
nativeAuthenticator.deeplinkCompletion = { error in
if (error == nil) {
- RidesAppDelegate.sharedInstance.loginManager = self
+ RidesAppDelegate.shared.loginManager = self
}
};
loginAuthenticator = nativeAuthenticator
@@ -163,33 +162,44 @@
- parameter url: The URL resource to open. As passed to the corresponding AppDelegate methods
- parameter sourceApplication: The bundle ID of the app that is requesting your app to open the URL (url).
As passed to the corresponding AppDelegate method (iOS 8)
- OR
- options[UIApplicationOpenURLOptionsSourceApplicationKey] (iOS 9+)
- parameter annotation: annotation: A property list object supplied by the source app to communicate
information to the receiving app As passed to the corresponding AppDelegate method (iOS 8)
- OR
- options[UIApplicationLaunchOptionsAnnotationKey] (iOS 9+)
-
- returns: true if the url was meant to be handled by the SDK, false otherwise
*/
- open func application(_ application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: Any?) -> Bool {
+ open func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
guard let source = sourceApplication, source.hasPrefix("com.ubercab"),
let nativeAuthenticator = authenticator as? NativeAuthenticator else {
return false
}
let redirectURL = URLRequest(url: url)
- let handled = nativeAuthenticator.handleRedirectRequest(redirectURL)
+ let handled = nativeAuthenticator.handleRedirect(for: redirectURL)
loggingIn = false
authenticator = nil
return handled
}
+
+ /**
+ Called via the RidesAppDelegate when the application is opened via a URL. Responsible
+ for parsing the url and creating an OAuthToken. (iOS 9+)
+
+ - parameter application: The UIApplication object. Pass in the value from the App Delegate
+ - parameter url: The URL resource to open. As passed to the corresponding AppDelegate methods
+ - parameter options: A dictionary of URL handling options. As passed to the corresponding AppDelegate method.
+
+ - returns: true if the url was meant to be handled by the SDK, false otherwise
+ */
+ @available(iOS 9.0, *)
+ open func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
+ let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
+ let annotation = options[.annotation] as Any
+
+ return application(app, open: url, sourceApplication: sourceApplication, annotation: annotation)
+ }
/**
Called via the RidesAppDelegate when the application becomes active. Used to determine
if a user abandons Native login without getting an access token.
-
- - parameter application: The UIApplication object. Pass in the value from the App Delegate
*/
open func applicationDidBecomeActive() {
if loggingIn {
@@ -253,11 +263,11 @@
}
if manager.scopes.contains(where: { $0.scopeType == .privileged }) {
- if (Configuration.getFallbackEnabled()) {
+ if (Configuration.shared.useFallback) {
loginType = .authorizationCode
} else {
let appstoreDeeplink = AppStoreDeeplink(userAgent: nil)
- appstoreDeeplink.execute({ _ in
+ appstoreDeeplink.execute(completion: { _ in
completion?(nil, error)
})
return
diff --git a/source/UberRides/OAuth/LoginManagingProtocol.swift b/source/UberRides/OAuth/LoginManagingProtocol.swift
index f57c9efd..cc5c5537 100644
--- a/source/UberRides/OAuth/LoginManagingProtocol.swift
+++ b/source/UberRides/OAuth/LoginManagingProtocol.swift
@@ -47,23 +47,31 @@
/**
Called via the RidesAppDelegate when the application is opened via a URL. Responsible
- for parsing the url and creating an OAuthToken.
+ for parsing the url and creating an OAuthToken. (iOS 8 and below)
- parameter application: The UIApplication object. Pass in the value from the App Delegate
- parameter url: The URL resource to open. As passed to the corresponding AppDelegate methods
- parameter sourceApplication: The bundle ID of the app that is requesting your app to open the URL (url).
- As passed to the corresponding AppDelegate method (iOS 8)
- OR
- options[UIApplicationOpenURLOptionsSourceApplicationKey] (iOS 9+)
+ As passed to the corresponding AppDelegate method
- parameter annotation: annotation: A property list object supplied by the source app to communicate
- information to the receiving app As passed to the corresponding AppDelegate method (iOS 8)
- OR
- options[UIApplicationLaunchOptionsAnnotationKey] (iOS 9+)
-
+ information to the receiving app As passed to the corresponding AppDelegate method
- returns: true if the url was meant to be handled by the SDK, false otherwise
*/
- func application(_ application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: Any?) -> Bool
+ func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
+
+ /**
+ Called via the RidesAppDelegate when the application is opened via a URL. Responsible
+ for parsing the url and creating an OAuthToken. (iOS 9+)
+
+ - parameter application: The UIApplication object. Pass in the value from the App Delegate
+ - parameter url: The URL resource to open. As passed to the corresponding AppDelegate methods
+ - parameter options: A dictionary of URL handling options. As passed to the corresponding AppDelegate method.
+
+ - returns: true if the url was meant to be handled by the SDK, false otherwise
+ */
+ @available(iOS 9.0, *)
+ func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool
/**
Called via the RidesAppDelegate when the application becomes active. Used to determine
diff --git a/source/UberRides/OAuth/LoginView.swift b/source/UberRides/OAuth/LoginView.swift
index 4a2dc111..2c940462 100644
--- a/source/UberRides/OAuth/LoginView.swift
+++ b/source/UberRides/OAuth/LoginView.swift
@@ -26,11 +26,11 @@ import Foundation
import WebKit
/// Login Web View class. Wrapper around a WKWebView to handle Login flow for Implicit Grant
-@objc(UBSDKLoginView) open class LoginView : UIView {
+@objc(UBSDKLoginView) open class LoginView: UIView {
open var loginAuthenticator: LoginViewAuthenticator
- var clientID = Configuration.getClientID()
+ var clientID = Configuration.shared.clientID
let webView: WKWebView
//MARK: Initializers
@@ -43,9 +43,9 @@ import WebKit
- returns: An initialized LoginWebView
*/
- @objc public init(loginAuthenticator: LoginViewAuthenticator, frame: CGRect) {
+ @objc public init(loginAuthenticator: LoginViewAuthenticator, frame: CGRect = CGRect.zero) {
let configuration = WKWebViewConfiguration()
- configuration.processPool = Configuration.processPool
+ configuration.processPool = Configuration.shared.processPool
webView = WKWebView.init(frame: frame, configuration: configuration)
self.loginAuthenticator = loginAuthenticator
super.init(frame: frame)
@@ -53,18 +53,6 @@ import WebKit
self.addSubview(webView)
setupWebView()
}
-
- /**
- Creates a LoginWebView for obtaining an access token.
- Defaults to a CGRectZero Frame
-
- - parameter loginAuthenticator: the login authentication process to use
-
- - returns: An initialized LoginWebView
- */
- @objc public convenience init(loginAuthenticator: LoginViewAuthenticator) {
- self.init(loginAuthenticator: loginAuthenticator, frame: CGRect.zero)
- }
/**
Initializer for adding a LoginWebView via Storyboard. If using this constructor,
@@ -130,7 +118,7 @@ extension LoginView : WKNavigationDelegate {
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
- if loginAuthenticator.handleRedirectRequest(navigationAction.request) {
+ if loginAuthenticator.handleRedirect(for: navigationAction.request) {
decisionHandler(WKNavigationActionPolicy.cancel)
} else {
decisionHandler(WKNavigationActionPolicy.allow)
diff --git a/source/UberRides/OAuth/UberAuthenticatingProtocol.swift b/source/UberRides/OAuth/UberAuthenticatingProtocol.swift
index d167afcd..ea5d9db8 100644
--- a/source/UberRides/OAuth/UberAuthenticatingProtocol.swift
+++ b/source/UberRides/OAuth/UberAuthenticatingProtocol.swift
@@ -52,7 +52,7 @@ protocol UberAuthenticating {
- returns: true if a redirect was handled, false otherwise.
*/
- func handleRedirectRequest(_ request: URLRequest) -> Bool
+ func handleRedirect(for request: URLRequest) -> Bool
/**
Performs login for the requested scopes.
diff --git a/source/UberRides/RequestDeeplink.swift b/source/UberRides/RequestDeeplink.swift
index 45b78c2b..921c2bea 100644
--- a/source/UberRides/RequestDeeplink.swift
+++ b/source/UberRides/RequestDeeplink.swift
@@ -38,7 +38,7 @@ import UIKit
@objc public init(rideParameters: RideParameters = RideParametersBuilder().build()) {
parameters = rideParameters
- clientID = Configuration.getClientID()
+ clientID = Configuration.shared.clientID
if rideParameters.source == nil {
rideParameters.source = RequestDeeplink.sourceString
diff --git a/source/UberRides/RideRequestButton.swift b/source/UberRides/RideRequestButton.swift
index 2e6d5727..813c49be 100644
--- a/source/UberRides/RideRequestButton.swift
+++ b/source/UberRides/RideRequestButton.swift
@@ -296,7 +296,7 @@ import CoreLocation
// Initiate deeplink when button is tapped
func uberButtonTapped(_ sender: UIButton) {
rideParameters.source = RideRequestButton.sourceString
- requestBehavior.requestRide(rideParameters)
+ requestBehavior.requestRide(parameters: rideParameters)
}
//Mark: Private Interface
diff --git a/source/UberRides/RideRequestView.swift b/source/UberRides/RideRequestView.swift
index aa3f01ec..6ee60f4e 100644
--- a/source/UberRides/RideRequestView.swift
+++ b/source/UberRides/RideRequestView.swift
@@ -67,7 +67,7 @@ import CoreLocation
self.rideParameters = rideParameters
self.accessToken = accessToken
let configuration = WKWebViewConfiguration()
- configuration.processPool = Configuration.processPool
+ configuration.processPool = Configuration.shared.processPool
webView = WKWebView(frame: CGRect.zero, configuration: configuration)
super.init(frame: frame)
initialSetup()
@@ -127,7 +127,7 @@ import CoreLocation
required public init?(coder aDecoder: NSCoder) {
rideParameters = RideParametersBuilder().build()
let configuration = WKWebViewConfiguration()
- configuration.processPool = Configuration.processPool
+ configuration.processPool = Configuration.shared.processPool
webView = WKWebView(frame: CGRect.zero, configuration: configuration)
super.init(coder: aDecoder)
initialSetup()
diff --git a/source/UberRides/RideRequestViewController.swift b/source/UberRides/RideRequestViewController.swift
index 7cbff26f..330201b9 100644
--- a/source/UberRides/RideRequestViewController.swift
+++ b/source/UberRides/RideRequestViewController.swift
@@ -106,7 +106,7 @@ import MapKit
}
rideRequestView.rideParameters = rideParameters
- rideRequestView.accessToken = TokenManager.fetchToken(accessTokenIdentifier, accessGroup: keychainAccessGroup)
+ rideRequestView.accessToken = TokenManager.fetchToken(identifier: accessTokenIdentifier, accessGroup: keychainAccessGroup)
}
// MARK: View Lifecycle
@@ -141,7 +141,7 @@ import MapKit
// MARK: Internal
func load() {
- if let accessToken = TokenManager.fetchToken(accessTokenIdentifier, accessGroup: keychainAccessGroup) {
+ if let accessToken = TokenManager.fetchToken(identifier: accessTokenIdentifier, accessGroup: keychainAccessGroup) {
rideRequestView.accessToken = accessToken
rideRequestView.isHidden = false
loginView.isHidden = true
@@ -278,7 +278,7 @@ import MapKit
}
nativeAuthenticator.deeplinkCompletion = { error in
if (error == nil) {
- RidesAppDelegate.sharedInstance.loginManager = self.loginManager
+ RidesAppDelegate.shared.loginManager = self.loginManager
}
};
}
@@ -311,20 +311,20 @@ extension RideRequestViewController : RideRequestViewDelegate {
}
private func attemptTokenRefresh(_ tokenIdentifier: String?, accessGroup: String?) {
- let identifer = tokenIdentifier ?? Configuration.getDefaultAccessTokenIdentifier()
- let group = accessGroup ?? Configuration.getDefaultKeychainAccessGroup()
- guard let accessToken = TokenManager.fetchToken(identifer, accessGroup: group), let refreshToken = accessToken.refreshToken else {
+ let identifer = tokenIdentifier ?? Configuration.shared.defaultAccessTokenIdentifier
+ let group = accessGroup ?? Configuration.shared.defaultKeychainAccessGroup
+ guard let accessToken = TokenManager.fetchToken(identifier: identifer, accessGroup: group), let refreshToken = accessToken.refreshToken else {
accessTokenWasUnauthorizedOnPreviousAttempt = true
- _ = TokenManager.deleteToken(identifer, accessGroup: group)
+ _ = TokenManager.deleteToken(identifier: identifer, accessGroup: group)
self.load()
return
}
- _ = TokenManager.deleteToken(accessTokenIdentifier, accessGroup: keychainAccessGroup)
+ _ = TokenManager.deleteToken(identifier: accessTokenIdentifier, accessGroup: keychainAccessGroup)
let ridesClient = RidesClient(accessTokenIdentifier: identifer, keychainAccessGroup: group)
- ridesClient.refreshAccessToken(refreshToken) { (accessToken, response) in
+ ridesClient.refreshAccessToken(usingRefreshToken: refreshToken) { (accessToken, response) in
if let token = accessToken {
- _ = TokenManager.saveToken(token, tokenIdentifier: self.accessTokenIdentifier, accessGroup: self.keychainAccessGroup)
+ _ = TokenManager.save(accessToken: token, tokenIdentifier: self.accessTokenIdentifier, accessGroup: self.keychainAccessGroup)
}
self.load()
}
diff --git a/source/UberRides/RideRequestViewRequestingBehavior.swift b/source/UberRides/RideRequestViewRequestingBehavior.swift
index bd91bb6b..a451eb14 100644
--- a/source/UberRides/RideRequestViewRequestingBehavior.swift
+++ b/source/UberRides/RideRequestViewRequestingBehavior.swift
@@ -83,10 +83,10 @@ extension RideRequestViewRequestingBehavior : RideRequesting {
Requests a ride by presenting a RideRequestView that is constructed using the provided
rideParameters
- - parameter rideParameters: The RideParameters to use for building and prefilling
+ - parameter parameters: The RideParameters to use for building and prefilling
the RideRequestView
*/
- public func requestRide(_ rideParameters: RideParameters?) {
+ public func requestRide(parameters rideParameters: RideParameters?) {
if let rideParameters = rideParameters {
modalRideRequestViewController.rideRequestViewController.rideRequestView.rideParameters = rideParameters
}
diff --git a/source/UberRides/RideRequestingProtocol.swift b/source/UberRides/RideRequestingProtocol.swift
index 1084e495..2356193d 100644
--- a/source/UberRides/RideRequestingProtocol.swift
+++ b/source/UberRides/RideRequestingProtocol.swift
@@ -30,7 +30,7 @@
/**
Requests a ride using the provided RideParameters.
- - parameter rideParameters: The RideParameters to use for the ride request
+ - parameter parameters: The RideParameters to use for the ride request
*/
- @objc func requestRide(_ rideParameters: RideParameters?)
+ @objc func requestRide(parameters: RideParameters?)
}
diff --git a/source/UberRides/RidesAppDelegate.swift b/source/UberRides/RidesAppDelegate.swift
index 41ae2f28..90cbc893 100644
--- a/source/UberRides/RidesAppDelegate.swift
+++ b/source/UberRides/RidesAppDelegate.swift
@@ -31,7 +31,7 @@
//MARK: Class variables
- open static let sharedInstance = RidesAppDelegate()
+ open static let shared = RidesAppDelegate()
//MARK: Public variables
@@ -57,7 +57,7 @@
application:openURL:sourceApplication:annotation: (iOS 8)
OR
app:openURL:options: (iOS 9+), passing in options[UIApplicationOpenURLOptionsSourceApplicationKey] as sourceApplication
-
+
- parameter application: Your singleton app object. As passed to the corresponding AppDelegate method
- parameter url: The URL resource to open. As passed to the corresponding AppDelegate methods
- parameter sourceApplication: The bundle ID of the app that is requesting
@@ -67,11 +67,11 @@
communicate information to the receiving app As passed to the corresponding AppDelegate method
- returns: true if the URL was intended for the Rides SDK, false otherwise
*/
- open func application(_ application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
+ open func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
guard let manager = loginManager else {
return false
}
- let urlHandled = manager.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
+ let urlHandled = manager.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
if (urlHandled) {
loginManager = nil
}
@@ -86,8 +86,8 @@
let manager = loginManager ?? LoginManager()
let sourceApplication = options[UIApplicationLaunchOptionsKey.sourceApplication] as? String
- let annotation = options[UIApplicationLaunchOptionsKey.annotation]
- let urlHandled = manager.application(application, openURL: launchURL, sourceApplication: sourceApplication, annotation: annotation)
+ let annotation = options[UIApplicationLaunchOptionsKey.annotation] as Any
+ let urlHandled = manager.application(application, open: launchURL, sourceApplication: sourceApplication, annotation: annotation)
loginManager = nil
return urlHandled
}
diff --git a/source/UberRides/RidesClient.swift b/source/UberRides/RidesClient.swift
index a20932bb..2bf646cb 100644
--- a/source/UberRides/RidesClient.swift
+++ b/source/UberRides/RidesClient.swift
@@ -29,7 +29,7 @@ import CoreLocation
@objc(UBSDKRidesClient) open class RidesClient: NSObject {
/// Application client ID. Required for every instance of RidesClient.
- var clientID: String = Configuration.getClientID()
+ var clientID: String = Configuration.shared.clientID
/// The Access Token Identifier. The identifier to use for looking up this client's accessToken
let accessTokenIdentifier: String
@@ -41,7 +41,7 @@ import CoreLocation
var session: URLSession
/// Developer server token.
- private var serverToken: String? = Configuration.getServerToken()
+ private var serverToken: String? = Configuration.shared.serverToken
/**
Initializer for the RidesClient. The RidesClient handles making requests to the API
@@ -98,7 +98,7 @@ import CoreLocation
@objc public convenience init(accessTokenIdentifier: String, sessionConfiguration: URLSessionConfiguration) {
self.init(accessTokenIdentifier: accessTokenIdentifier,
sessionConfiguration: sessionConfiguration,
- keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup())
+ keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
/**
@@ -115,7 +115,7 @@ import CoreLocation
@objc public convenience init(accessTokenIdentifier: String) {
self.init(accessTokenIdentifier: accessTokenIdentifier,
sessionConfiguration: URLSessionConfiguration.default,
- keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup())
+ keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
/**
@@ -128,9 +128,9 @@ import CoreLocation
- returns: An initialized RidesClient
*/
@objc public convenience override init() {
- self.init(accessTokenIdentifier: Configuration.getDefaultAccessTokenIdentifier(),
+ self.init(accessTokenIdentifier: Configuration.shared.defaultAccessTokenIdentifier,
sessionConfiguration: URLSessionConfiguration.default,
- keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup())
+ keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
/**
@@ -141,7 +141,7 @@ import CoreLocation
- returns: an AccessToken object, or nil if one can't be located
*/
@objc open func fetchAccessToken() -> AccessToken? {
- guard let accessToken = TokenManager.fetchToken(accessTokenIdentifier, accessGroup: keychainAccessGroup) else {
+ guard let accessToken = TokenManager.fetchToken(identifier: accessTokenIdentifier, accessGroup: keychainAccessGroup) else {
return nil
}
return accessToken
@@ -152,7 +152,7 @@ import CoreLocation
- returns: true if a server token exists, false otherwise.
*/
- @objc open func hasServerToken() -> Bool {
+ @objc open var hasServerToken: Bool {
return serverToken != nil
}
@@ -246,7 +246,7 @@ import CoreLocation
- parameter productID: string representing product ID.
- parameter completion: completion handler for returned product.
*/
- @objc open func fetchProduct(_ productID: String, completion:@escaping (_ product: UberProduct?, _ response: Response) -> Void) {
+ @objc open func fetchProduct(productID: String, completion:@escaping (_ product: UberProduct?, _ response: Response) -> Void) {
let endpoint = Products.getProduct(productID: productID)
apiCall(endpoint, completion: { response in
var product: UberProduct?
@@ -325,7 +325,7 @@ import CoreLocation
- parameter completion: completion handler for returned user profile.
*/
- @objc open func fetchUserProfile(_ completion:@escaping (_ profile: UserProfile?, _ response: Response) -> Void) {
+ @objc open func fetchUserProfile(completion:@escaping (_ profile: UserProfile?, _ response: Response) -> Void) {
let endpoint = Me.userProfile
apiCall(endpoint, completion: { response in
var userProfile: UserProfile?
@@ -339,11 +339,11 @@ import CoreLocation
/**
Request a ride on behalf of Uber user.
- - parameter rideParameters: RideParameters object containing paramaters for the request.
+ - parameter parameters: RideParameters object containing paramaters for the request.
- parameter completion: completion handler for returned request information.
*/
- @objc open func requestRide(_ rideParameters: RideParameters, completion:@escaping (_ ride: Ride?, _ response: Response) -> Void) {
- let endpoint = Requests.make(rideParameters: rideParameters)
+ @objc open func requestRide(parameters: RideParameters, completion:@escaping (_ ride: Ride?, _ response: Response) -> Void) {
+ let endpoint = Requests.make(rideParameters: parameters)
apiCallForRideResponse(endpoint, completion: completion)
}
@@ -352,7 +352,7 @@ import CoreLocation
- parameter completion: completion handler for returned ride information.
*/
- @objc open func fetchCurrentRide(_ completion: @escaping (_ ride: Ride?, _ response: Response) -> Void) {
+ @objc open func fetchCurrentRide(completion: @escaping (_ ride: Ride?, _ response: Response) -> Void) {
let endpoint = Requests.getCurrent
apiCallForRideResponse(endpoint, completion: completion)
}
@@ -363,7 +363,7 @@ import CoreLocation
- parameter requestID: unique identifier representing a Request.
- parameter completion: completion handler for returned trip information.
*/
- @objc open func fetchRideDetails(_ requestID: String, completion:@escaping (_ ride: Ride? , _ response: Response) -> Void) {
+ @objc open func fetchRideDetails(requestID: String, completion:@escaping (_ ride: Ride? , _ response: Response) -> Void) {
let endpoint = Requests.getRequest(requestID: requestID)
apiCallForRideResponse(endpoint, completion: completion)
}
@@ -374,8 +374,8 @@ import CoreLocation
- parameter rideParameters: RideParameters object containing necessary information.
- parameter completion: completion handler for returned estimate.
*/
- @objc open func fetchRideRequestEstimate(_ rideParameters: RideParameters, completion:@escaping (_ estimate: RideEstimate?, _ response: Response) -> Void) {
- let endpoint = Requests.estimate(rideParameters: rideParameters)
+ @objc open func fetchRideRequestEstimate(parameters: RideParameters, completion:@escaping (_ estimate: RideEstimate?, _ response: Response) -> Void) {
+ let endpoint = Requests.estimate(rideParameters: parameters)
apiCall(endpoint, completion: { response in
var estimate: RideEstimate? = nil
if response.error == nil {
@@ -390,7 +390,7 @@ import CoreLocation
- parameter completion: completion handler for returned payment method list as well as last used payment method.
*/
- @objc open func fetchPaymentMethods(_ completion:@escaping (_ methods: [PaymentMethod], _ lastUsed: PaymentMethod?, _ response: Response) -> Void) {
+ @objc open func fetchPaymentMethods(completion:@escaping (_ methods: [PaymentMethod], _ lastUsed: PaymentMethod?, _ response: Response) -> Void) {
let endpoint = Payment.getMethods
apiCall(endpoint, completion: { response in
var paymentMethods = [PaymentMethod]()
@@ -412,7 +412,7 @@ import CoreLocation
- parameter placeID: the name of the place to retrieve. Only home and work are acceptable.
- parameter completion: completion handler for returned place.
*/
- @objc open func fetchPlace(_ placeID: String, completion:@escaping (_ place: Place?, _ response: Response) -> Void) {
+ @objc open func fetchPlace(placeID: String, completion:@escaping (_ place: Place?, _ response: Response) -> Void) {
let endpoint = Places.getPlace(placeID: placeID)
apiCall(endpoint, completion: { response in
var place: Place? = nil
@@ -430,7 +430,7 @@ import CoreLocation
- parameter address: the address of the place that should be tied to the given placeID.
- parameter completion: completion handler for response.
*/
- @objc open func updatePlace(_ placeID: String, withAddress address: String, completion:@escaping (_ place: Place?, _ response: Response) -> Void) {
+ @objc open func updatePlace(placeID: String, withAddress address: String, completion:@escaping (_ place: Place?, _ response: Response) -> Void) {
let endpoint = Places.putPlace(placeID: placeID, address: address)
apiCall(endpoint, completion: { response in
var place: Place?
@@ -448,9 +448,9 @@ import CoreLocation
- parameter rideParameters: the RideParameters object containing the updated parameters.
- parameter completion: completion handler for response.
*/
- @objc open func updateRideDetails(_ requestID: String?, rideParameters: RideParameters, completion:@escaping (_ response: Response) -> Void) {
+ @objc open func updateRideDetails(requestID: String?, rideParameters: RideParameters, completion:@escaping (_ response: Response) -> Void) {
guard let requestID = requestID else {
- updateCurrentRide(rideParameters, completion: completion)
+ updateCurrentRide(rideParameters: rideParameters, completion: completion)
return
}
@@ -466,7 +466,7 @@ import CoreLocation
- parameter rideParameters: RideParameters object with updated ride parameters.
- parameter completion: completion handler for response.
*/
- @objc open func updateCurrentRide(_ rideParameters: RideParameters, completion:@escaping (_ response: Response) -> Void) {
+ @objc open func updateCurrentRide(rideParameters: RideParameters, completion:@escaping (_ response: Response) -> Void) {
let endpoint = Requests.patchCurrent(rideParameters: rideParameters)
apiCall(endpoint, completion: { response in
completion(response)
@@ -479,9 +479,9 @@ import CoreLocation
- parameter requestID: request ID of the ride. If nil, current ride will be canceled.
- parameter completion: completion handler for response.
*/
- @objc open func cancelRide(_ requestID: String?, completion:@escaping (_ response: Response) -> Void) {
+ @objc open func cancelRide(requestID: String?, completion:@escaping (_ response: Response) -> Void) {
guard let requestID = requestID else {
- cancelCurrentRide(completion)
+ cancelCurrentRide(completion: completion)
return
}
@@ -496,7 +496,7 @@ import CoreLocation
- parameter completion: completion handler for response
*/
- @objc open func cancelCurrentRide(_ completion:@escaping (_ response: Response) -> Void) {
+ @objc open func cancelCurrentRide(completion:@escaping (_ response: Response) -> Void) {
let endpoint = Requests.deleteCurrent
apiCall(endpoint, completion: { response in
completion(response)
@@ -509,7 +509,7 @@ import CoreLocation
- parameter requestID: unique identifier representing a ride request
- parameter completion: completion handler for receipt
*/
- open func fetchRideReceipt(_ requestID: String, completion:@escaping (_ rideReceipt: RideReceipt?, _ response: Response) -> Void) {
+ open func fetchRideReceipt(requestID: String, completion:@escaping (_ rideReceipt: RideReceipt?, _ response: Response) -> Void) {
let endpoint = Requests.rideReceipt(requestID: requestID)
apiCall(endpoint, completion: { response in
var receipt: RideReceipt?
@@ -526,7 +526,7 @@ import CoreLocation
- parameter requestID: unique identifier representing a request
- parameter completion: completion handler for map
*/
- open func fetchRideMap(_ requestID: String, completion:@escaping (_ map: RideMap?, _ response: Response) -> Void) {
+ open func fetchRideMap(requestID: String, completion:@escaping (_ map: RideMap?, _ response: Response) -> Void) {
let endpoint = Requests.rideMap(requestID: requestID)
apiCall(endpoint, completion: { response in
var map: RideMap?
@@ -544,7 +544,7 @@ import CoreLocation
- parameter refreshToken: The Refresh Token String from an SSO access token
- parameter completion: completion handler for the new access token
*/
- open func refreshAccessToken(_ refreshToken: String, completion:@escaping (_ accessToken: AccessToken?, _ response: Response) -> Void) {
+ open func refreshAccessToken(usingRefreshToken refreshToken: String, completion:@escaping (_ accessToken: AccessToken?, _ response: Response) -> Void) {
let endpoint = OAuth.refresh(clientID: clientID, refreshToken: refreshToken)
apiCall(endpoint) { response in
var accessToken: AccessToken?
diff --git a/source/UberRides/TokenManager.swift b/source/UberRides/TokenManager.swift
index 86ae1d04..fd903990 100644
--- a/source/UberRides/TokenManager.swift
+++ b/source/UberRides/TokenManager.swift
@@ -27,8 +27,8 @@ import Foundation
/// Manager class for saving and deleting AccessTokens. Allows you to manage tokens based on token identifier & keychain access group
@objc(UBSDKTokenManager) public class TokenManager: NSObject {
- public static let TokenManagerDidSaveTokenNotification = "TokenManagerDidSaveTokenNotification"
- public static let TokenManagerDidDeleteTokenNotification = "TokenManagerDidDeleteTokenNotification"
+ public static let tokenManagerDidSaveTokenNotification = "TokenManagerDidSaveTokenNotification"
+ public static let tokenManagerDidDeleteTokenNotification = "TokenManagerDidDeleteTokenNotification"
private static let keychainWrapper = KeychainWrapper()
@@ -37,14 +37,14 @@ import Foundation
/**
Gets the AccessToken for the given tokenIdentifier and accessGroup.
- - parameter tokenIdentifier: The token identifier string to use
+ - parameter identifier: The token identifier string to use
- parameter accessGroup: The keychain access group to use
- returns: An AccessToken, or nil if one wasn't found
*/
- @objc public static func fetchToken(_ tokenIdentifier: String, accessGroup: String) -> AccessToken? {
+ @objc public static func fetchToken(identifier: String, accessGroup: String) -> AccessToken? {
keychainWrapper.setAccessGroup(accessGroup)
- guard let token = keychainWrapper.getObjectForKey(tokenIdentifier) as? AccessToken else {
+ guard let token = keychainWrapper.getObjectForKey(identifier) as? AccessToken else {
return nil
}
return token
@@ -58,9 +58,9 @@ import Foundation
- returns: An AccessToken, or nil if one wasn't found
*/
- @objc public static func fetchToken(_ tokenIdentifier: String) -> AccessToken? {
- return self.fetchToken(tokenIdentifier,
- accessGroup: Configuration.getDefaultKeychainAccessGroup())
+ @objc public static func fetchToken(identifier: String) -> AccessToken? {
+ return self.fetchToken(identifier: identifier,
+ accessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
/**
@@ -70,8 +70,8 @@ import Foundation
- returns: An AccessToken, or nil if one wasn't found
*/
@objc public static func fetchToken() -> AccessToken? {
- return self.fetchToken(Configuration.getDefaultAccessTokenIdentifier(),
- accessGroup: Configuration.getDefaultKeychainAccessGroup())
+ return self.fetchToken(identifier: Configuration.shared.defaultAccessTokenIdentifier,
+ accessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
//MARK: Save
@@ -83,16 +83,16 @@ import Foundation
Access Token is saved syncronously
- parameter accessToken: The AccessToken to save
- - parameter tokenIdentifier: The token identifier string to use (defaults to Configuration.getDefaultAccessTokenIdentifier())
- - parameter accessGroup: The keychain access group to use (defaults to Configuration.getDefaultKeychainAccessGroup())
+ - parameter tokenIdentifier: The token identifier string to use (defaults to Configuration.shared.defaultAccessTokenIdentifier)
+ - parameter accessGroup: The keychain access group to use (defaults to Configuration.shared.defaultKeychainAccessGroup)
- returns: true if the accessToken was saved successfully, false otherwise
*/
- @objc public static func saveToken(_ accessToken: AccessToken, tokenIdentifier: String, accessGroup: String) -> Bool {
+ @objc public static func save(accessToken: AccessToken, tokenIdentifier: String, accessGroup: String) -> Bool {
keychainWrapper.setAccessGroup(accessGroup)
let success = keychainWrapper.setObject(accessToken, key: tokenIdentifier)
if success {
- NotificationCenter.default.post(name: Notification.Name(rawValue: TokenManagerDidSaveTokenNotification), object: self)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: tokenManagerDidSaveTokenNotification), object: self)
}
return success
}
@@ -108,8 +108,8 @@ import Foundation
- returns: true if the accessToken was saved successfully, false otherwise
*/
- @objc public static func saveToken(_ accessToken: AccessToken, tokenIdentifier: String) -> Bool {
- return self.saveToken(accessToken, tokenIdentifier: tokenIdentifier, accessGroup: Configuration.getDefaultKeychainAccessGroup())
+ @objc public static func save(accessToken: AccessToken, tokenIdentifier: String) -> Bool {
+ return self.save(accessToken: accessToken, tokenIdentifier: tokenIdentifier, accessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
/**
@@ -123,8 +123,8 @@ import Foundation
- returns: true if the accessToken was saved successfully, false otherwise
*/
- @objc public static func saveToken(_ accessToken: AccessToken) -> Bool {
- return self.saveToken(accessToken, tokenIdentifier: Configuration.getDefaultAccessTokenIdentifier(), accessGroup: Configuration.getDefaultKeychainAccessGroup())
+ @objc public static func save(accessToken: AccessToken) -> Bool {
+ return self.save(accessToken: accessToken, tokenIdentifier: Configuration.shared.defaultAccessTokenIdentifier, accessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
//MARK: Delete
@@ -133,17 +133,17 @@ import Foundation
Deletes the AccessToken for the givent tokenIdentifier and accessGroup. If no values
are supplied, it uses the defaults defined in your Configuration.
- - parameter tokenIdentifier: The token identifier string to use (defaults to Configuration.getDefaultAccessTokenIdentifier())
- - parameter accessGroup: The keychain access group to use (defaults to Configuration.getDefaultKeychainAccessGroup())
+ - parameter tokenIdentifier: The token identifier string to use (defaults to Configuration.shared.defaultAccessTokenIdentifier)
+ - parameter accessGroup: The keychain access group to use (defaults to Configuration.shared.defaultKeychainAccessGroup)
- returns: true if the token was deleted, false otherwise
*/
- @objc public static func deleteToken(_ tokenIdentifier: String, accessGroup: String) -> Bool {
+ @objc public static func deleteToken(identifier: String, accessGroup: String) -> Bool {
keychainWrapper.setAccessGroup(accessGroup)
deleteCookies()
- let success = keychainWrapper.deleteObjectForKey(tokenIdentifier)
+ let success = keychainWrapper.deleteObjectForKey(identifier)
if success {
- NotificationCenter.default.post(name: Notification.Name(rawValue: TokenManagerDidDeleteTokenNotification), object: self)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: tokenManagerDidDeleteTokenNotification), object: self)
}
return success
}
@@ -156,8 +156,8 @@ import Foundation
- returns: true if the token was deleted, false otherwise
*/
- @objc public static func deleteToken(_ tokenIdentifier: String) -> Bool {
- return self.deleteToken(tokenIdentifier, accessGroup: Configuration.getDefaultKeychainAccessGroup())
+ @objc public static func deleteToken(identifier: String) -> Bool {
+ return self.deleteToken(identifier: identifier, accessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
/**
@@ -168,15 +168,15 @@ import Foundation
- returns: true if the token was deleted, false otherwise
*/
@objc public static func deleteToken() -> Bool {
- return self.deleteToken(Configuration.getDefaultAccessTokenIdentifier(), accessGroup: Configuration.getDefaultKeychainAccessGroup())
+ return self.deleteToken(identifier: Configuration.shared.defaultAccessTokenIdentifier, accessGroup: Configuration.shared.defaultKeychainAccessGroup)
}
// MARK: Private Interface
private static func deleteCookies() {
- Configuration.resetProcessPool()
+ Configuration.shared.resetProcessPool()
var urlsToClear = [URL]()
- if let loginURL = URL(string: OAuth.regionHostString(.default)) {
+ if let loginURL = URL(string: OAuth.regionHost) {
urlsToClear.append(loginURL)
}
diff --git a/source/UberRides/Utilities/AuthenticationURLUtility.swift b/source/UberRides/Utilities/AuthenticationURLUtility.swift
index 12d6a0c8..1b378d59 100644
--- a/source/UberRides/Utilities/AuthenticationURLUtility.swift
+++ b/source/UberRides/Utilities/AuthenticationURLUtility.swift
@@ -29,7 +29,6 @@ class AuthenticationURLUtility {
static let appNameKey = "third_party_app_name"
static let callbackURIKey = "callback_uri_string"
static let clientIDKey = "client_id"
- static let loginTypeKey = "login_type"
static let scopesKey = "scope"
static let sdkKey = "sdk"
static let sdkVersionKey = "sdk_version"
@@ -39,20 +38,19 @@ class AuthenticationURLUtility {
static func buildQueryParameters(_ scopes: [RidesScope]) -> [URLQueryItem] {
var queryItems = [URLQueryItem]()
- queryItems.append(URLQueryItem(name: appNameKey, value: Configuration.getAppDisplayName()))
- queryItems.append(URLQueryItem(name: callbackURIKey, value: Configuration.getCallbackURIString(.native)))
- queryItems.append(URLQueryItem(name: clientIDKey, value: Configuration.getClientID()))
- queryItems.append(URLQueryItem(name: loginTypeKey, value: Configuration.regionString))
+ queryItems.append(URLQueryItem(name: appNameKey, value: Configuration.shared.appDisplayName))
+ queryItems.append(URLQueryItem(name: callbackURIKey, value: Configuration.shared.getCallbackURIString(for: .native)))
+ queryItems.append(URLQueryItem(name: clientIDKey, value: Configuration.shared.clientID))
queryItems.append(URLQueryItem(name: scopesKey, value: scopes.toRidesScopeString()))
queryItems.append(URLQueryItem(name: sdkKey, value: sdkValue))
- queryItems.append(URLQueryItem(name: sdkVersionKey, value: Configuration.sdkVersion))
+ queryItems.append(URLQueryItem(name: sdkVersionKey, value: Configuration.shared.sdkVersion))
return queryItems
}
static func shouldHandleRedirectURL(_ URL: Foundation.URL, type: CallbackURIType) -> Bool {
guard let redirectURLComponents = URLComponents(url: URL, resolvingAgainstBaseURL: false),
- let expectedURLComponents = URLComponents(string: Configuration.getCallbackURIString(type)) else {
+ let expectedURLComponents = URLComponents(string: Configuration.shared.getCallbackURIString(for: type)) else {
return false
}
@@ -60,7 +58,7 @@ class AuthenticationURLUtility {
(redirectURLComponents.host?.lowercased() == expectedURLComponents.host?.lowercased())
var isLoginError = false
- if let loginURLComponents = URLComponents(string: OAuth.regionHostString()) {
+ if let loginURLComponents = URLComponents(string: OAuth.regionHost) {
isLoginError = (loginURLComponents.host == redirectURLComponents.host) && redirectURLComponents.path.contains("errors")
}
diff --git a/source/UberRides/Utilities/RidesUtil.swift b/source/UberRides/Utilities/RidesUtil.swift
index a01aab2e..65b34213 100644
--- a/source/UberRides/Utilities/RidesUtil.swift
+++ b/source/UberRides/Utilities/RidesUtil.swift
@@ -157,7 +157,7 @@ class RequestURLUtil {
var queryItems = [URLQueryItem]()
queryItems.append(URLQueryItem(name: RequestURLUtil.actionKey, value: RequestURLUtil.setPickupValue))
- queryItems.append(URLQueryItem(name: RequestURLUtil.clientIDKey, value: Configuration.getClientID()))
+ queryItems.append(URLQueryItem(name: RequestURLUtil.clientIDKey, value: Configuration.shared.clientID))
if let productID = rideParameters.productID {
queryItems.append(URLQueryItem(name: RequestURLUtil.productIDKey, value: productID))
diff --git a/source/UberRidesTests/APIManagerTests.swift b/source/UberRidesTests/APIManagerTests.swift
index d4c1f25f..6b1af163 100644
--- a/source/UberRidesTests/APIManagerTests.swift
+++ b/source/UberRidesTests/APIManagerTests.swift
@@ -61,7 +61,7 @@ class APIManagerTests: XCTestCase {
override func setUp() {
super.setUp()
Configuration.restoreDefaults()
- Configuration.setSandboxEnabled(true)
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
diff --git a/source/UberRidesTests/AccessTokenFactoryTests.swift b/source/UberRidesTests/AccessTokenFactoryTests.swift
index a7f9734d..aa59abe9 100644
--- a/source/UberRidesTests/AccessTokenFactoryTests.swift
+++ b/source/UberRidesTests/AccessTokenFactoryTests.swift
@@ -56,7 +56,7 @@ class AccessTokenFactoryTests: XCTestCase {
do {
let expectedExpirationInterval = Date().timeIntervalSince1970 + expirationTime
- let token : AccessToken = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ let token : AccessToken = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTAssertNotNil(token)
XCTAssertEqual(token.tokenString, tokenString)
XCTAssertEqual(token.refreshToken, refreshTokenString)
@@ -86,7 +86,7 @@ class AccessTokenFactoryTests: XCTestCase {
return
}
do {
- _ = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ _ = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTFail("Didn't parse out error")
} catch let error as NSError {
XCTAssertEqual(error.code, RidesAuthenticationErrorType.invalidRequest.rawValue)
@@ -105,7 +105,7 @@ class AccessTokenFactoryTests: XCTestCase {
return
}
do {
- _ = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ _ = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTFail("Didn't parse out error")
} catch let error as NSError {
XCTAssertEqual(error.code, RidesAuthenticationErrorType.invalidRequest.rawValue)
@@ -124,7 +124,7 @@ class AccessTokenFactoryTests: XCTestCase {
return
}
do {
- let token : AccessToken = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ let token : AccessToken = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTAssertNotNil(token)
XCTAssertEqual(token.tokenString, tokenString)
XCTAssertNil(token.refreshToken)
@@ -147,7 +147,7 @@ class AccessTokenFactoryTests: XCTestCase {
return
}
do {
- _ = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ _ = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTFail("Didn't parse out error")
} catch let error as NSError {
XCTAssertEqual(error.code, RidesAuthenticationErrorType.invalidRequest.rawValue)
@@ -169,7 +169,7 @@ class AccessTokenFactoryTests: XCTestCase {
do {
let expectedExpirationInterval = Date().timeIntervalSince1970 + expirationTime
- let token : AccessToken = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ let token : AccessToken = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTAssertNotNil(token)
XCTAssertEqual(token.tokenString, tokenString)
XCTAssertEqual(token.refreshToken, refreshTokenString)
@@ -199,7 +199,7 @@ class AccessTokenFactoryTests: XCTestCase {
return
}
do {
- let token : AccessToken = try AccessTokenFactory.createAccessTokenFromRedirectURL(url)
+ let token : AccessToken = try AccessTokenFactory.createAccessToken(fromRedirectURL: url)
XCTAssertNotNil(token)
XCTAssertEqual(token.tokenString, tokenString)
XCTAssertNil(token.refreshToken)
@@ -215,7 +215,7 @@ class AccessTokenFactoryTests: XCTestCase {
func testParseValidJsonStringToAccessToken() {
let tokenString = "tokenString1234"
let jsonString = "{\"access_token\": \"\(tokenString)\"}"
- let accessToken = AccessTokenFactory.createAccessTokenFromJSONString(string: jsonString)
+ let accessToken = AccessTokenFactory.createAccessToken(fromJSONString: jsonString)
XCTAssertNotNil(accessToken)
XCTAssertEqual(accessToken?.tokenString, tokenString)
@@ -224,7 +224,7 @@ class AccessTokenFactoryTests: XCTestCase {
func testParseInvalidJsonStringToAccessToken() {
let tokenString = "tokenString1234"
let jsonString = "{\"access_token\": \"\(tokenString)\""
- let accessToken = AccessTokenFactory.createAccessTokenFromJSONString(string: jsonString)
+ let accessToken = AccessTokenFactory.createAccessToken(fromJSONString: jsonString)
XCTAssertNil(accessToken)
}
diff --git a/source/UberRidesTests/AuthenticationDeeplinkTests.swift b/source/UberRidesTests/AuthenticationDeeplinkTests.swift
index cd565b26..954071c0 100644
--- a/source/UberRidesTests/AuthenticationDeeplinkTests.swift
+++ b/source/UberRidesTests/AuthenticationDeeplinkTests.swift
@@ -30,9 +30,9 @@ class AuthenticationDeeplinkTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}
diff --git a/source/UberRidesTests/AuthenticationURLUtilityTests.swift b/source/UberRidesTests/AuthenticationURLUtilityTests.swift
index c2a4a4a3..35ed7737 100644
--- a/source/UberRidesTests/AuthenticationURLUtilityTests.swift
+++ b/source/UberRidesTests/AuthenticationURLUtilityTests.swift
@@ -30,9 +30,9 @@ class AuthenticationURLUtilityTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}
@@ -41,7 +41,7 @@ class AuthenticationURLUtilityTests: XCTestCase {
super.tearDown()
}
- func testBuildQueryParameters_withDefaultRegion_withSingleScope() {
+ func testBuildQueryParameters_withSingleScope() {
let scopes = [RidesScope.RideWidgets]
@@ -49,7 +49,6 @@ class AuthenticationURLUtilityTests: XCTestCase {
let expectedClientID = "testClientID"
let expectedAppName = "My Awesome App"
let expectedCallbackURI = "testURI://uberConnectNative"
- let expectedLoginType = "default"
let expectedSDK = "ios"
let expectedSDKVersion = versionNumber
@@ -57,11 +56,10 @@ class AuthenticationURLUtilityTests: XCTestCase {
let clientIDQueryItem = URLQueryItem(name: AuthenticationURLUtility.clientIDKey, value: expectedClientID)
let appNameQueryItem = URLQueryItem(name: AuthenticationURLUtility.appNameKey, value: expectedAppName)
let callbackURIQueryItem = URLQueryItem(name: AuthenticationURLUtility.callbackURIKey, value: expectedCallbackURI)
- let loginTypeQueryItem = URLQueryItem(name: AuthenticationURLUtility.loginTypeKey, value: expectedLoginType)
let sdkQueryItem = URLQueryItem(name: AuthenticationURLUtility.sdkKey, value: expectedSDK)
let sdkVersionQueryItem = URLQueryItem(name: AuthenticationURLUtility.sdkVersionKey, value: expectedSDKVersion)
- let expectedQueryItems = [scopeQueryItem, clientIDQueryItem, appNameQueryItem, callbackURIQueryItem, loginTypeQueryItem, sdkQueryItem, sdkVersionQueryItem]
+ let expectedQueryItems = [scopeQueryItem, clientIDQueryItem, appNameQueryItem, callbackURIQueryItem, sdkQueryItem, sdkVersionQueryItem]
let comparisonSet = NSSet(array: expectedQueryItems)
let testQueryItems = AuthenticationURLUtility.buildQueryParameters(scopes)
@@ -70,7 +68,7 @@ class AuthenticationURLUtilityTests: XCTestCase {
XCTAssertEqual(comparisonSet, testComparisonSet)
}
- func testBuildQueryParameters_withDefaultRegion_withMultipleScopes() {
+ func testBuildQueryParameters_withMultipleScopes() {
let scopes = [RidesScope.RideWidgets, RidesScope.AllTrips, RidesScope.History]
@@ -78,7 +76,6 @@ class AuthenticationURLUtilityTests: XCTestCase {
let expectedClientID = "testClientID"
let expectedAppName = "My Awesome App"
let expectedCallbackURI = "testURI://uberConnectNative"
- let expectedLoginType = "default"
let expectedSDK = "ios"
let expectedSDKVersion = versionNumber
@@ -86,11 +83,10 @@ class AuthenticationURLUtilityTests: XCTestCase {
let clientIDQueryItem = URLQueryItem(name: AuthenticationURLUtility.clientIDKey, value: expectedClientID)
let appNameQueryItem = URLQueryItem(name: AuthenticationURLUtility.appNameKey, value: expectedAppName)
let callbackURIQueryItem = URLQueryItem(name: AuthenticationURLUtility.callbackURIKey, value: expectedCallbackURI)
- let loginTypeQueryItem = URLQueryItem(name: AuthenticationURLUtility.loginTypeKey, value: expectedLoginType)
let sdkQueryItem = URLQueryItem(name: AuthenticationURLUtility.sdkKey, value: expectedSDK)
let sdkVersionQueryItem = URLQueryItem(name: AuthenticationURLUtility.sdkVersionKey, value: expectedSDKVersion)
- let expectedQueryItems = [scopeQueryItem, clientIDQueryItem, appNameQueryItem, callbackURIQueryItem, loginTypeQueryItem, sdkQueryItem, sdkVersionQueryItem]
+ let expectedQueryItems = [scopeQueryItem, clientIDQueryItem, appNameQueryItem, callbackURIQueryItem, sdkQueryItem, sdkVersionQueryItem]
let comparisonSet = NSSet(array: expectedQueryItems)
let testQueryItems = AuthenticationURLUtility.buildQueryParameters(scopes)
@@ -105,14 +101,14 @@ class AuthenticationURLUtilityTests: XCTestCase {
XCTFail()
return
}
- Configuration.setCallbackURIString(testRedirectURLString, type: .implicit)
+ Configuration.shared.setCallbackURIString(testRedirectURLString, type: .implicit)
XCTAssertFalse(AuthenticationURLUtility.shouldHandleRedirectURL(testRedirectURL, type: .general))
XCTAssertFalse(AuthenticationURLUtility.shouldHandleRedirectURL(testRedirectURL, type: .native))
XCTAssertFalse(AuthenticationURLUtility.shouldHandleRedirectURL(testRedirectURL, type: .authorizationCode))
XCTAssertTrue(AuthenticationURLUtility.shouldHandleRedirectURL(testRedirectURL, type: .implicit))
- Configuration.setCallbackURIString(nil, type: .implicit)
+ Configuration.shared.setCallbackURIString(nil, type: .implicit)
XCTAssertFalse(AuthenticationURLUtility.shouldHandleRedirectURL(testRedirectURL, type: .implicit))
}
diff --git a/source/UberRidesTests/BaseAuthenticatorTests.swift b/source/UberRidesTests/BaseAuthenticatorTests.swift
index 4aacd1da..8ba39178 100644
--- a/source/UberRidesTests/BaseAuthenticatorTests.swift
+++ b/source/UberRidesTests/BaseAuthenticatorTests.swift
@@ -35,11 +35,11 @@ class BaseAuthenticatorTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
- redirectURI = Configuration.getCallbackURIString(.general)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
+ redirectURI = Configuration.shared.getCallbackURIString(for: .general)
}
override func tearDown() {
@@ -67,20 +67,20 @@ class BaseAuthenticatorTests: XCTestCase {
var emptyRequest = URLRequest(url: url)
emptyRequest.url = nil
let baseAuthenticator = BaseAuthenticator(scopes: [])
- XCTAssertFalse(baseAuthenticator.handleRedirectRequest(emptyRequest))
+ XCTAssertFalse(baseAuthenticator.handleRedirect(for: emptyRequest))
}
func testBaseAuthenticator_handleRedirectFalse_whenURLNotRedirect() {
let redirectURLString = "testURI://redirect"
let notRedirectURLString = "testURI://notRedirect"
- Configuration.setCallbackURIString(redirectURLString, type: .general)
+ Configuration.shared.setCallbackURIString(redirectURLString, type: .general)
guard let notRedirectURL = URL(string: notRedirectURLString) else {
XCTFail()
return
}
let handleRequest = URLRequest(url: notRedirectURL)
let baseAuthenticator = BaseAuthenticator(scopes: [])
- XCTAssertFalse(baseAuthenticator.handleRedirectRequest(handleRequest))
+ XCTAssertFalse(baseAuthenticator.handleRedirect(for: handleRequest))
}
func testBaseAuthenticator_handleRedirectTrue_whenValidRedirect() {
@@ -91,7 +91,7 @@ class BaseAuthenticatorTests: XCTestCase {
}
let redirectURLString = "testURI://redirect?error=server_error"
- Configuration.setCallbackURIString(redirectURLString, type: .general)
+ Configuration.shared.setCallbackURIString(redirectURLString, type: .general)
guard let redirectURL = URL(string: redirectURLString) else {
XCTFail()
return
@@ -100,7 +100,7 @@ class BaseAuthenticatorTests: XCTestCase {
let baseAuthenticator = BaseAuthenticator(scopes: [])
baseAuthenticator.loginCompletion = loginCompletionBlock
- XCTAssertTrue(baseAuthenticator.handleRedirectRequest(handleRequest))
+ XCTAssertTrue(baseAuthenticator.handleRedirect(for: handleRequest))
waitForExpectations(timeout: 1, handler: nil)
}
diff --git a/source/UberRidesTests/BaseDeeplinkTests.swift b/source/UberRidesTests/BaseDeeplinkTests.swift
index 5badf367..ef65c3f5 100644
--- a/source/UberRidesTests/BaseDeeplinkTests.swift
+++ b/source/UberRidesTests/BaseDeeplinkTests.swift
@@ -30,9 +30,9 @@ class BaseDeeplinkTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}
diff --git a/source/UberRidesTests/ConfigurationTests.swift b/source/UberRidesTests/ConfigurationTests.swift
index fcbbbc91..9e7cfd46 100644
--- a/source/UberRidesTests/ConfigurationTests.swift
+++ b/source/UberRidesTests/ConfigurationTests.swift
@@ -36,14 +36,13 @@ class ConfigurationTests: XCTestCase {
private let defaultNativeCallbackString = "testURI://uberConnectNative"
private let defaultServerToken = "testServerToken"
private let defaultAccessTokenIdentifier = "RidesAccessTokenKey"
- private let defaultRegion = Region.default
private let defaultSandbox = false
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
}
override func tearDown() {
@@ -61,90 +60,67 @@ class ConfigurationTests: XCTestCase {
let newServerToken = "newserver"
let newGroup = "new group"
let newTokenId = "newTokenID"
- let newRegion = Region.china
let newSandbox = true
- Configuration.setClientID(newClientID)
- Configuration.setCallbackURIString(newCallback)
- Configuration.setAppDisplayName(newDisplay)
- Configuration.setServerToken(newServerToken)
- Configuration.setDefaultKeychainAccessGroup(newGroup)
- Configuration.setDefaultAccessTokenIdentifier(newTokenId)
- Configuration.setRegion(newRegion)
- Configuration.setSandboxEnabled(newSandbox)
+ Configuration.shared.clientID = newClientID
+ Configuration.shared.setCallbackURIString(newCallback)
+ Configuration.shared.appDisplayName = newDisplay
+ Configuration.shared.serverToken = newServerToken
+ Configuration.shared.defaultKeychainAccessGroup = newGroup
+ Configuration.shared.defaultAccessTokenIdentifier = newTokenId
+ Configuration.shared.isSandbox = newSandbox
- XCTAssertEqual(newClientID, Configuration.getClientID())
- XCTAssertEqual(newCallback, Configuration.getCallbackURIString())
- XCTAssertEqual(newDisplay, Configuration.getAppDisplayName())
- XCTAssertEqual(newServerToken, Configuration.getServerToken())
- XCTAssertEqual(newGroup, Configuration.getDefaultKeychainAccessGroup())
- XCTAssertEqual(newTokenId, Configuration.getDefaultAccessTokenIdentifier())
- XCTAssertEqual(newRegion, Configuration.getRegion())
- XCTAssertEqual(newSandbox, Configuration.getSandboxEnabled())
+ XCTAssertEqual(newClientID, Configuration.shared.clientID)
+ XCTAssertEqual(newCallback, Configuration.shared.getCallbackURIString())
+ XCTAssertEqual(newDisplay, Configuration.shared.appDisplayName)
+ XCTAssertEqual(newServerToken, Configuration.shared.serverToken)
+ XCTAssertEqual(newGroup, Configuration.shared.defaultKeychainAccessGroup)
+ XCTAssertEqual(newTokenId, Configuration.shared.defaultAccessTokenIdentifier)
+ XCTAssertEqual(newSandbox, Configuration.shared.isSandbox)
Configuration.restoreDefaults()
- XCTAssertEqual(Configuration.plistName, "Info")
- XCTAssertEqual(Configuration.bundle, Bundle.main)
-
Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- XCTAssertEqual(Configuration.getClientID(), defaultClientID)
- XCTAssertEqual(defaultGeneralCallbackString, Configuration.getCallbackURIString())
- XCTAssertEqual(defaultDisplayName, Configuration.getAppDisplayName())
- XCTAssertEqual(defaultServerToken, Configuration.getServerToken())
- XCTAssertEqual("", Configuration.getDefaultKeychainAccessGroup())
- XCTAssertEqual(defaultAccessTokenIdentifier, Configuration.getDefaultAccessTokenIdentifier())
- XCTAssertEqual(defaultRegion, Configuration.getRegion())
- XCTAssertEqual(defaultSandbox, Configuration.getSandboxEnabled())
+ XCTAssertEqual(Configuration.shared.clientID, defaultClientID)
+ XCTAssertEqual(defaultGeneralCallbackString, Configuration.shared.getCallbackURIString())
+ XCTAssertEqual(defaultDisplayName, Configuration.shared.appDisplayName)
+ XCTAssertEqual(defaultServerToken, Configuration.shared.serverToken)
+ XCTAssertEqual("", Configuration.shared.defaultKeychainAccessGroup)
+ XCTAssertEqual(defaultAccessTokenIdentifier, Configuration.shared.defaultAccessTokenIdentifier)
+ XCTAssertEqual(defaultSandbox, Configuration.shared.isSandbox)
}
//MARK: Client ID Tests
func testClientID_getDefault() {
- XCTAssertEqual(defaultClientID, Configuration.getClientID())
+ XCTAssertEqual(defaultClientID, Configuration.shared.clientID)
}
func testClientID_overwriteDefault() {
let clientID = "clientID"
- Configuration.setClientID(clientID)
- XCTAssertEqual(clientID, Configuration.getClientID())
- }
-
- func testClientID_resetDefault() {
- Configuration.setClientID("alternateClient")
-
- Configuration.setClientID(nil)
-
- XCTAssertEqual(defaultClientID, Configuration.getClientID())
+ Configuration.shared.clientID = clientID
+ XCTAssertEqual(clientID, Configuration.shared.clientID)
}
//MARK: Callback URI String Tests
func testCallbackURIString_getDefault() {
- XCTAssertEqual(defaultGeneralCallbackString, Configuration.getCallbackURIString())
+ XCTAssertEqual(defaultGeneralCallbackString, Configuration.shared.getCallbackURIString())
}
func testCallbackURIString_overwriteDefault() {
let callbackURIString = "callback://test"
- Configuration.setCallbackURIString(callbackURIString)
+ Configuration.shared.setCallbackURIString(callbackURIString)
- XCTAssertEqual(callbackURIString, Configuration.getCallbackURIString())
- }
-
- func testCallbackURIString_resetDefault() {
- Configuration.setCallbackURIString("testCallback://asdf")
-
- Configuration.setCallbackURIString(nil)
-
- XCTAssertEqual(defaultGeneralCallbackString, Configuration.getCallbackURIString())
+ XCTAssertEqual(callbackURIString, Configuration.shared.getCallbackURIString())
}
func testCallbackURIString_getDefault_getTypes() {
- XCTAssertEqual(defaultGeneralCallbackString, Configuration.getCallbackURIString(.general))
- XCTAssertEqual(defaultAuthorizationCodeCallbackString, Configuration.getCallbackURIString(.authorizationCode))
- XCTAssertEqual(defaultImplicitCallbackString, Configuration.getCallbackURIString(.implicit))
- XCTAssertEqual(defaultNativeCallbackString, Configuration.getCallbackURIString(.native))
+ XCTAssertEqual(defaultGeneralCallbackString, Configuration.shared.getCallbackURIString(for: .general))
+ XCTAssertEqual(defaultAuthorizationCodeCallbackString, Configuration.shared.getCallbackURIString(for: .authorizationCode))
+ XCTAssertEqual(defaultImplicitCallbackString, Configuration.shared.getCallbackURIString(for: .implicit))
+ XCTAssertEqual(defaultNativeCallbackString, Configuration.shared.getCallbackURIString(for: .native))
}
func testCallbackURIString_overwriteDefault_allTypes() {
@@ -153,15 +129,15 @@ class ConfigurationTests: XCTestCase {
let implicitCallbackString = "testURI://uberConnectImplicitNew"
let nativeCallbackString = "testURI://uberConnectNativeNew"
- Configuration.setCallbackURIString(generalCallbackString, type: .general)
- Configuration.setCallbackURIString(authorizationCodeCallbackString, type: .authorizationCode)
- Configuration.setCallbackURIString(implicitCallbackString, type: .implicit)
- Configuration.setCallbackURIString(nativeCallbackString, type: .native)
+ Configuration.shared.setCallbackURIString(generalCallbackString, type: .general)
+ Configuration.shared.setCallbackURIString(authorizationCodeCallbackString, type: .authorizationCode)
+ Configuration.shared.setCallbackURIString(implicitCallbackString, type: .implicit)
+ Configuration.shared.setCallbackURIString(nativeCallbackString, type: .native)
- XCTAssertEqual(generalCallbackString, Configuration.getCallbackURIString(.general))
- XCTAssertEqual(authorizationCodeCallbackString, Configuration.getCallbackURIString(.authorizationCode))
- XCTAssertEqual(implicitCallbackString, Configuration.getCallbackURIString(.implicit))
- XCTAssertEqual(nativeCallbackString, Configuration.getCallbackURIString(.native))
+ XCTAssertEqual(generalCallbackString, Configuration.shared.getCallbackURIString(for: .general))
+ XCTAssertEqual(authorizationCodeCallbackString, Configuration.shared.getCallbackURIString(for: .authorizationCode))
+ XCTAssertEqual(implicitCallbackString, Configuration.shared.getCallbackURIString(for: .implicit))
+ XCTAssertEqual(nativeCallbackString, Configuration.shared.getCallbackURIString(for: .native))
}
func testCallbackURIString_resetDefault_allTypes() {
@@ -170,20 +146,20 @@ class ConfigurationTests: XCTestCase {
let implicitCallbackString = "testURI://uberConnectImplicitNew"
let nativeCallbackString = "testURI://uberConnectNativeNew"
- Configuration.setCallbackURIString(generalCallbackString, type: .general)
- Configuration.setCallbackURIString(authorizationCodeCallbackString, type: .authorizationCode)
- Configuration.setCallbackURIString(implicitCallbackString, type: .implicit)
- Configuration.setCallbackURIString(nativeCallbackString, type: .native)
+ Configuration.shared.setCallbackURIString(generalCallbackString, type: .general)
+ Configuration.shared.setCallbackURIString(authorizationCodeCallbackString, type: .authorizationCode)
+ Configuration.shared.setCallbackURIString(implicitCallbackString, type: .implicit)
+ Configuration.shared.setCallbackURIString(nativeCallbackString, type: .native)
- Configuration.setCallbackURIString(nil, type: .general)
- Configuration.setCallbackURIString(nil, type: .authorizationCode)
- Configuration.setCallbackURIString(nil, type: .implicit)
- Configuration.setCallbackURIString(nil, type: .native)
+ Configuration.shared.setCallbackURIString(nil, type: .general)
+ Configuration.shared.setCallbackURIString(nil, type: .authorizationCode)
+ Configuration.shared.setCallbackURIString(nil, type: .implicit)
+ Configuration.shared.setCallbackURIString(nil, type: .native)
- XCTAssertEqual(defaultGeneralCallbackString, Configuration.getCallbackURIString(.general))
- XCTAssertEqual(defaultAuthorizationCodeCallbackString, Configuration.getCallbackURIString(.authorizationCode))
- XCTAssertEqual(defaultImplicitCallbackString, Configuration.getCallbackURIString(.implicit))
- XCTAssertEqual(defaultNativeCallbackString, Configuration.getCallbackURIString(.native))
+ XCTAssertEqual(defaultGeneralCallbackString, Configuration.shared.getCallbackURIString(for: .general))
+ XCTAssertEqual(defaultAuthorizationCodeCallbackString, Configuration.shared.getCallbackURIString(for: .authorizationCode))
+ XCTAssertEqual(defaultImplicitCallbackString, Configuration.shared.getCallbackURIString(for: .implicit))
+ XCTAssertEqual(defaultNativeCallbackString, Configuration.shared.getCallbackURIString(for: .native))
}
func testCallbackURIString_resetDefault_oneType() {
@@ -192,144 +168,99 @@ class ConfigurationTests: XCTestCase {
let implicitCallbackString = "testURI://uberConnectImplicitNew"
let nativeCallbackString = "testURI://uberConnectNativeNew"
- Configuration.setCallbackURIString(generalCallbackString, type: .general)
- Configuration.setCallbackURIString(authorizationCodeCallbackString, type: .authorizationCode)
- Configuration.setCallbackURIString(implicitCallbackString, type: .implicit)
- Configuration.setCallbackURIString(nativeCallbackString, type: .native)
+ Configuration.shared.setCallbackURIString(generalCallbackString, type: .general)
+ Configuration.shared.setCallbackURIString(authorizationCodeCallbackString, type: .authorizationCode)
+ Configuration.shared.setCallbackURIString(implicitCallbackString, type: .implicit)
+ Configuration.shared.setCallbackURIString(nativeCallbackString, type: .native)
- Configuration.setCallbackURIString(nil, type: .native)
+ Configuration.shared.setCallbackURIString(nil, type: .native)
- XCTAssertEqual(generalCallbackString, Configuration.getCallbackURIString(.general))
- XCTAssertEqual(authorizationCodeCallbackString, Configuration.getCallbackURIString(.authorizationCode))
- XCTAssertEqual(implicitCallbackString, Configuration.getCallbackURIString(.implicit))
- XCTAssertEqual(defaultNativeCallbackString, Configuration.getCallbackURIString(.native))
+ XCTAssertEqual(generalCallbackString, Configuration.shared.getCallbackURIString(for: .general))
+ XCTAssertEqual(authorizationCodeCallbackString, Configuration.shared.getCallbackURIString(for: .authorizationCode))
+ XCTAssertEqual(implicitCallbackString, Configuration.shared.getCallbackURIString(for: .implicit))
+ XCTAssertEqual(defaultNativeCallbackString, Configuration.shared.getCallbackURIString(for: .native))
}
func testCallbackURIStringFallback_whenCallbackURIsMissing() {
Configuration.plistName = "testInfoMissingCallbacks"
- XCTAssertEqual(defaultCallbackString, Configuration.getCallbackURIString(.general))
- XCTAssertEqual(defaultCallbackString, Configuration.getCallbackURIString(.authorizationCode))
- XCTAssertEqual(defaultCallbackString, Configuration.getCallbackURIString(.implicit))
- XCTAssertEqual(defaultCallbackString, Configuration.getCallbackURIString(.native))
+ XCTAssertEqual(defaultCallbackString, Configuration.shared.getCallbackURIString(for: .general))
+ XCTAssertEqual(defaultCallbackString, Configuration.shared.getCallbackURIString(for: .authorizationCode))
+ XCTAssertEqual(defaultCallbackString, Configuration.shared.getCallbackURIString(for: .implicit))
+ XCTAssertEqual(defaultCallbackString, Configuration.shared.getCallbackURIString(for: .native))
}
func testCallbackURIStringFallbackUsesGeneralOverride_whenCallbackURIsMissing() {
Configuration.plistName = "testInfoMissingCallbacks"
let override = "testURI://override"
- Configuration.setCallbackURIString(override, type: .general)
- XCTAssertEqual(override, Configuration.getCallbackURIString(.general))
- XCTAssertEqual(override, Configuration.getCallbackURIString(.authorizationCode))
- XCTAssertEqual(override, Configuration.getCallbackURIString(.implicit))
- XCTAssertEqual(override, Configuration.getCallbackURIString(.native))
+ Configuration.shared.setCallbackURIString(override, type: .general)
+ XCTAssertEqual(override, Configuration.shared.getCallbackURIString(for: .general))
+ XCTAssertEqual(override, Configuration.shared.getCallbackURIString(for: .authorizationCode))
+ XCTAssertEqual(override, Configuration.shared.getCallbackURIString(for: .implicit))
+ XCTAssertEqual(override, Configuration.shared.getCallbackURIString(for: .native))
}
//MARK: App Display Name Tests
func testAppDisplayName_getDefault() {
- XCTAssertEqual(defaultDisplayName, Configuration.getAppDisplayName())
+ XCTAssertEqual(defaultDisplayName, Configuration.shared.appDisplayName)
}
func testAppDisplayName_overwriteDefault() {
let appDisplayName = "Test App"
- Configuration.setAppDisplayName(appDisplayName)
+ Configuration.shared.appDisplayName = appDisplayName
- XCTAssertEqual(appDisplayName, Configuration.getAppDisplayName())
- }
-
- func testAppDisplayName_resetDefault() {
- Configuration.setAppDisplayName("new app name")
-
- Configuration.setAppDisplayName(nil)
-
- XCTAssertEqual(defaultDisplayName, Configuration.getAppDisplayName())
+ XCTAssertEqual(appDisplayName, Configuration.shared.appDisplayName)
}
//MARK: Server Token Tests
func testServerToken_getDefault() {
- XCTAssertEqual(defaultServerToken, Configuration.getServerToken())
+ XCTAssertEqual(defaultServerToken, Configuration.shared.serverToken)
}
func testServerToken_overwriteDefault() {
let serverToken = "nonDefaultToken"
- Configuration.setServerToken(serverToken)
+ Configuration.shared.serverToken = serverToken
- XCTAssertEqual(serverToken, Configuration.getServerToken())
- }
-
- func testServerToken_resetDefault() {
- Configuration.setServerToken("nonDefaultToken")
-
- Configuration.setServerToken(nil)
-
- XCTAssertEqual(defaultServerToken, Configuration.getServerToken())
+ XCTAssertEqual(serverToken, Configuration.shared.serverToken)
}
//MARK: Keychain Access Group Tests
func testDefaultKeychainAccessGroup_getDefault() {
- XCTAssertEqual("", Configuration.getDefaultKeychainAccessGroup())
+ XCTAssertEqual("", Configuration.shared.defaultKeychainAccessGroup)
}
func testDefaultKeychainAccessGroup_overwriteDefault() {
let defaultKeychainAccessGroup = "accessGroup"
- Configuration.setDefaultKeychainAccessGroup(defaultKeychainAccessGroup)
+ Configuration.shared.defaultKeychainAccessGroup = defaultKeychainAccessGroup
- XCTAssertEqual(defaultKeychainAccessGroup, Configuration.getDefaultKeychainAccessGroup())
+ XCTAssertEqual(defaultKeychainAccessGroup, Configuration.shared.defaultKeychainAccessGroup)
}
-
- func testDefaultKeychainAccessGroup_resetDefault() {
- Configuration.setDefaultKeychainAccessGroup("accessGroup")
-
- Configuration.setDefaultKeychainAccessGroup(nil)
-
- XCTAssertEqual("", Configuration.getDefaultKeychainAccessGroup())
- }
-
+
//MARK: Access token identifier tests
func testDefaultAccessTokenIdentifier_getDefault() {
- XCTAssertEqual(defaultAccessTokenIdentifier, Configuration.getDefaultAccessTokenIdentifier())
+ XCTAssertEqual(defaultAccessTokenIdentifier, Configuration.shared.defaultAccessTokenIdentifier)
}
func testDefaultAccessTokenIdentifier_overwriteDefault() {
let newIdentifier = "newIdentifier"
- Configuration.setDefaultAccessTokenIdentifier(newIdentifier)
+ Configuration.shared.defaultAccessTokenIdentifier = newIdentifier
- XCTAssertEqual(newIdentifier, Configuration.getDefaultAccessTokenIdentifier())
+ XCTAssertEqual(newIdentifier, Configuration.shared.defaultAccessTokenIdentifier)
}
-
- func testDefaultAccessTokenIdentifier_resetDefault() {
- Configuration.setDefaultAccessTokenIdentifier("newIdentifier")
- Configuration.setDefaultAccessTokenIdentifier(nil)
-
- XCTAssertEqual(defaultAccessTokenIdentifier, Configuration.getDefaultAccessTokenIdentifier())
- }
-
- //MARK: Region Tests
-
- func testRegion_getDefault() {
- XCTAssertEqual(defaultRegion, Configuration.getRegion())
- }
-
- func testRegion_overwriteDefault() {
- let newRegion = Region.china
- Configuration.setRegion(newRegion)
-
- XCTAssertEqual(newRegion, Configuration.getRegion())
- }
-
//MARK: Sandbox Tests
func testSandbox_getDefault() {
- XCTAssertEqual(defaultSandbox, Configuration.getSandboxEnabled())
+ XCTAssertEqual(defaultSandbox, Configuration.shared.isSandbox)
}
func testSandbox_overwriteDefault() {
let newSandbox = true
- Configuration.setSandboxEnabled(newSandbox)
+ Configuration.shared.isSandbox = newSandbox
- XCTAssertEqual(newSandbox, Configuration.getSandboxEnabled())
+ XCTAssertEqual(newSandbox, Configuration.shared.isSandbox)
}
}
diff --git a/source/UberRidesTests/DeeplinkRequestingBehaviorTests.swift b/source/UberRidesTests/DeeplinkRequestingBehaviorTests.swift
index 9d1d1319..9bf0a66a 100644
--- a/source/UberRidesTests/DeeplinkRequestingBehaviorTests.swift
+++ b/source/UberRidesTests/DeeplinkRequestingBehaviorTests.swift
@@ -32,11 +32,11 @@ class DeeplinkRequestingBehaviorTests : XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setClientID(clientID)
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.clientID = clientID
+ Configuration.shared.isSandbox = true
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
expectedDeeplinkUserAgent = "rides-ios-v\(versionNumber!)-deeplink"
expectedButtonUserAgent = "rides-ios-v\(versionNumber!)-button"
@@ -46,7 +46,7 @@ class DeeplinkRequestingBehaviorTests : XCTestCase {
Configuration.restoreDefaults()
super.tearDown()
}
-
+
/**
* Test createURL with source button.
*/
@@ -56,7 +56,7 @@ class DeeplinkRequestingBehaviorTests : XCTestCase {
let rideParameters = RideParametersBuilder().setSource(RideRequestButton.sourceString).build()
let requestingBehavior = DeeplinkRequestingBehavior()
- let appStoreDeeplink = requestingBehavior.createAppStoreDeeplink(rideParameters)
+ let appStoreDeeplink = requestingBehavior.createAppStoreDeeplink(rideParameters: rideParameters)
let components = URLComponents(url: appStoreDeeplink.deeplinkURL, resolvingAgainstBaseURL: false)
XCTAssertNotNil(components)
@@ -75,7 +75,7 @@ class DeeplinkRequestingBehaviorTests : XCTestCase {
let rideParameters = RideParametersBuilder().setSource(RequestDeeplink.sourceString).build()
let requestingBehavior = DeeplinkRequestingBehavior()
- let appStoreDeeplink = requestingBehavior.createAppStoreDeeplink(rideParameters)
+ let appStoreDeeplink = requestingBehavior.createAppStoreDeeplink(rideParameters: rideParameters)
let components = URLComponents(url: appStoreDeeplink.deeplinkURL, resolvingAgainstBaseURL: false)
XCTAssertNotNil(components)
@@ -94,7 +94,7 @@ class DeeplinkRequestingBehaviorTests : XCTestCase {
}
let requestingBehavior = DeeplinkRequestingBehaviorMock(testClosure: testClosure)
- requestingBehavior.requestRide(rideParameters)
+ requestingBehavior.requestRide(parameters: rideParameters)
waitForExpectations(timeout: 0.5, handler: nil)
}
diff --git a/source/UberRidesTests/LoginButtonTests.swift b/source/UberRidesTests/LoginButtonTests.swift
index 1397a84a..47c16e69 100644
--- a/source/UberRidesTests/LoginButtonTests.swift
+++ b/source/UberRidesTests/LoginButtonTests.swift
@@ -31,10 +31,10 @@ class LoginButtonTests : XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
keychain = KeychainWrapper()
let tokenData = ["access_token" : "testTokenString"]
testToken = AccessToken(JSON: tokenData)
@@ -51,7 +51,7 @@ class LoginButtonTests : XCTestCase {
_ = keychain.deleteObjectForKey(identifier)
- let token = TokenManager.fetchToken(identifier)
+ let token = TokenManager.fetchToken(identifier: identifier)
XCTAssertNil(token)
let loginManager = LoginManager(accessTokenIdentifier: identifier, keychainAccessGroup: nil, loginType: .implicit)
@@ -82,7 +82,7 @@ class LoginButtonTests : XCTestCase {
_ = keychain.deleteObjectForKey(identifier)
- let token = TokenManager.fetchToken(identifier)
+ let token = TokenManager.fetchToken(identifier: identifier)
XCTAssertNil(token)
let expectation = self.expectation(description: "Expected executeLogin() called")
@@ -120,7 +120,7 @@ class LoginButtonTests : XCTestCase {
XCTAssertEqual(loginButton.buttonState, LoginButtonState.signedIn)
loginButton.uberButtonTapped(loginButton)
- XCTAssertNil(TokenManager.fetchToken(identifier))
+ XCTAssertNil(TokenManager.fetchToken(identifier: identifier))
_ = keychain.deleteObjectForKey(identifier)
}
diff --git a/source/UberRidesTests/LoginManagerTests.swift b/source/UberRidesTests/LoginManagerTests.swift
index 9012aedd..e5c6aabb 100644
--- a/source/UberRidesTests/LoginManagerTests.swift
+++ b/source/UberRidesTests/LoginManagerTests.swift
@@ -30,10 +30,10 @@ class LoginManagerTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
@@ -75,7 +75,7 @@ class LoginManagerTests: XCTestCase {
}
authenticator.deeplinkCompletion?(nil)
- guard let ridesAppDelegateLoginManager = RidesAppDelegate.sharedInstance.loginManager as? LoginManagerPartialMock else {
+ guard let ridesAppDelegateLoginManager = RidesAppDelegate.shared.loginManager as? LoginManagerPartialMock else {
XCTFail("Expected RidesAppDelegate to have loginManager instance")
return
}
@@ -212,7 +212,7 @@ class LoginManagerTests: XCTestCase {
let testSourceApplication = "com.not.uber.app"
let testAnnotation = "annotation"
- XCTAssertFalse(loginManager.application(testApp, openURL: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
+ XCTAssertFalse(loginManager.application(testApp, open: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
}
func testOpenURLFails_whenNotNativeType() {
@@ -225,7 +225,7 @@ class LoginManagerTests: XCTestCase {
let testSourceApplication = "com.ubercab.foo"
let testAnnotation = "annotation"
- XCTAssertFalse(loginManager.application(testApp, openURL: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
+ XCTAssertFalse(loginManager.application(testApp, open: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
}
func testOpenURLSuccess() {
@@ -253,7 +253,7 @@ class LoginManagerTests: XCTestCase {
authenticatorMock.handleRedirectClosure = handleRedirectClosure
loginManager.authenticator = authenticatorMock
- XCTAssertTrue(loginManager.application(testApp, openURL: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
+ XCTAssertTrue(loginManager.application(testApp, open: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
waitForExpectations(timeout: 0.2) { _ in
XCTAssertFalse(loginManager.loggingIn)
@@ -315,7 +315,7 @@ class LoginManagerTests: XCTestCase {
let expectationNative = expectation(description: "executeLogin Native called")
let expectationAuthorizationCode = expectation(description: "executeLogin Authorization Code called")
- Configuration.setFallbackEnabled(true)
+ Configuration.shared.useFallback = true
let scopes = [RidesScope.Request]
let loginManagerMock = LoginManagerPartialMock(loginType: .native)
diff --git a/source/UberRidesTests/ModalViewControllerTests.swift b/source/UberRidesTests/ModalViewControllerTests.swift
index ff62a264..e1e5800e 100644
--- a/source/UberRidesTests/ModalViewControllerTests.swift
+++ b/source/UberRidesTests/ModalViewControllerTests.swift
@@ -31,10 +31,10 @@ class ModalViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
diff --git a/source/UberRidesTests/NativeAuthenticatorTests.swift b/source/UberRidesTests/NativeAuthenticatorTests.swift
index 95354dd2..4db7f3b9 100644
--- a/source/UberRidesTests/NativeAuthenticatorTests.swift
+++ b/source/UberRidesTests/NativeAuthenticatorTests.swift
@@ -35,11 +35,11 @@ class NativeAuthenticatorTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
- redirectURI = Configuration.getCallbackURIString(.native)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
+ redirectURI = Configuration.shared.getCallbackURIString(for: .native)
}
override func tearDown() {
diff --git a/source/UberRidesTests/OAuthTests.swift b/source/UberRidesTests/OAuthTests.swift
index bd21d4c8..24bfe113 100644
--- a/source/UberRidesTests/OAuthTests.swift
+++ b/source/UberRidesTests/OAuthTests.swift
@@ -35,11 +35,11 @@ class OAuthTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
- redirectURI = Configuration.getCallbackURIString()
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
+ redirectURI = Configuration.shared.getCallbackURIString()
}
override func tearDown() {
@@ -53,7 +53,7 @@ class OAuthTests: XCTestCase {
*/
func testParseAccessTokenFromRedirect() {
testExpectation = expectation(description: "success access token")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -76,7 +76,7 @@ class OAuthTests: XCTestCase {
*/
func testParseEmptyAccessTokenFromRedirect() {
testExpectation = expectation(description: "empty access token")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -100,7 +100,7 @@ class OAuthTests: XCTestCase {
*/
func testMismatchingRedirectError() {
testExpectation = expectation(description: "errors")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -125,7 +125,7 @@ class OAuthTests: XCTestCase {
*/
func testInvalidRedirectError() {
testExpectation = expectation(description: "errors")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -150,7 +150,7 @@ class OAuthTests: XCTestCase {
*/
func testInvalidClientIDError() {
testExpectation = expectation(description: "errors")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -175,7 +175,7 @@ class OAuthTests: XCTestCase {
*/
func testInvalidScopeError() {
testExpectation = expectation(description: "errors")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -200,7 +200,7 @@ class OAuthTests: XCTestCase {
*/
func testInvalidParametersError() {
testExpectation = expectation(description: "errors")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -225,7 +225,7 @@ class OAuthTests: XCTestCase {
*/
func testServerError() {
testExpectation = expectation(description: "errors")
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let loginBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
loginBehavior.loginCompletion = loginCompletion()
let loginView = LoginView(loginAuthenticator: loginBehavior)
@@ -305,7 +305,7 @@ class OAuthTests: XCTestCase {
Test that endpoint has correct query
*/
func testImplicitGrantAuthenticator_withScopes_returnsCorrectEndpoint() {
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let scopes = [RidesScope.Profile]
let expectedPath = "/oauth/v2/authorize"
let implicitGrantBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: scopes)
@@ -324,29 +324,29 @@ class OAuthTests: XCTestCase {
}
func testImplicitGrantRedirect_shouldReturnFalse_forNonRedirectUrlRequest() {
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let request = URLRequest(url: URL(string: "test://notRedirect")!)
let implicitGrantBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
implicitGrantBehavior.loginCompletion = { accessToken, error in
XCTAssert(false)
}
- let result = implicitGrantBehavior.handleRedirectRequest(request)
+ let result = implicitGrantBehavior.handleRedirect(for: request)
XCTAssertFalse(result)
}
func testAuthorizationCodeGrantRedirect_shouldReturnFalse_forNonRedirectUrlRequest() {
- redirectURI = Configuration.getCallbackURIString(.authorizationCode)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .authorizationCode)
let request = URLRequest(url: URL(string: "test://notRedirect")!)
let authorizationCodeGrantAuthenticator = AuthorizationCodeGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile], state: "state")
authorizationCodeGrantAuthenticator.loginCompletion = { accessToken, error in
XCTAssert(false)
}
- let result = authorizationCodeGrantAuthenticator.handleRedirectRequest(request)
+ let result = authorizationCodeGrantAuthenticator.handleRedirect(for: request)
XCTAssertFalse(result)
}
func testImplicitGrantRedirect_shouldReturnTrue_forCorrectRedirectRequest() {
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let tokenString = "accessToken1234"
guard let url = URL(string: "\(redirectURI)#access_token=\(tokenString)") else {
XCTFail()
@@ -361,7 +361,7 @@ class OAuthTests: XCTestCase {
XCTAssertEqual(accessToken?.tokenString, tokenString)
self.testExpectation.fulfill()
}
- let result = implicitGrantBehavior.handleRedirectRequest(request)
+ let result = implicitGrantBehavior.handleRedirect(for: request)
XCTAssertTrue(result)
waitForExpectations(timeout: timeout, handler: { error in
@@ -370,7 +370,7 @@ class OAuthTests: XCTestCase {
}
func testAuthorizationCodeGrantRedirect_shouldReturnTrue_forCorrectRedirectRequest() {
- redirectURI = Configuration.getCallbackURIString(.authorizationCode)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .authorizationCode)
let request = URLRequest(url: URL(string: redirectURI)!)
let loginCompletionExpectation = expectation(description: "call login completion")
let executeLoginExpectation = expectation(description: "execute login")
@@ -380,7 +380,7 @@ class OAuthTests: XCTestCase {
XCTAssertNil(accessToken)
loginCompletionExpectation.fulfill()
}
- let result = authorizationCodeGrantAuthenticator.handleRedirectRequest(request)
+ let result = authorizationCodeGrantAuthenticator.handleRedirect(for: request)
XCTAssertTrue(result)
waitForExpectations(timeout: timeout, handler: { error in
@@ -389,7 +389,7 @@ class OAuthTests: XCTestCase {
}
func testAuthorizationCodeGrantRedirect_shouldReturnTrue_forCorrectRedirectRequest_withErrorParameter() {
- redirectURI = Configuration.getCallbackURIString(.authorizationCode)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .authorizationCode)
guard var urlComponents = URLComponents(string: redirectURI) else {
XCTFail()
return
@@ -412,7 +412,7 @@ class OAuthTests: XCTestCase {
XCTAssertNil(accessToken)
loginCompletionExpectation.fulfill()
}
- let result = authorizationCodeGrantAuthenticator.handleRedirectRequest(request)
+ let result = authorizationCodeGrantAuthenticator.handleRedirect(for: request)
XCTAssertTrue(result)
waitForExpectations(timeout: timeout, handler: { error in
@@ -421,7 +421,7 @@ class OAuthTests: XCTestCase {
}
func testImplicitGrantRedirect_shouldReturnError_forEmptyAccessToken() {
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
let request = URLRequest(url: URL(string: "\(redirectURI)?error=mismatching_redirect_uri")!)
testExpectation = expectation(description: "call login completion with error")
let implicitGrantBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewController(), scopes: [.Profile])
@@ -436,7 +436,7 @@ class OAuthTests: XCTestCase {
self.testExpectation.fulfill()
}
- let result = implicitGrantBehavior.handleRedirectRequest(request)
+ let result = implicitGrantBehavior.handleRedirect(for: request)
XCTAssertTrue(result)
waitForExpectations(timeout: timeout, handler: { error in
@@ -445,7 +445,7 @@ class OAuthTests: XCTestCase {
}
func testImplicitGrantLogin_showsLogin() {
- redirectURI = Configuration.getCallbackURIString(.implicit)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .implicit)
testExpectation = expectation(description: "present login")
let implicitGrantBehavior = ImplicitGrantAuthenticator(presentingViewController: UIViewControllerMock(expectation: testExpectation), scopes: [.Profile])
@@ -457,7 +457,7 @@ class OAuthTests: XCTestCase {
}
func testAuthorizationCodeGrantLogin_showsLogin() {
- redirectURI = Configuration.getCallbackURIString(.authorizationCode)
+ redirectURI = Configuration.shared.getCallbackURIString(for: .authorizationCode)
testExpectation = expectation(description: "present login")
let implicitGrantBehavior = AuthorizationCodeGrantAuthenticator(presentingViewController: UIViewControllerMock(expectation: testExpectation), scopes: [.Profile], state: "state")
diff --git a/source/UberRidesTests/OauthEndpointTests.swift b/source/UberRidesTests/OauthEndpointTests.swift
index 5221e581..35eed245 100644
--- a/source/UberRidesTests/OauthEndpointTests.swift
+++ b/source/UberRidesTests/OauthEndpointTests.swift
@@ -32,9 +32,9 @@ class OauthEndpointTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
}
override func tearDown() {
@@ -42,16 +42,15 @@ class OauthEndpointTests: XCTestCase {
super.tearDown()
}
- func testLogin_withRegionDefault_withSandboxEnabled() {
- Configuration.setSandboxEnabled(true)
- Configuration.setRegion(Region.default)
+ func testLogin_withSandboxEnabled() {
+ Configuration.shared.isSandbox = true
let scopes = [ RidesScope.Profile, RidesScope.History ]
let expectedHost = "https://login.uber.com"
let expectedPath = "/oauth/v2/authorize"
let expectedScopes = scopes.toRidesScopeString()
- let expectedClientID = Configuration.getClientID()
- let expectedRedirect = Configuration.getCallbackURIString()
+ let expectedClientID = Configuration.shared.clientID
+ let expectedRedirect = Configuration.shared.getCallbackURIString()
let expectedTokenType = "token"
let expectedQueryItems = queryBuilder(
@@ -67,17 +66,16 @@ class OauthEndpointTests: XCTestCase {
XCTAssertEqual(login.path, expectedPath)
XCTAssertEqual(login.query, expectedQueryItems)
}
-
- func testLogin_withRegionDefault_withSandboxDisabled() {
- Configuration.setSandboxEnabled(false)
- Configuration.setRegion(Region.default)
+
+ func testLogin_withSandboxDisabled() {
+ Configuration.shared.isSandbox = false
let scopes = [ RidesScope.Profile, RidesScope.History ]
let expectedHost = "https://login.uber.com"
let expectedPath = "/oauth/v2/authorize"
let expectedScopes = scopes.toRidesScopeString()
- let expectedClientID = Configuration.getClientID()
- let expectedRedirect = Configuration.getCallbackURIString()
+ let expectedClientID = Configuration.shared.clientID
+ let expectedRedirect = Configuration.shared.getCallbackURIString()
let expectedTokenType = "token"
let expectedQueryItems = queryBuilder(
@@ -93,14 +91,14 @@ class OauthEndpointTests: XCTestCase {
XCTAssertEqual(login.path, expectedPath)
XCTAssertEqual(login.query, expectedQueryItems)
}
-
+
func testLogin_forAuthorizationCodeGrant_defaultSettings() {
let scopes = [ RidesScope.AllTrips, RidesScope.History ]
let expectedHost = "https://login.uber.com"
let expectedPath = "/oauth/v2/authorize"
let expectedScopes = scopes.toRidesScopeString()
- let expectedClientID = Configuration.getClientID()
- let expectedRedirect = Configuration.getCallbackURIString()
+ let expectedClientID = Configuration.shared.clientID
+ let expectedRedirect = Configuration.shared.getCallbackURIString()
let expectedTokenType = "code"
let expectedState = "state123423"
diff --git a/source/UberRidesTests/ObjectMappingTests.swift b/source/UberRidesTests/ObjectMappingTests.swift
index 9dfeaaa7..201047d4 100644
--- a/source/UberRidesTests/ObjectMappingTests.swift
+++ b/source/UberRidesTests/ObjectMappingTests.swift
@@ -31,7 +31,7 @@ class ObjectMappingTests: XCTestCase {
override func setUp() {
super.setUp()
Configuration.restoreDefaults()
- Configuration.setSandboxEnabled(true)
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
diff --git a/source/UberRidesTests/RefreshEndpointTests.swift b/source/UberRidesTests/RefreshEndpointTests.swift
index 32cdf675..12e6393f 100644
--- a/source/UberRidesTests/RefreshEndpointTests.swift
+++ b/source/UberRidesTests/RefreshEndpointTests.swift
@@ -33,10 +33,10 @@ class RefreshEndpointTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
headers = ["Content-Type": "application/json"]
client = RidesClient()
}
@@ -55,7 +55,7 @@ class RefreshEndpointTests: XCTestCase {
return OHHTTPStubsResponse(fileAtPath:OHPathForFile("refresh.json", type(of: self))!, statusCode:200, headers:self.headers)
}
let refreshToken = "ThisIsRefresh"
- let clientID = Configuration.getClientID()
+ let clientID = Configuration.shared.clientID
let expectation = self.expectation(description: "200 success response")
let endpoint = OAuth.refresh(clientID: clientID, refreshToken: refreshToken)
guard let request = Request(session: client.session, endpoint: endpoint) else {
diff --git a/source/UberRidesTests/RequestButtonTests.swift b/source/UberRidesTests/RequestButtonTests.swift
index 9ece7f84..fea28fa7 100644
--- a/source/UberRidesTests/RequestButtonTests.swift
+++ b/source/UberRidesTests/RequestButtonTests.swift
@@ -38,10 +38,10 @@ class RequestButtonTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
client = RidesClient()
}
@@ -84,9 +84,9 @@ class RequestButtonTests: XCTestCase {
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
let baseViewController = UIViewControllerMock()
let requestBehavior = RideRequestViewRequestingBehavior(presentingViewController: baseViewController)
diff --git a/source/UberRidesTests/RequestDeeplinkTests.swift b/source/UberRidesTests/RequestDeeplinkTests.swift
index baa034d1..d50c8457 100644
--- a/source/UberRidesTests/RequestDeeplinkTests.swift
+++ b/source/UberRidesTests/RequestDeeplinkTests.swift
@@ -66,11 +66,11 @@ class UberRidesDeeplinkTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setClientID(clientID)
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.clientID = clientID
+ Configuration.shared.isSandbox = true
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
expectedDeeplinkUserAgent = "rides-ios-v\(versionNumber!)-deeplink"
expectedButtonUserAgent = "rides-ios-v\(versionNumber!)-button"
diff --git a/source/UberRidesTests/RequestLayerTests.swift b/source/UberRidesTests/RequestLayerTests.swift
index 5be4b405..3198d592 100644
--- a/source/UberRidesTests/RequestLayerTests.swift
+++ b/source/UberRidesTests/RequestLayerTests.swift
@@ -33,10 +33,10 @@ class RequestLayerTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
headers = ["Content-Type": "application/json"]
client = RidesClient()
}
diff --git a/source/UberRidesTests/RequestURLUtilTests.swift b/source/UberRidesTests/RequestURLUtilTests.swift
index 78b8789b..64a3f4d4 100644
--- a/source/UberRidesTests/RequestURLUtilTests.swift
+++ b/source/UberRidesTests/RequestURLUtilTests.swift
@@ -32,9 +32,9 @@ class RequestURLUtilTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
baseUserAgent = "rides-ios-v\(versionNumber!)"
}
diff --git a/source/UberRidesTests/RideRequestViewControllerTests.swift b/source/UberRidesTests/RideRequestViewControllerTests.swift
index f51ca016..03d84b31 100644
--- a/source/UberRidesTests/RideRequestViewControllerTests.swift
+++ b/source/UberRidesTests/RideRequestViewControllerTests.swift
@@ -30,10 +30,10 @@ class RideRequestViewControllerTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
@@ -67,11 +67,11 @@ class RideRequestViewControllerTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
rideRequestVC.rideRequestView = RideRequestViewMock(rideRequestView: rideRequestVC.rideRequestView, testClosure: expectationClosure)
XCTAssertNotNil(rideRequestVC.view)
@@ -89,8 +89,8 @@ class RideRequestViewControllerTests: XCTestCase {
expectation = true
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
XCTAssertNotNil(rideRequestVC.view)
@@ -108,8 +108,8 @@ class RideRequestViewControllerTests: XCTestCase {
var expectation = false
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .native)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .native)
let rideRequestVC = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
let expectationClosure: () -> () = {
@@ -132,8 +132,8 @@ class RideRequestViewControllerTests: XCTestCase {
var expectation = true
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .native)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .native)
let rideRequestVC = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
let expectationClosure: () -> () = {
@@ -161,8 +161,8 @@ class RideRequestViewControllerTests: XCTestCase {
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "test"])
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .native)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .native)
let rideRequestVC = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
let expectationClosure: () -> () = {
@@ -194,8 +194,8 @@ class RideRequestViewControllerTests: XCTestCase {
expectation = true
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
XCTAssertNotNil(rideRequestVC.view)
@@ -216,8 +216,8 @@ class RideRequestViewControllerTests: XCTestCase {
expectation = true
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
XCTAssertNotNil(rideRequestVC.view)
@@ -251,8 +251,8 @@ class RideRequestViewControllerTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
XCTAssertNotNil(rideRequestVC.view)
@@ -285,8 +285,8 @@ class RideRequestViewControllerTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
XCTAssertNotNil(rideRequestVC.view)
@@ -320,11 +320,11 @@ class RideRequestViewControllerTests: XCTestCase {
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
- let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManager)
let requestViewMock = RideRequestViewMock(rideRequestView: rideRequestVC.rideRequestView, testClosure: loadExpectationClosure)
rideRequestVC.rideRequestView = requestViewMock
@@ -367,11 +367,11 @@ class RideRequestViewControllerTests: XCTestCase {
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
XCTAssertNotNil(rideRequestVC.view)
@@ -393,11 +393,11 @@ class RideRequestViewControllerTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
- let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestViewControllerMock = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManager, loadClosure: nil, networkClosure: networkClosure, presentViewControllerClosure: nil)
@@ -413,9 +413,9 @@ class RideRequestViewControllerTests: XCTestCase {
expectation = true
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
- let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestViewControllerMock = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManager, loadClosure: nil, networkClosure: networkClosure, presentViewControllerClosure: nil)
@@ -435,11 +435,11 @@ class RideRequestViewControllerTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
- let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestViewControllerMock = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManager, loadClosure: nil, networkClosure: nil, presentViewControllerClosure: presentViewControllerClosure)
@@ -469,9 +469,9 @@ class RideRequestViewControllerTests: XCTestCase {
expectation = true
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
- let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestViewControllerMock = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManager, notSupportedClosure: notSupportedClosure)
@@ -489,9 +489,9 @@ class RideRequestViewControllerTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
- let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManager = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestViewControllerMock = RideRequestViewControllerMock(rideParameters: RideParametersBuilder().build(), loginManager: loginManager, presentViewControllerClosure: presentViewControllerClosure)
@@ -502,7 +502,7 @@ class RideRequestViewControllerTests: XCTestCase {
func testNativeLogin_handlesError_whenAccessTokenAndErrorAreNotNil() {
let testIdentifier = "testAccessTokenIdentifier"
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .native)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .native)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
var delegateCalled = false
let mock = RideRequestViewControllerDelegateMock { (_, _) in
@@ -522,7 +522,7 @@ class RideRequestViewControllerTests: XCTestCase {
func testImplicitLogin_handlesError_whenAccessTokenAndErrorAreNotNil() {
let testIdentifier = "testAccessTokenIdentifier"
- let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.getDefaultKeychainAccessGroup(), loginType: .implicit)
+ let loginManger = LoginManager(accessTokenIdentifier: testIdentifier, keychainAccessGroup: Configuration.shared.defaultKeychainAccessGroup, loginType: .implicit)
let rideRequestVC = RideRequestViewController(rideParameters: RideParametersBuilder().build(), loginManager: loginManger)
var delegateCalled = false
let mock = RideRequestViewControllerDelegateMock { (_, _) in
diff --git a/source/UberRidesTests/RideRequestViewRequestingBehaviorTests.swift b/source/UberRidesTests/RideRequestViewRequestingBehaviorTests.swift
index be90c7c9..db67c71e 100644
--- a/source/UberRidesTests/RideRequestViewRequestingBehaviorTests.swift
+++ b/source/UberRidesTests/RideRequestViewRequestingBehaviorTests.swift
@@ -28,10 +28,10 @@ class RideRequestViewRequestingBehaviorTests : XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
@@ -66,7 +66,7 @@ class RideRequestViewRequestingBehaviorTests : XCTestCase {
XCTAssertNotNil(behavior.modalRideRequestViewController.rideRequestViewController)
let pickupLocation = CLLocation(latitude: -32.0, longitude: 42.2)
let newRideParams = RideParametersBuilder().setPickupLocation(pickupLocation).build()
- behavior.requestRide(newRideParams)
+ behavior.requestRide(parameters: newRideParams)
XCTAssertTrue(behavior.modalRideRequestViewController.rideRequestViewController.rideRequestView.rideParameters === newRideParams)
}
@@ -97,7 +97,7 @@ class RideRequestViewRequestingBehaviorTests : XCTestCase {
let baseVC = UIViewControllerMock(testClosure: expectationClosure)
let initialLoginManger = LoginManager(loginType: .native)
let behavior = RideRequestViewRequestingBehavior(presentingViewController: baseVC, loginManager: initialLoginManger)
- behavior.requestRide(RideParametersBuilder().build())
+ behavior.requestRide(parameters: RideParametersBuilder().build())
waitForExpectations(timeout: 2.0) {error in
XCTAssertNil(error)
}
diff --git a/source/UberRidesTests/RideRequestViewTests.swift b/source/UberRidesTests/RideRequestViewTests.swift
index 6ee00ef8..5e6de82f 100644
--- a/source/UberRidesTests/RideRequestViewTests.swift
+++ b/source/UberRidesTests/RideRequestViewTests.swift
@@ -33,10 +33,10 @@ class RideRequestViewTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.isSandbox = true
}
override func tearDown() {
@@ -99,7 +99,7 @@ class RideRequestViewTests: XCTestCase {
XCTAssert(false)
return
}
- _ = TokenManager.saveToken(token)
+ _ = TokenManager.save(accessToken: token)
let view = RideRequestView()
XCTAssertNotNil(view.accessToken)
@@ -162,14 +162,14 @@ class RideRequestViewTests: XCTestCase {
}
let testIdentifier = "testAccessTokenIdentifier"
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
let testToken = AccessToken(JSON: ["access_token" : "testTokenString"])
- _ = TokenManager.saveToken(testToken!, tokenIdentifier: testIdentifier)
+ _ = TokenManager.save(accessToken: testToken!, tokenIdentifier: testIdentifier)
defer {
- _ = TokenManager.deleteToken(testIdentifier)
+ _ = TokenManager.deleteToken(identifier: testIdentifier)
}
- let rideRequestView = RideRequestView(rideParameters: RideParametersBuilder().build(), accessToken: TokenManager.fetchToken(testIdentifier), frame: CGRect.zero)
+ let rideRequestView = RideRequestView(rideParameters: RideParametersBuilder().build(), accessToken: TokenManager.fetchToken(identifier: testIdentifier), frame: CGRect.zero)
XCTAssertNotNil(rideRequestView)
let webViewMock = WebViewMock(frame: CGRect.zero, configuration: WKWebViewConfiguration(), testClosure: expectationClosure)
diff --git a/source/UberRidesTests/RidesAppDelegateTests.swift b/source/UberRidesTests/RidesAppDelegateTests.swift
index c8d80c5a..b47fc34e 100644
--- a/source/UberRidesTests/RidesAppDelegateTests.swift
+++ b/source/UberRidesTests/RidesAppDelegateTests.swift
@@ -32,11 +32,11 @@ class RidesAppDelegateTests : XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setClientID(clientID)
- Configuration.setSandboxEnabled(true)
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
+ Configuration.shared.clientID = clientID
+ Configuration.shared.isSandbox = true
versionNumber = Bundle(for: RideParameters.self).object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
expectedDeeplinkUserAgent = "rides-ios-v\(versionNumber!)-deeplink"
expectedButtonUserAgent = "rides-ios-v\(versionNumber!)-button"
@@ -49,7 +49,7 @@ class RidesAppDelegateTests : XCTestCase {
}
func testOpenUrlReturnsFalse_whenNoLoginManager() {
- let appDelegate = RidesAppDelegate.sharedInstance
+ let appDelegate = RidesAppDelegate.shared
let testApp = UIApplication.shared
guard let url = URL(string: "http://www.google.com") else {
@@ -57,12 +57,12 @@ class RidesAppDelegateTests : XCTestCase {
return
}
- XCTAssertFalse(appDelegate.application(testApp, openURL: url, sourceApplication: nil, annotation: nil))
+ XCTAssertFalse(appDelegate.application(testApp, open: url, sourceApplication: nil, annotation: ""))
}
func testOpenUrlReturnsTrue_callsOpenURLOnLoginManager() {
let expectation = self.expectation(description: "open URL called")
- let appDelegate = RidesAppDelegate.sharedInstance
+ let appDelegate = RidesAppDelegate.shared
let loginManagerMock = LoginManagingProtocolMock()
let testApp = UIApplication.shared
guard let testURL = URL(string: "http://www.google.com") else {
@@ -83,20 +83,20 @@ class RidesAppDelegateTests : XCTestCase {
loginManagerMock.openURLClosure = urlClosure
appDelegate.loginManager = loginManagerMock
- XCTAssertTrue(appDelegate.application(testApp, openURL: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation as AnyObject?))
+ XCTAssertTrue(appDelegate.application(testApp, open: testURL, sourceApplication: testSourceApplication, annotation: testAnnotation))
XCTAssertNil(appDelegate.loginManager)
waitForExpectations(timeout: 0.2, handler: nil)
}
func testDidFinishLaunchingReturnsFalse_whenNoLaunchOptions() {
- let appDelegate = RidesAppDelegate.sharedInstance
+ let appDelegate = RidesAppDelegate.shared
let testApp = UIApplication.shared
XCTAssertFalse(appDelegate.application(testApp, didFinishLaunchingWithOptions: nil))
}
func testDidFinishLaunchingCallsOpenURL_whenLaunchURL() {
let expectation = self.expectation(description: "open URL called")
- let appDelegate = RidesAppDelegate.sharedInstance
+ let appDelegate = RidesAppDelegate.shared
let testApp = UIApplication.shared
let loginManagerMock = LoginManagingProtocolMock()
guard let testURL = URL(string: "http://www.google.com") else {
@@ -128,7 +128,7 @@ class RidesAppDelegateTests : XCTestCase {
func testDidBecomeActiveCallsLoginManager_whenDidBecomeActiveNotification() {
let expectation = self.expectation(description: "didBecomeActive called")
- let appDelegate = RidesAppDelegate.sharedInstance
+ let appDelegate = RidesAppDelegate.shared
let loginManagerMock = LoginManagingProtocolMock()
let didBecomeActiveClosure: () -> () = {
diff --git a/source/UberRidesTests/RidesClientTests.swift b/source/UberRidesTests/RidesClientTests.swift
index 2d64d81d..3b4cf3a4 100644
--- a/source/UberRidesTests/RidesClientTests.swift
+++ b/source/UberRidesTests/RidesClientTests.swift
@@ -33,12 +33,12 @@ class RidesClientTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
Configuration.plistName = "testInfoNoServerToken"
Configuration.bundle = Bundle(for: type(of: self))
- Configuration.setClientID(clientID)
- Configuration.setServerToken(nil)
- Configuration.setSandboxEnabled(true)
+ Configuration.restoreDefaults()
+ Configuration.shared.clientID = clientID
+ Configuration.shared.serverToken = nil
+ Configuration.shared.isSandbox = true
client = RidesClient()
}
@@ -53,10 +53,10 @@ class RidesClientTests: XCTestCase {
*/
func testHasServerToken() {
- XCTAssertFalse(client.hasServerToken())
- Configuration.setServerToken(serverToken)
+ XCTAssertFalse(client.hasServerToken)
+ Configuration.shared.serverToken = serverToken
client = RidesClient()
- XCTAssertTrue(client.hasServerToken())
+ XCTAssertTrue(client.hasServerToken)
}
/**
@@ -122,7 +122,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get product by id")
- client.fetchProduct(productID, completion: { product, response in
+ client.fetchProduct(productID: productID, completion: { product, response in
XCTAssertNotNil(product)
XCTAssertEqual(product!.name, "UberBLACK")
@@ -231,7 +231,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get user profile")
- client.fetchUserProfile({ profile, error in
+ client.fetchUserProfile(completion: { profile, error in
XCTAssertNotNil(profile)
XCTAssertEqual(profile!.firstName, "Uber")
XCTAssertEqual(profile!.lastName, "Developer")
@@ -257,7 +257,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "make ride request")
let rideParameters = RideParametersBuilder().setPickupPlaceID("home").build()
- client.requestRide(rideParameters, completion: { ride, response in
+ client.requestRide(parameters: rideParameters, completion: { ride, response in
XCTAssertNotNil(ride)
XCTAssertEqual(ride!.status, RideStatus.processing)
XCTAssertEqual(ride!.requestID, "852b8fdd-4369-4659-9628-e122662ad257")
@@ -283,7 +283,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get current ride")
- client.fetchCurrentRide({ ride, response in
+ client.fetchCurrentRide(completion: { ride, response in
XCTAssertNotNil(ride)
XCTAssertEqual(ride!.requestID, "17cb78a7-b672-4d34-a288-a6c6e44d5315")
XCTAssertEqual(ride!.status, RideStatus.accepted)
@@ -308,7 +308,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get ride by ID")
- client.fetchRideDetails("someID", completion: { ride, response in
+ client.fetchRideDetails(requestID: "someID", completion: { ride, response in
XCTAssertNotNil(ride)
XCTAssertEqual(ride!.requestID, "17cb78a7-b672-4d34-a288-a6c6e44d5315")
XCTAssertEqual(ride!.status, RideStatus.accepted)
@@ -334,7 +334,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get request estimate")
let rideParams = RideParametersBuilder().setPickupPlaceID("home").build()
- client.fetchRideRequestEstimate(rideParams, completion:{ estimate, error in
+ client.fetchRideRequestEstimate(parameters: rideParams, completion:{ estimate, error in
XCTAssertNotNil(estimate)
XCTAssertEqual(estimate!.pickupEstimate, 2)
@@ -356,7 +356,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get place")
let testPlace = Place.Home
- client.fetchPlace(testPlace, completion: { place, response in
+ client.fetchPlace(placeID: testPlace, completion: { place, response in
guard let place = place else {
XCTAssert(false)
return
@@ -385,7 +385,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get place not found error")
let testPlace = "gym"
- client.fetchPlace(testPlace, completion: { place, response in
+ client.fetchPlace(placeID: testPlace, completion: { place, response in
XCTAssertNil(place)
guard let error = response.error else {
@@ -419,7 +419,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "get place not found error")
let testPlace = Place.Home
- client.fetchPlace(testPlace, completion: { place, response in
+ client.fetchPlace(placeID: testPlace, completion: { place, response in
XCTAssertNil(place)
guard let error = response.error else {
@@ -448,7 +448,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateRideDetails("requestID1234", rideParameters: params, completion: { response in
+ client.updateRideDetails(requestID: "requestID1234", rideParameters: params, completion: { response in
XCTAssertNil(response.error)
XCTAssertEqual(response.statusCode, 204)
expectation.fulfill()
@@ -466,7 +466,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateRideDetails("requestID1234", rideParameters: params, completion: { response in
+ client.updateRideDetails(requestID: "requestID1234", rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -490,7 +490,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateRideDetails("requestID1234", rideParameters: params, completion: { response in
+ client.updateRideDetails(requestID: "requestID1234", rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -514,7 +514,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateRideDetails("requestID1234", rideParameters: params, completion: { response in
+ client.updateRideDetails(requestID: "requestID1234", rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -538,7 +538,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateCurrentRide(params, completion: { response in
+ client.updateCurrentRide(rideParameters: params, completion: { response in
XCTAssertNil(response.error)
XCTAssertEqual(response.statusCode, 204)
expectation.fulfill()
@@ -556,7 +556,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateCurrentRide(params, completion: { response in
+ client.updateCurrentRide(rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -580,7 +580,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateCurrentRide(params, completion: { response in
+ client.updateCurrentRide(rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -604,7 +604,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateCurrentRide(params, completion: { response in
+ client.updateCurrentRide(rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -628,7 +628,7 @@ class RidesClientTests: XCTestCase {
let expectation = self.expectation(description: "update ride")
let params = RideParametersBuilder().setDropoffPlaceID(Place.Work).build()
- client.updateCurrentRide(params, completion: { response in
+ client.updateCurrentRide(rideParameters: params, completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -651,7 +651,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "delete ride")
- client.cancelRide("requestID1234", completion: { response in
+ client.cancelRide(requestID: "requestID1234", completion: { response in
XCTAssertNil(response.error)
XCTAssertEqual(response.statusCode, 204)
expectation.fulfill()
@@ -668,7 +668,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "delete ride")
- client.cancelCurrentRide({ response in
+ client.cancelCurrentRide(completion: { response in
XCTAssertNil(response.error)
XCTAssertEqual(response.statusCode, 204)
expectation.fulfill()
@@ -685,7 +685,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "update ride")
- client.cancelCurrentRide({ response in
+ client.cancelCurrentRide(completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -708,7 +708,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "update ride")
- client.cancelCurrentRide({ response in
+ client.cancelCurrentRide(completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -731,7 +731,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "update ride")
- client.cancelCurrentRide({ response in
+ client.cancelCurrentRide(completion: { response in
guard let error = response.error else {
XCTAssert(false)
return
@@ -757,7 +757,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "get payment methods")
- client.fetchPaymentMethods({ methods, lastUsed, response in
+ client.fetchPaymentMethods(completion: { methods, lastUsed, response in
guard let lastUsed = lastUsed else {
XCTAssert(false)
return
@@ -782,7 +782,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "ride receipt")
- client.fetchRideReceipt("requestID1234", completion: { receipt, response in
+ client.fetchRideReceipt(requestID: "requestID1234", completion: { receipt, response in
guard let receipt = receipt else {
XCTAssert(false)
return
@@ -805,7 +805,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "ride map")
- client.fetchRideMap("requestID1234", completion: { map, response in
+ client.fetchRideMap(requestID: "requestID1234", completion: { map, response in
guard let map = map else {
XCTAssert(false)
return
@@ -829,7 +829,7 @@ class RidesClientTests: XCTestCase {
}
let expectation = self.expectation(description: "ride map")
- client.fetchRideMap("requestID1234", completion: { map, response in
+ client.fetchRideMap(requestID: "requestID1234", completion: { map, response in
XCTAssertNil(map)
guard let error = response.error else {
@@ -859,7 +859,7 @@ class RidesClientTests: XCTestCase {
let expectedScopeSet = Set(expectedScopes)
let expectation = self.expectation(description: "Refresh token completion")
- client.refreshAccessToken(refreshToken, completion: { accessToken, response in
+ client.refreshAccessToken(usingRefreshToken: refreshToken, completion: { accessToken, response in
guard let accessToken = accessToken, let scopes = accessToken.grantedScopes else {
XCTAssert(false)
return
@@ -879,7 +879,7 @@ class RidesClientTests: XCTestCase {
XCTAssertNil(error)
})
}
-
+
func testRefreshTokenInvalid() {
stub(condition: isHost("login.uber.com")) { _ in
return OHHTTPStubsResponse(jsonObject: ["error":"invalid_refresh_token"], statusCode: 400, headers: nil)
@@ -887,7 +887,7 @@ class RidesClientTests: XCTestCase {
let refreshToken = "thisIsRefresh"
let expectation = self.expectation(description: "Refresh token completion")
- client.refreshAccessToken(refreshToken, completion: { accessToken, response in
+ client.refreshAccessToken(usingRefreshToken: refreshToken, completion: { accessToken, response in
XCTAssertNil(accessToken)
guard let error = response.error else {
@@ -918,8 +918,8 @@ class RidesClientTests: XCTestCase {
let keychainHelper = KeychainWrapper()
- let tokenKey = Configuration.getDefaultAccessTokenIdentifier()
- let tokenGroup = Configuration.getDefaultKeychainAccessGroup()
+ let tokenKey = Configuration.shared.defaultAccessTokenIdentifier
+ let tokenGroup = Configuration.shared.defaultKeychainAccessGroup
keychainHelper.setAccessGroup(tokenGroup)
XCTAssertTrue(keychainHelper.setObject(token, key: tokenKey))
@@ -958,7 +958,7 @@ class RidesClientTests: XCTestCase {
let keychainHelper = KeychainWrapper()
let tokenKey = "newTokenKey"
- let tokenGroup = Configuration.getDefaultKeychainAccessGroup()
+ let tokenGroup = Configuration.shared.defaultKeychainAccessGroup
keychainHelper.setAccessGroup(tokenGroup)
XCTAssertTrue(keychainHelper.setObject(token, key: tokenKey))
diff --git a/source/UberRidesTests/RidesMocks.swift b/source/UberRidesTests/RidesMocks.swift
index b28fee10..d68af7cc 100644
--- a/source/UberRidesTests/RidesMocks.swift
+++ b/source/UberRidesTests/RidesMocks.swift
@@ -178,7 +178,7 @@ class RequestDeeplinkMock : RequestDeeplink {
super.init(rideParameters: rideParameters)
}
- override func execute(_ completion: ((NSError?) -> ())? = nil) {
+ override func execute(completion: ((NSError?) -> ())? = nil) {
guard let testClosure = testClosure else {
completion?(nil)
return
@@ -187,14 +187,14 @@ class RequestDeeplinkMock : RequestDeeplink {
}
}
-class DeeplinkRequestingBehaviorMock : DeeplinkRequestingBehavior {
+class DeeplinkRequestingBehaviorMock: DeeplinkRequestingBehavior {
var testClosure: ((URL?) -> (Bool))?
init(testClosure: ((URL?) -> (Bool))?) {
self.testClosure = testClosure
super.init()
}
- override func createDeeplink(_ rideParameters: RideParameters) -> RequestDeeplink {
+ override func createDeeplink(rideParameters: RideParameters) -> RequestDeeplink {
return RequestDeeplinkMock(rideParameters: rideParameters, testClosure: testClosure)
}
}
@@ -268,13 +268,13 @@ class DeeplinkRequestingBehaviorMock : DeeplinkRequestingBehavior {
}
}
- @objc func execute(_ completion: ((NSError?) -> ())?) {
+ @objc func execute(completion: ((NSError?) -> ())?) {
if let closure = executeClosure {
closure(completion)
} else if overrideExecute {
completion?(overrideExecuteValue)
} else {
- deeplinkingObject.execute(completion)
+ deeplinkingObject.execute(completion: completion)
}
}
@@ -305,16 +305,24 @@ class DeeplinkRequestingBehaviorMock : DeeplinkRequestingBehavior {
}
}
- func application(_ application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: Any?) -> Bool {
+ func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if let closure = openURLClosure {
return closure(application, url, sourceApplication, annotation)
} else if let manager = backingManager {
- return manager.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
+ return manager.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
} else {
return false
}
}
-
+
+ @available(iOS 9.0, *)
+ open func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
+ let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
+ let annotation = options[.annotation] as Any
+
+ return application(app, open: url, sourceApplication: sourceApplication, annotation: annotation)
+ }
+
func applicationDidBecomeActive() {
if let closure = didBecomeActiveClosure {
closure()
@@ -341,11 +349,11 @@ class NativeAuthenticatorPartialMock : NativeAuthenticator {
var handleRedirectClosure: ((URLRequest) -> (Bool))?
- override func handleRedirectRequest(_ request: URLRequest) -> Bool {
+ override func handleRedirect(for request: URLRequest) -> Bool {
if let closure = handleRedirectClosure {
return closure(request)
} else {
- return super.handleRedirectRequest(request)
+ return super.handleRedirect(for: request)
}
}
diff --git a/source/UberRidesTests/TokenManagerTests.swift b/source/UberRidesTests/TokenManagerTests.swift
index 7a93c1c3..44a063de 100644
--- a/source/UberRidesTests/TokenManagerTests.swift
+++ b/source/UberRidesTests/TokenManagerTests.swift
@@ -51,7 +51,7 @@ class TokenManagerTests: XCTestCase {
func testSave() {
let identifier = "testIdentifier"
- XCTAssertTrue(TokenManager.saveToken(token!, tokenIdentifier:identifier))
+ XCTAssertTrue(TokenManager.save(accessToken: token!, tokenIdentifier:identifier))
guard let actualToken = keychain?.getObjectForKey(identifier) as? AccessToken else {
XCTFail("Unable to fetch token")
@@ -67,9 +67,9 @@ class TokenManagerTests: XCTestCase {
func testSave_firesNotification() {
let identifier = "testIdentifier"
- NotificationCenter.default.addObserver(self, selector: #selector(handleTokenManagerNotifications), name: NSNotification.Name(rawValue: TokenManager.TokenManagerDidSaveTokenNotification), object: nil)
+ NotificationCenter.default.addObserver(self, selector: #selector(handleTokenManagerNotifications), name: NSNotification.Name(rawValue: TokenManager.tokenManagerDidSaveTokenNotification), object: nil)
- XCTAssertTrue(TokenManager.saveToken(token!, tokenIdentifier:identifier))
+ XCTAssertTrue(TokenManager.save(accessToken: token!, tokenIdentifier:identifier))
NotificationCenter.default.removeObserver(self)
@@ -91,7 +91,7 @@ class TokenManagerTests: XCTestCase {
XCTAssertTrue(keychain!.setObject(token!, key: identifier))
- let actualToken = TokenManager.fetchToken(identifier)
+ let actualToken = TokenManager.fetchToken(identifier: identifier)
XCTAssertNotNil(actualToken)
XCTAssertEqual(actualToken?.tokenString, token?.tokenString)
@@ -102,7 +102,7 @@ class TokenManagerTests: XCTestCase {
func testGet_nonExistent() {
let identifer = "there.is.no.token.named.this.123412wfdasd3o"
- XCTAssertNil(TokenManager.fetchToken(identifer))
+ XCTAssertNil(TokenManager.fetchToken(identifier: identifer))
}
func testDelete() {
@@ -110,7 +110,7 @@ class TokenManagerTests: XCTestCase {
XCTAssertTrue(keychain!.setObject(token!, key: identifier))
- XCTAssertTrue(TokenManager.deleteToken(identifier))
+ XCTAssertTrue(TokenManager.deleteToken(identifier: identifier))
let actualToken = keychain?.getObjectForKey(identifier) as? AccessToken
guard actualToken == nil else {
@@ -123,7 +123,7 @@ class TokenManagerTests: XCTestCase {
func testDelete_nonExistent() {
let identifier = "there.is.no.token.named.this.123412wfdasd3o"
- XCTAssertFalse(TokenManager.deleteToken(identifier))
+ XCTAssertFalse(TokenManager.deleteToken(identifier: identifier))
}
@@ -133,9 +133,9 @@ class TokenManagerTests: XCTestCase {
XCTAssertTrue(keychain!.setObject(token!, key: identifier))
- NotificationCenter.default.addObserver(self, selector: #selector(handleTokenManagerNotifications), name: NSNotification.Name(rawValue: TokenManager.TokenManagerDidDeleteTokenNotification), object: nil)
+ NotificationCenter.default.addObserver(self, selector: #selector(handleTokenManagerNotifications), name: NSNotification.Name(rawValue: TokenManager.tokenManagerDidDeleteTokenNotification), object: nil)
- XCTAssertTrue(TokenManager.deleteToken(identifier))
+ XCTAssertTrue(TokenManager.deleteToken(identifier: identifier))
NotificationCenter.default.removeObserver(self)
@@ -152,9 +152,9 @@ class TokenManagerTests: XCTestCase {
func testDelete_nonExistent_doesNotFireNotification() {
let identifier = "there.is.no.token.named.this.123412wfdasd3o"
- NotificationCenter.default.addObserver(self, selector: #selector(handleTokenManagerNotifications), name: NSNotification.Name(rawValue: TokenManager.TokenManagerDidDeleteTokenNotification), object: nil)
+ NotificationCenter.default.addObserver(self, selector: #selector(handleTokenManagerNotifications), name: NSNotification.Name(rawValue: TokenManager.tokenManagerDidDeleteTokenNotification), object: nil)
- XCTAssertFalse(TokenManager.deleteToken(identifier))
+ XCTAssertFalse(TokenManager.deleteToken(identifier: identifier))
NotificationCenter.default.removeObserver(self)
@@ -185,7 +185,7 @@ class TokenManagerTests: XCTestCase {
_ = keychain?.setObject(token!, key: identifier)
- XCTAssertTrue(TokenManager.deleteToken(identifier))
+ XCTAssertTrue(TokenManager.deleteToken(identifier: identifier))
let actualToken = keychain?.getObjectForKey(identifier) as? AccessToken
guard actualToken == nil else {
diff --git a/source/UberRidesTests/WidgetsEndpointTests.swift b/source/UberRidesTests/WidgetsEndpointTests.swift
index fd33486e..9d34a1b5 100644
--- a/source/UberRidesTests/WidgetsEndpointTests.swift
+++ b/source/UberRidesTests/WidgetsEndpointTests.swift
@@ -30,9 +30,9 @@ class WidgetsEndpointTests: XCTestCase {
override func setUp() {
super.setUp()
- Configuration.restoreDefaults()
- Configuration.plistName = "testInfo"
Configuration.bundle = Bundle(for: type(of: self))
+ Configuration.plistName = "testInfo"
+ Configuration.restoreDefaults()
}
override func tearDown() {
@@ -41,8 +41,7 @@ class WidgetsEndpointTests: XCTestCase {
}
func testERRC_withNoLocation() {
- Configuration.setSandboxEnabled(true)
- Configuration.setRegion(Region.default)
+ Configuration.shared.isSandbox = true
let expectedHost = "https://components.uber.com"
let expectedPath = "/rides/"
@@ -55,9 +54,8 @@ class WidgetsEndpointTests: XCTestCase {
XCTAssertEqual(rideRequestWidget.query, expectedQueryItems)
}
- func testERRC_withRegionDefault_withSandboxEnabled() {
- Configuration.setSandboxEnabled(true)
- Configuration.setRegion(Region.default)
+ func testERRC_withSandboxEnabled() {
+ Configuration.shared.isSandbox = true
let expectedLat = 33.2
let expectedLong = -41.2
@@ -78,9 +76,8 @@ class WidgetsEndpointTests: XCTestCase {
}
}
- func testERRC_withRegionDefault_withSandboxDisabled() {
- Configuration.setSandboxEnabled(false)
- Configuration.setRegion(Region.default)
+ func testERRC_withSandboxDisabled() {
+ Configuration.shared.isSandbox = false
let expectedHost = "https://components.uber.com"
let expectedPath = "/rides/"