Skip to content

Commit

Permalink
Adds support for sidecarBaseURL to the Region model
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbrethorst committed Nov 27, 2024
1 parent e7ae2fe commit 833032b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions OBAKitCore/Models/Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class Region: NSObject, Identifiable, Codable {

/// The base URL for making OBA REST API requests.
public let OBABaseURL: URL

/// The base URL for sidecar server (i.e. OneBusAway.co/Obaco) REST API requests
public let sidecarBaseURL: URL?

/// The base URL for making Service Interface for Real Time Information (SIRI) requests.
///
Expand Down Expand Up @@ -162,6 +165,7 @@ public class Region: NSObject, Identifiable, Codable {
case isActive = "active"
case isCustom = "custom"
case isExperimental = "experimental"
case sidecarBaseURL = "sidecarBaseUrl"
case OBABaseURL = "obaBaseUrl"
case siriBaseURL = "siriBaseUrl"
case openTripPlannerURL = "otpBaseUrl"
Expand Down Expand Up @@ -203,6 +207,7 @@ public class Region: NSObject, Identifiable, Codable {
isCustom = true

self.OBABaseURL = OBABaseURL
self.sidecarBaseURL = nil

let bound = RegionBound(lat: coordinateRegion.center.latitude, lon: coordinateRegion.center.longitude, latSpan: coordinateRegion.span.latitudeDelta, lonSpan: coordinateRegion.span.longitudeDelta)
regionBounds = [bound]
Expand Down Expand Up @@ -242,6 +247,7 @@ public class Region: NSObject, Identifiable, Codable {
isCustom = (try? container.decodeIfPresent(Bool.self, forKey: .isCustom)) ?? false

OBABaseURL = try container.decode(URL.self, forKey: .OBABaseURL)
sidecarBaseURL = try? container.decodeIfPresent(URL.self, forKey: .sidecarBaseURL)
siriBaseURL = try? container.decodeIfPresent(URL.self, forKey: .siriBaseURL)
openTripPlannerURL = try? container.decodeIfPresent(URL.self, forKey: .openTripPlannerURL)
stopInfoURL = try? container.decodeIfPresent(URL.self, forKey: .stopInfoURL)
Expand Down Expand Up @@ -281,6 +287,7 @@ public class Region: NSObject, Identifiable, Codable {
try container.encode(isExperimental, forKey: .isExperimental)
try container.encode(isCustom, forKey: .isCustom)
try container.encode(OBABaseURL, forKey: .OBABaseURL)
try container.encode(sidecarBaseURL, forKey: .sidecarBaseURL)
try container.encodeIfPresent(siriBaseURL, forKey: .siriBaseURL)
try container.encodeIfPresent(openTripPlannerURL, forKey: .openTripPlannerURL)
try container.encodeIfPresent(stopInfoURL, forKey: .stopInfoURL)
Expand Down Expand Up @@ -320,6 +327,7 @@ public class Region: NSObject, Identifiable, Codable {
isExperimental == rhs.isExperimental &&
isCustom == rhs.isCustom &&
OBABaseURL == rhs.OBABaseURL &&
sidecarBaseURL == rhs.sidecarBaseURL &&
siriBaseURL == rhs.siriBaseURL &&
openTripPlannerURL == rhs.openTripPlannerURL &&
stopInfoURL == rhs.stopInfoURL &&
Expand Down Expand Up @@ -350,6 +358,7 @@ public class Region: NSObject, Identifiable, Codable {
hasher.combine(isExperimental)
hasher.combine(isCustom)
hasher.combine(OBABaseURL)
hasher.combine(sidecarBaseURL)
hasher.combine(siriBaseURL)
hasher.combine(openTripPlannerURL)
hasher.combine(stopInfoURL)
Expand Down

0 comments on commit 833032b

Please sign in to comment.