Trip

Handles Trip related requests with IMS web services.

Fetch by ID

Parameters:
  • id: The unique ID of the `Trip`
  • expansions: A `Set` of `Expansion`s for the `Trip`. Defaults to an empty set.
The Expansion includes events, scores, geometry, and user.

Concrete example

To fetch a trip by ID one can use following snippet
Swift
Kotlin
let tripService = TripService(identity: identity)
tripService.fetch(id: id,
expansions: expansions then: { result in
guard !result.value.empty else {
// error
return
}
completionHandler(.success(result.value))
})
val service = TripService(identity: identity)
service.fetch(id,
expansions) { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})

Fetch by user

Fetch a Trip collection with expanded detail.
Parameters:
  • user: The user for which trips are being fetched. If nil, fetches the trips for the currently authenticated User. Defaults to nil.
  • filters: A Set of Filters for the request. Defaults to an empty set..
  • expansions: A Set of Expansions for the collection.
The filters include cursor(limit, offset), date(start, end)

Concrete example

To fetch a trip by user one can use following snippet
Swift
Kotlin
let tripService = TripService(identity: identity)
tripService.fetch(user: user,
filters: [Filter],
expansions: expansions,
then: { result in
guard !result.value.empty else {
// error
return
}
completionHandler(.success(result.value))
})
val service = TripService(identity)
service.fetch(user,
filters,
expansions) { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})

Fetch all

Parameters:
  • filters: A Set of Filters for the request. Defaults to an empty set..
  • expansions: A Set of Expansions for the collection.

Concrete example

To fetch all trips one can use following snippet
Swift
Kotlin
let tripService = TripService(identity: identity)
tripService.fetchAll(filters: [Filter],
expansions: expansions then: { result in
guard !result.value.empty else {
// error
return
}
completionHandler(.success(result.value))
})
val service = TripService(identity)
service.fetchAll(filters,
expansions) { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})

Update trip

Parameters:

  • trip: The Trip to update.
  • transportMode: The TransportMode to apply to the Trip.
  • purpose: The Purpose to apply to the Trip.
TransportMode options are:
  • UNKNOWN
  • DRIVER
  • PASSENGER
  • TRAIN
  • BUS
  • AIRPLANE
  • TAXI
  • MOTORCYCLE
  • BOAT
  • WALK
  • BICYCLE
  • PUBLIC_TRANSIT
  • OTHER
The available TransportMode options are:
  • UNKNOWN
  • DRIVER
  • PASSENGER
  • TRAIN
  • BUS
  • AIRPLANE
  • TAXI
  • MOTORCYCLE
  • BOAT
  • WALK
  • BICYCLE
  • PUBLIC_TRANSIT
  • OTHER
The Purposes of the trips can be:
  • UNKNOWN
  • PERSONAL
  • BUSINESS

Concrete example

To update the trip one can use following snippet
Swift
Kotlin
let service = TripService(identity: identity)
service.update(trip,
transportMode: TransportMode,
purpose: purpose { result in
switch result {
case .success(_):
// update successful
case .failure(_):
// error
}
})
val service = TripService(identity)
service.updateTrip(trip,
transportationMode,
purpose) { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})

Fetch trips by vehicle

- Parameters:
  • vehicleId: The id of the vehicle for which we want the list of Trip
  • vehicleTripsLimit: The maximum number of trips
  • shouldExpandScores: If true will provide the scores information inside the Trip object

Concrete example

To fetch trips by vehicle, one can use following snippet
Swift
Kotlin
let service = TripService(identity: identity)
service.fetchTripsByVehicle(vehicleId: vehicleId,
vehicleTripsLimit: vehicleTripsLimit,
shouldExpandScores: shouldExpandScores, then: { result in
guard !result.value.isEmpty else {
// error
return
}
completionHandler(.success(result.value))
})
val service = TripService(identity: identity)
service.fetchTripsByVehicle(vehicleId,
vehicleTripsLimit,
shouldExpandScore) { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})