Skip to content

Commit

Permalink
Remove DeepLinkServerBaseAddress and replace it with the `sidecarBa…
Browse files Browse the repository at this point in the history
…seUrl`

#722

This change removes all hardcoded dependencies on the OneBusAway.co server and makes it straightforward to use a different server in place of it.
  • Loading branch information
aaronbrethorst committed Nov 27, 2024
1 parent 65ad52a commit 3edb677
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 46 deletions.
1 change: 0 additions & 1 deletion Apps/CatalystTest/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ targets:
AppDevelopersEmailAddress: [email protected]
AppGroup: group.org.onebusaway.iphone
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
ExtensionURLScheme: onebusaway
PrivacyPolicyURL: https://onebusaway.org/privacy/
PushNotificationAPIKey: d5d0d28a-6091-46cd-9627-0ce01ffa9f9e
Expand Down
2 changes: 0 additions & 2 deletions Apps/MTA/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ targets:
AppDevelopersEmailAddress: [email protected]
AppGroup: group.info.mta.bustime
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
ExtensionURLScheme: bustime
PrivacyPolicyURL: https://new.mta.info/privacy-policy
PushNotificationAPIKey: d5d0d28a-6091-46cd-9627-0ce01ffa9f9e
Expand All @@ -75,7 +74,6 @@ targets:
OBAKitConfig:
AppGroup: group.info.mta.bustime
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
ExtensionURLScheme: bustime
RESTServerAPIKey: test
RegionsServerBaseAddress: https://regions.onebusaway.org
Expand Down
3 changes: 0 additions & 3 deletions Apps/OneBusAway/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ targets:
AppDevelopersEmailAddress: [email protected]
AppGroup: group.org.onebusaway.iphone
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
Donations:
Enabled: true
ApplePayMerchantID: merchant.org.onebusaway.iphone
Expand Down Expand Up @@ -85,7 +84,6 @@ targets:
OBAKitConfig:
AppGroup: group.org.onebusaway.iphone
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
ExtensionURLScheme: onebusaway
RESTServerAPIKey: org.onebusaway.iphone
RegionsServerBaseAddress: https://regions.onebusaway.org
Expand All @@ -106,7 +104,6 @@ targets:
OBAKitConfig:
AppGroup: group.org.onebusaway.iphone
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
ExtensionURLScheme: onebusaway
RESTServerAPIKey: org.onebusaway.iphone
RegionsServerBaseAddress: https://regions.onebusaway.org
Expand Down
21 changes: 12 additions & 9 deletions OBAKit/DeepLinks/AppLinksRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,28 @@ import OBAKitCore

