Skip to content

Commit

Permalink
Follow up breaking changes from SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
r3to committed Apr 30, 2024
1 parent 5fd6d79 commit b1cce85
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
29 changes: 12 additions & 17 deletions SampleApp/OJPSampleApp/LocationSearchByNameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ struct LocationResult: Identifiable {
var coordinates: CLLocationCoordinate2D
}

extension OJPv2.PlaceResult: Identifiable {
public var id: String {
self.place.stopPlace.privateCode.value
}
}

struct LocationSearchByNameView: View {
@State var inputName: String = ""
@State var results: [OJPv2.PlaceResult] = []
Expand All @@ -37,23 +31,24 @@ struct LocationSearchByNameView: View {
Text("Search Stations by Name")
Form {
TextField("Search Name", text: $inputName)
Picker(selection: $limit) {
ForEach(availableRange, id: \.self) {
Text("\($0)").tag($0)
}
} label: {
Text("Limit")
}
// can't define number of results any more
// Picker(selection: $limit) {
// ForEach(availableRange, id: \.self) {
// Text("\($0)").tag($0)
// }
// } label: {
// Text("Limit")
// }
}
List($results) { $stop in
Text(stop.place.stopPlace.stopPlaceName.text) .onTapGesture {
Text(stop.place.stopPlace?.stopPlaceName.text ?? "No Stop Place") .onTapGesture {
self.selectetedPlace = stop
}
}
Map {
ForEach($results) { $stop in
Annotation(stop.place.stopPlace.stopPlaceName.text,
coordinate: stop.place.geoPosition.coordinates) {
Annotation(stop.place.stopPlace?.stopPlaceName.text ?? "No Stop Place",
coordinate: stop.place.geoPosition?.coordinates ?? CLLocationCoordinate2D(latitude: 0, longitude: 0)) {
Circle().onTapGesture {
self.selectetedPlace = stop
}
Expand All @@ -72,7 +67,7 @@ struct LocationSearchByNameView: View {
let ojp = OJP(loadingStrategy: .http(.int))
let t = Task {
do {
results = try await ojp.stations(by: newValue, limit: limit)
results = try await ojp.requestLocations(from: inputName)
print(results)
} catch {
print(error)
Expand Down
9 changes: 6 additions & 3 deletions SampleApp/OJPSampleApp/PlaceDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ struct PlaceDetailView: View {
if let place {
List {
Text("Place").font(.headline)
Text("Name: \(place.place.name.text)")
Text("GeoPosition: (\(place.place.geoPosition.latitude), \(place.place.geoPosition.longitude))")

Text("Name: \(place.place.name?.text ?? "<nil>")")
if let geoPosition = place.place.geoPosition {
Text("GeoPosition: (\(geoPosition.latitude), \(geoPosition.longitude))")
} else {
Text("⚠️ No Geopostion")
}
}
.cornerRadius(10.0)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OJP/APIConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public struct APIConfiguration {

/// TEST environment.
/// - Note: this configuration should only be used for demo / testing purposes. It can change frequently
static let test = Self(apiEndPoint: URL(string: "https://odpch-api.clients.liip.ch/ojp20-test")!, requesterReference: "OJP_Demo_iOS", authBearerToken: "eyJvcmciOiI2M2Q4ODhiMDNmZmRmODAwMDEzMDIwODkiLCJpZCI6IjUzYzAyNWI2ZTRhNjQyOTM4NzMxMDRjNTg2ODEzNTYyIiwiaCI6Im11cm11cjEyOCJ9")
public static let test = Self(apiEndPoint: URL(string: "https://odpch-api.clients.liip.ch/ojp20-test")!, requesterReference: "OJP_Demo_iOS", authBearerToken: "eyJvcmciOiI2M2Q4ODhiMDNmZmRmODAwMDEzMDIwODkiLCJpZCI6IjUzYzAyNWI2ZTRhNjQyOTM4NzMxMDRjNTg2ODEzNTYyIiwiaCI6Im11cm11cjEyOCJ9")

/// INT environment.
/// - Note: this configuration should only be used for demo / testing purposes. It can change frequently
static let int = Self(apiEndPoint: URL(string: "https://odpch-api.clients.liip.ch/ojp20-beta")!, requesterReference: "OJP_Demo_iOS", authBearerToken: "eyJvcmciOiI2M2Q4ODhiMDNmZmRmODAwMDEzMDIwODkiLCJpZCI6IjUzYzAyNWI2ZTRhNjQyOTM4NzMxMDRjNTg2ODEzNTYyIiwiaCI6Im11cm11cjEyOCJ9")
public static let int = Self(apiEndPoint: URL(string: "https://odpch-api.clients.liip.ch/ojp20-beta")!, requesterReference: "OJP_Demo_iOS", authBearerToken: "eyJvcmciOiI2M2Q4ODhiMDNmZmRmODAwMDEzMDIwODkiLCJpZCI6IjUzYzAyNWI2ZTRhNjQyOTM4NzMxMDRjNTg2ODEzNTYyIiwiaCI6Im11cm11cjEyOCJ9")
}
8 changes: 3 additions & 5 deletions Sources/OJP/Models/OJPv2+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Vasile Cotovanu on 20.03.2024.
//

import Foundation
import CoreLocation
import Foundation

public extension OJPv2.Mode {
enum PtMode: String {
Expand All @@ -29,16 +29,14 @@ public extension OJPv2.Mode {
}

extension OJPv2.PlaceResult: GeoAware {

public var coords: Point {
guard let geoPosition = place.geoPosition else { return (long: COORDINATE_FALLBACK, lat: COORDINATE_FALLBACK) }
return (long: geoPosition.longitude, lat: geoPosition.latitude)
}
}

extension OJPv2.GeoPosition {
public var coordinates: CLLocationCoordinate2D {
public extension OJPv2.GeoPosition {
var coordinates: CLLocationCoordinate2D {
CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
}

6 changes: 6 additions & 0 deletions Sources/OJP/Models/OJPv2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,9 @@ public struct OJPv2: Codable {
}
}
}

extension OJPv2.PlaceResult: Identifiable {
public var id: String {
place.stopPlace!.stopPlaceRef // stopPlace be renamed in https://github.com/openTdataCH/ojp-ios/tree/feature/address
}
}
2 changes: 1 addition & 1 deletion Sources/OJP/OJP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class OJP {
return locationInformationDelivery.placeResults
}

private func request(with ojp: OJPv2) async throws -> OJPv2.Response {
func request(with ojp: OJPv2) async throws -> OJPv2.Response {
let ojpXMLData = try encoder.encode(ojp, withRootKey: "OJP", rootAttributes: OJP.requestXMLRootAttributes)
guard String(data: ojpXMLData, encoding: .utf8) != nil else {
throw OJPError.encodingFailed
Expand Down
4 changes: 2 additions & 2 deletions Tests/OJPTests/OjpSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ final class OjpSDKTests: XCTestCase {
dump(locationInformation)
XCTAssertTrue(true)
}

func testParseMinimumRequiredLIRResponse() throws {
let xmlData = try TestHelpers.loadXML(xmlFilename: "lir-minimum-response")
let locationInformation = try OJPDecoder.parseXML(xmlData)
dump(locationInformation)
XCTAssertTrue(true)
}

func testParseRailBusAndUndergroundPtModes() throws {
let xmlData = try TestHelpers.loadXML(xmlFilename: "lir-lausanne")

Expand Down

0 comments on commit b1cce85

Please sign in to comment.