Skip to content

Commit 62fbf04

Browse files
Add trip option maxFootpathTime to Efa and maxFootpathDist to Hci (closes #24)
1 parent 6f05821 commit 62fbf04

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Sources/TripKit/Provider/AbstractEfaProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SwiftyJSON
55

66
public class AbstractEfaProvider: AbstractNetworkProvider {
77

8-
override public var supportedQueryTraits: Set<QueryTrait> { return [.maxChanges] }
8+
override public var supportedQueryTraits: Set<QueryTrait> { [.maxChanges, .maxFootpathTime] }
99

1010
let departureMonitorEndpoint: String
1111
let tripEndpoint: String
@@ -1544,7 +1544,7 @@ public class AbstractEfaProvider: AbstractNetworkProvider {
15441544
if useProxFootSearch {
15451545
builder.addParameter(key: "useProxFootSearch", value: 1) // walk if it makes journeys quicker
15461546
}
1547-
builder.addParameter(key: "trITMOTvalue100", value: 10) // maximum time to walk to first or from last stop
1547+
builder.addParameter(key: "trITMOTvalue100", value: tripOptions.maxFootpathTime ?? 10) // maximum time to walk to first or from last stop
15481548

15491549
if let options = tripOptions.options, options.contains(.bike) {
15501550
builder.addParameter(key: "bikeTakeAlong", value: 1)

Sources/TripKit/Provider/AbstractHafasClientInterfaceProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os.log
33

44
public class AbstractHafasClientInterfaceProvider: AbstractHafasProvider {
55

6-
override public var supportedQueryTraits: Set<QueryTrait> { return [.maxChanges, .minChangeTime] }
6+
override public var supportedQueryTraits: Set<QueryTrait> { [.maxChanges, .minChangeTime, .maxFootpathDist] }
77

88
var mgateEndpoint: String
99
var apiVersion: String?
@@ -916,7 +916,7 @@ public class AbstractHafasClientInterfaceProvider: AbstractHafasProvider {
916916
"profile": [
917917
"type": "F",
918918
"linDistRouting": false,
919-
"maxdist": 2000
919+
"maxdist": tripOptions.maxFootpathDist ?? 2000
920920
],
921921
"type": "M",
922922
"meta": meta

Sources/TripKit/Provider/NetworkProvider.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,18 @@ public class TripOptions: NSObject, NSSecureCoding {
142142
public var options: [Option]?
143143
public var maxChanges: Int?
144144
public var minChangeTime: Int? // in minutes
145+
public var maxFootpathTime: Int? // in minutes
146+
public var maxFootpathDist: Int? // in meters
145147

146-
public init(products: [Product]? = nil, optimize: Optimize? = nil, walkSpeed: WalkSpeed? = nil, accessibility: Accessibility? = nil, options: [Option]? = nil, maxChanges: Int? = nil, minChangeTime: Int? = nil) {
148+
public init(products: [Product]? = nil, optimize: Optimize? = nil, walkSpeed: WalkSpeed? = nil, accessibility: Accessibility? = nil, options: [Option]? = nil, maxChanges: Int? = nil, minChangeTime: Int? = nil, maxFootpathTime: Int? = nil, maxFootpathDist: Int? = nil) {
147149
self.products = products
148150
self.optimize = optimize
149151
self.accessibility = accessibility
150152
self.options = options
151153
self.maxChanges = maxChanges
152154
self.minChangeTime = minChangeTime
155+
self.maxFootpathTime = maxFootpathTime
156+
self.maxFootpathDist = maxFootpathDist
153157
}
154158

155159
public required convenience init?(coder aDecoder: NSCoder) {
@@ -162,7 +166,9 @@ public class TripOptions: NSObject, NSSecureCoding {
162166
let options = optionsInt?.compactMap { Option(rawValue: $0) }
163167
let maxChanges = aDecoder.decodeObject(of: NSNumber.self, forKey: PropertyKey.maxChanges) as? Int
164168
let minChangeTime = aDecoder.decodeObject(of: NSNumber.self, forKey: PropertyKey.minChangeTime) as? Int
165-
self.init(products: products, optimize: optimize, walkSpeed: walkSpeed, accessibility: accessibility, options: options, maxChanges: maxChanges, minChangeTime: minChangeTime)
169+
let maxFootpathTime = aDecoder.decodeObject(of: NSNumber.self, forKey: PropertyKey.maxFootpathTime) as? Int
170+
let maxFootpathDist = aDecoder.decodeObject(of: NSNumber.self, forKey: PropertyKey.maxFootpathDist) as? Int
171+
self.init(products: products, optimize: optimize, walkSpeed: walkSpeed, accessibility: accessibility, options: options, maxChanges: maxChanges, minChangeTime: minChangeTime, maxFootpathTime: maxFootpathTime, maxFootpathDist: maxFootpathDist)
166172
}
167173

168174
public func encode(with aCoder: NSCoder) {
@@ -175,6 +181,8 @@ public class TripOptions: NSObject, NSSecureCoding {
175181
aCoder.encode(options?.map { $0.rawValue }, forKey: PropertyKey.options)
176182
aCoder.encode(maxChanges, forKey: PropertyKey.maxChanges)
177183
aCoder.encode(minChangeTime, forKey: PropertyKey.minChangeTime)
184+
aCoder.encode(maxFootpathTime, forKey: PropertyKey.maxFootpathTime)
185+
aCoder.encode(maxFootpathDist, forKey: PropertyKey.maxFootpathDist)
178186
}
179187

180188
struct PropertyKey {
@@ -185,9 +193,11 @@ public class TripOptions: NSObject, NSSecureCoding {
185193
static let options = "options"
186194
static let maxChanges = "maxChanges"
187195
static let minChangeTime = "minChangeTime"
196+
static let maxFootpathTime = "maxFootpathTime"
197+
static let maxFootpathDist = "maxFootpathDist"
188198
}
189199
}
190200

191201
public enum QueryTrait: Int {
192-
case maxChanges, minChangeTime
202+
case maxChanges, minChangeTime, maxFootpathTime, maxFootpathDist
193203
}

0 commit comments

Comments
 (0)