status

Track changes of TripState of a specified trip.

status(tripId: String) : PollCall<TripState>

Track changes of TripState of a specified trip. This endpoint returns a PollCall object, which allows you to attach an observer to watch a trips status over time.

Parameters

  • tripId: String

Returns

  • PollCall<TripState>

Errors

Examples

iOS

let tripService = Karhoo.getTripService()

/* Polling */

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

// create observable
let tripStateObservable = status(tripId: "1234").observable()

// subscribe observer to observable
tripStateObservable.subscribe(observer: tripStateObserver)

// unsubscribe observer from observable
tripStateObservable.unsubscribe(observer: tripStateObserver)


/* Single Response */

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

Android

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

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

// Start tracking with default poll time
tripStateObservable = tripsService.status(tripId).observable().apply {
    tripStateObserver?.let { subscribe(it) }
}

// Unsubscribe from observable
tripStateObservable?.apply {
    tripStateObserver?.let {
        unsubscribe(it)
    }
}