demand-bloc-quotes
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published
Karhoo logo

demand-bloc-quotes

BLoC to work with Karhoo Quotes API


License

⚠️ This package is work in progress and can not be used as an independent package.

Installation

npm i @karhoo/demand-bloc-quotes

Usage

 
import { getApi } from '@karhoo/demand-api'
import { QuotesBloc } from '@karhoo/demand-bloc-quotes'
 
const api = getApi({
  url: 'api',
  defaultRequestOptionsGetter: () => ({
    headers: {
      identifier: 'XXXX',
      referrer: 'https://example-referer.com/'
    }
  })
})
 
const quotesSearchParams = {
  originPlaceId: "ChIJpwBVsLIadkgRE767cq0HnXQ",
  destinationPlaceId: "ChIJmdRFlbIadkgRhYudNQm2yOc",
  localTimeOfPickup: "2020-05-20T12:00"
}
 
const quotesBloc = new QuotesBloc(api.quotesService)
 
quotesBloc.filters = {
  numOfLuggage: 2,
  numOfPassengers: 2,
}
 
quotesBloc.matchingQuotes.subscribe((data) => {
  // quotes that accepts 2 passengers and 2 bags
  console.log('Matching quotes', data)
})
 
quotesBloc.otherAvailibleQuotes.subscribe((data) => {
  // all other quotes that did not match filters
  console.log('Other quotes', data)
})
 
quotesBloc.loading.subscribe(isLoading => {
  console.log('isLoading', isLoading)
})
 
quotesBloc.quotesExpired.subscribe(() => {
  console.log('Quotes Expired')
 
  quotesBloc.refreshQuotes() // requests quotes with same search params
})
 
quotesBloc.requestQuotes(quotesSearchParams)
 

Readme

Keywords

Package Sidebar

Install

npm i demand-bloc-quotes

Weekly Downloads

2

Version

2.1.1

License

BSD-2-Clause

Unpacked Size

325 kB

Total Files

41

Last publish

Collaborators

  • karhoo_demand_web