trackTrip

Track updates of a specified trip

trackTrip(tripId: String) : PollCall<TripInfo>

Track updates of a specified trip. This endpoint returns PollCall, which allows you to observe changes to the trip over time.

Parameters

  • tripId: String

Returns

  • PollCall<TripInfo>

Errors

Examples

iOS

let tripService = Karhoo.getTripService()

/* Polling */

// create observer
let tripObserver = Observer<TripInfo> { [weak self] result in
    switch result {
        case .success(let tripInfo):
            print("Trip: \(tripInfo)")
        case .failure(let error):
            // handle error (KarhooError)
    }
}

// create observable
let tripObservable = tripService.trackTrip(tripId: "1234").observable()

// subscribe observer to observable
tripObservable.subscribe(observer: tripObserver)

// unsubscribe observer from observable
tripObservable.unsubscribe(observer: tripObserver)


/* Single Response */

tripService.trackTrip(tripId: "1234").execute { [weak self] result in
    switch result {
        case .success(let tripInfo):
            print("Trip: \(tripInfo)")
        case .failure(let error):
            // handle error (KarhooError)
    }
}

Android

val tripService = KarhooApi.tripService
val tripId = "1234"

// Create observer and handle payload
val tripDetailsObserver = object : Observer<Resource<TripInfo>> {
    override fun onValueChanged(value: Resource<TripInfo>) {
        when (value) {
            is Resource.Success -> print(result.data) //Handle data
            is Resource.Failure -> print(result.error)) //Handle error
        }
    }
}

// Start tracking with default poll time
val tripDetailsObservable = tripsService.trackTrip(tripId).observable().apply {
    tripDetailsObserver?.let {
        subscribe(it)
    }
}

// Unsubscribe from observable
tripDetailsObservable?.apply {
    tripDetailsObserver?.let {
        unsubscribe(it)
    }
}