/// Creates deep links (i.e. Universal Links) to OBA-associated web pages.
public class AppLinksRouter: NSObject {
private let baseURL: URL
private let application: Application

/// Initializes the `AppLinksRouter`
///
/// - Parameter baseURL: The deep link server host. Usually this is `http://alerts.onebusaway.org`.
public init?(baseURL: URL?, application: Application) {
guard let baseURL = baseURL else {
return nil
}

self.baseURL = baseURL
/// - Parameter application: The Application object
public init?(application: Application) {
self.application = application
}

/// The base URL for all operations in this object.
private var baseURL: URL? {
application.regionsService.currentRegion?.sidecarBaseURL
}

/// Creates a link to the OneBusAway stop page for the specified stop and region.
///
/// - Parameters:
/// - stop: The stop for which a link will be created.
/// - region: The region in which the link will exist.
public func url(for stop: Stop, region: Region) -> URL? {
guard let baseURL else { return nil }

guard var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false) else { return nil }
components.path = String(format: "/regions/%d/stops/%@", region.regionIdentifier, stop.id)

Expand All @@ -46,7 +47,9 @@ public class AppLinksRouter: NSObject {
/// - Parameters:
/// - arrivalDeparture: The object that will be encoded into a deep link URL.
/// - region: The region in which the `ArrivalDeparture` exists.
public func encode(arrivalDeparture: ArrivalDeparture, region: Region) -> URL {
public func encode(arrivalDeparture: ArrivalDeparture, region: Region) -> URL? {
guard let baseURL else { return nil }

var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)!
components.path = String(format: deepLinkPathFormat, region.regionIdentifier, arrivalDeparture.stopID)
components.queryItems = [
Expand Down
4 changes: 0 additions & 4 deletions OBAKit/Orchestration/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class AppConfig: CoreAppConfig {
) {
self.init(
regionsBaseURL: appBundle.regionsServerBaseAddress,
obacoBaseURL: appBundle.deepLinkServerBaseAddress,
apiKey: appBundle.restServerAPIKey!,
appVersion: appBundle.appVersion,
userDefaults: userDefaults,
Expand All @@ -44,7 +43,6 @@ public class AppConfig: CoreAppConfig {

/// This initializer will let you specify all properties.
/// - Parameter regionsBaseURL: The base URL for the Regions server.
/// - Parameter obacoBaseURL: The base URL for the Obaco server.
/// - Parameter apiKey: Your API key for the REST API server.
/// - Parameter appVersion: The version of the app.
/// - Parameter userDefaults: The user defaults object.
Expand All @@ -55,7 +53,6 @@ public class AppConfig: CoreAppConfig {
/// - Parameter regionsAPIPath: The API Path on the Regions server to the regions file.
public init(
regionsBaseURL: URL?,
obacoBaseURL: URL?,
apiKey: String,
appVersion: String,
userDefaults: UserDefaults,
Expand All @@ -69,7 +66,6 @@ public class AppConfig: CoreAppConfig {
self.analytics = analytics
super.init(
regionsBaseURL: regionsBaseURL,
obacoBaseURL: obacoBaseURL,
apiKey: apiKey,
appVersion: appVersion,
userDefaults: userDefaults,
Expand Down
7 changes: 4 additions & 3 deletions OBAKit/Orchestration/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public class Application: CoreApplication, PushServiceDelegate {

/// Handles all deep-linking into the app.
@objc public private(set) lazy var appLinksRouter: AppLinksRouter? = {
let router = AppLinksRouter(baseURL: applicationBundle.deepLinkServerBaseAddress, application: self)
let router = AppLinksRouter(application: self)

router?.showStopHandler = { [weak self] stop in
guard
let self = self,
Expand Down Expand Up @@ -604,7 +605,7 @@ public class Application: CoreApplication, PushServiceDelegate {

/// Feature status of the Obaco service.
public var obaco: FeatureStatus {
switch (config.obacoBaseURL, application?.obacoService) {
switch (application?.regionsService.currentRegion?.sidecarBaseURL, application?.obacoService) {
case (nil, nil): return .off
case (_, nil): return .notRunning
default: return .running
Expand All @@ -622,7 +623,7 @@ public class Application: CoreApplication, PushServiceDelegate {

/// Feature status of Deep Linking.
public var deepLinking: FeatureStatus {
switch (config.obacoBaseURL, application?.appLinksRouter) {
switch (application?.regionsService.currentRegion?.sidecarBaseURL, application?.appLinksRouter) {
case (nil, nil): return .off
case (_, nil): return .notRunning
default: return .running
Expand Down
10 changes: 0 additions & 10 deletions OBAKitCore/Extensions/FoundationExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ public extension Bundle {
/// A helper method for easily accessing the bundle's `NSUserActivityTypes`.
var userActivityTypes: [String]? { optionalValue(for: "NSUserActivityTypes", type: [String].self) }

/// A helper method for accessing the bundle's `DeepLinkServerBaseAddress`
var deepLinkServerBaseAddress: URL? {
guard
let dict = OBAKitConfig,
let str = dict["DeepLinkServerBaseAddress"] as? String
else { return nil }

return URL(string: str)
}

/// A helper method for accessing the bundle's `Donations.Enabled` setting
var donationsEnabled: Bool {
guard let dict = donationsConfig, let val = dict["Enabled"] as? Bool else {
Expand Down
5 changes: 0 additions & 5 deletions OBAKitCore/Orchestration/CoreAppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import CoreLocation
open class CoreAppConfig: NSObject {
public let regionsBaseURL: URL?
public let regionsAPIPath: String?
public let obacoBaseURL: URL?
public let apiKey: String
public let appVersion: String
public let queue: OperationQueue
Expand All @@ -41,7 +40,6 @@ open class CoreAppConfig: NSObject {
) {
self.init(
regionsBaseURL: appBundle.regionsServerBaseAddress!,
obacoBaseURL: appBundle.deepLinkServerBaseAddress,
apiKey: appBundle.restServerAPIKey!,
appVersion: appBundle.appVersion,
userDefaults: userDefaults,
Expand All @@ -55,7 +53,6 @@ open class CoreAppConfig: NSObject {

/// This initializer will let you specify all properties.
/// - Parameter regionsBaseURL: The base URL for the Regions server.
/// - Parameter obacoBaseURL: The base URL for the Obaco server.
/// - Parameter apiKey: Your API key for the REST API server.
/// - Parameter appVersion: The version of the app.
/// - Parameter userDefaults: The user defaults object.
Expand All @@ -65,7 +62,6 @@ open class CoreAppConfig: NSObject {
/// - Parameter regionsAPIPath: The API Path on the Regions server to the regions file.
public init(
regionsBaseURL: URL?,
obacoBaseURL: URL?,
apiKey: String,
appVersion: String,
userDefaults: UserDefaults,
Expand All @@ -76,7 +72,6 @@ open class CoreAppConfig: NSObject {
dataLoader: URLDataLoader
) {
self.regionsBaseURL = regionsBaseURL
self.obacoBaseURL = obacoBaseURL
self.apiKey = apiKey
self.appVersion = appVersion
self.queue = queue
Expand Down
2 changes: 1 addition & 1 deletion OBAKitCore/Orchestration/CoreApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ open class CoreApplication: NSObject,
private func refreshObacoService() {
guard
let region = regionsService.currentRegion,
let baseURL = config.obacoBaseURL
let baseURL = region.sidecarBaseURL
else { return }

let configuration = APIServiceConfiguration(baseURL: baseURL, apiKey: config.apiKey, uuid: userUUID, appVersion: config.appVersion, regionIdentifier: region.regionIdentifier)
Expand Down
4 changes: 1 addition & 3 deletions OBAKitTests/Application/AppConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Nimble

class AppConfigTests: OBATestCase {
let regionsBaseURL = URL(string: "http://www.example.com")!
let obacoBaseURL = URL(string: "http://www.example.com")!

func testAppConfig_creation_propertiesWork() {
let queue = OperationQueue()
Expand All @@ -28,10 +27,9 @@ class AppConfigTests: OBATestCase {
let analytics = AnalyticsMock()
let dataLoader = MockDataLoader(testName: name)

let appConfig = AppConfig(regionsBaseURL: regionsBaseURL, obacoBaseURL: obacoBaseURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: analytics, queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: dataLoader)
let appConfig = AppConfig(regionsBaseURL: regionsBaseURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: analytics, queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: dataLoader)

expect(appConfig.regionsBaseURL) == regionsBaseURL
expect(appConfig.obacoBaseURL) == obacoBaseURL
expect(appConfig.apiKey) == apiKey
expect(appConfig.appVersion) == appVersion
expect(appConfig.queue) == queue
Expand Down
6 changes: 3 additions & 3 deletions OBAKitTests/Application/ApplicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ApplicationTests: OBATestCase {
func configureAuthorizedObjects() -> (MockAuthorizedLocationManager, LocationService, AppConfig) {
let locManager = MockAuthorizedLocationManager(updateLocation: TestData.mockSeattleLocation, updateHeading: TestData.mockHeading)
let locationService = LocationService(userDefaults: UserDefaults(), locationManager: locManager)
let config = AppConfig(regionsBaseURL: regionsURL, obacoBaseURL: obacoURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: AnalyticsMock(), queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: MockDataLoader(testName: name))
let config = AppConfig(regionsBaseURL: regionsURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: AnalyticsMock(), queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: MockDataLoader(testName: name))

return (locManager, locationService, config)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ class ApplicationTests: OBATestCase {
let locManager = LocationManagerMock()
let locationService = LocationService(userDefaults: userDefaults, locationManager: locManager)

let config = AppConfig(regionsBaseURL: regionsURL, obacoBaseURL: obacoURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: AnalyticsMock(), queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: dataLoader)
let config = AppConfig(regionsBaseURL: regionsURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: AnalyticsMock(), queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: dataLoader)

expect(locationService.isLocationUseAuthorized).to(beFalse())

Expand All @@ -160,7 +160,7 @@ class ApplicationTests: OBATestCase {

let locManager = AuthorizableLocationManagerMock(updateLocation: TestData.mockSeattleLocation, updateHeading: TestData.mockHeading)
let locationService = LocationService(userDefaults: UserDefaults(), locationManager: locManager)
let config = AppConfig(regionsBaseURL: regionsURL, obacoBaseURL: obacoURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: AnalyticsMock(), queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: dataLoader)
let config = AppConfig(regionsBaseURL: regionsURL, apiKey: apiKey, appVersion: appVersion, userDefaults: userDefaults, analytics: AnalyticsMock(), queue: queue, locationService: locationService, bundledRegionsFilePath: bundledRegionsPath, regionsAPIPath: regionsAPIPath, dataLoader: dataLoader)
let appDelegate = TestAppDelegate()

expect(locationService.isLocationUseAuthorized).to(beFalse())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MapRegionManagerTests: OBATestCase {
private func makeConfig(locationService: LocationService, bundledRegionsPath: String, dataLoader: MockDataLoader) -> AppConfig {
AppConfig(
regionsBaseURL: regionsURL,
obacoBaseURL: obacoURL,
apiKey: apiKey,
appVersion: appVersion,
userDefaults: userDefaults,
Expand Down
1 change: 0 additions & 1 deletion Tutorials/WhiteLabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ These are parameters specified in your app's `project.yml` file that customizes
OBAKitConfig:
AppGroup: group.org.onebusaway.iphone
BundledRegionsFileName: regions.json
DeepLinkServerBaseAddress: https://onebusaway.co
ExtensionURLScheme: onebusaway
RESTServerAPIKey: org.onebusaway.iphone
RegionsServerBaseAddress: https://regions.onebusaway.org
Expand Down

0 comments on commit 3edb677

Please sign in to comment.