UNPKG

react-native-here-mobility-sdk

Version:

Offical Here Mobility SDK for react native to access Here's marketplace features

155 lines (144 loc) 5.24 kB
"use strict"; // @flow /********************************************************** * Copyright © 2018 HERE Global B.V. All rights reserved. * **********************************************************/ import { Waypoint, CancellationPolicy, Supplier, RideWaypoints, PriceEstimate, TransitType } from "./Demand"; /** * Base class for ride offers. * @namespace RideOfferBase * @property {TransitType} type optional, The type of the offer. * @property {RideWaypoints } route The suggested route. May be different from the requested route. * @property { number } estimatedPickupTime optional, Estimated pickup time, if provided by the supplier. The time is in milliseconds since Epoch. * @property { number } estimatedDropOffTime optional, Estimated drop-off time, if provided by the supplier. The time is in milliseconds since Epoch. * @property { number } estimatedDurationMs optional, Estimated duration of the ride, in milliseconds, if can be estimated. * @property { PriceEstimate } estimatedPrice optional, Price estimation, if provided by the supplier. */ export type RideOfferBase = { type: TransitType, route: RideWaypoints, estimatedPickupTime?: number, estimatedDropOffTime?: number, estimatedDurationMs?: number, sestimatedPrice?: PriceEstimate }; /** * Taxi Ride offer. * @namespace TaxiRideOffer * @property {string} offerId The offer ID, to be sent to the server. Not applicable for public transport offers. * @property {Supplier} supplier The supplier. * @property {number} expirationTime is in milliseconds since Epoch. * @property {CancellationPolicy} cancellationPolicy Ride cancellation policy. */ export type TaxiRideOffer = RideOfferBase & { offerId: string, supplier: Supplier, expirationTime: number, cancellationPolicy: CancellationPolicy }; /** * Public Transport ride offer. * @namespace PublicTransportRideOffer * @property {number} transfers Number of transport changes to reach the destination. * @property {Array<PublicTransportRouteLeg>} legs A list of transportation sections for the route. */ export type PublicTransportRideOffer = RideOfferBase & { transfers: number, legs: Array<PublicTransportRouteLeg> }; /** * The transport mode of this leg. * @property {string} UNKNOWN Unknown mode. * @property {string} HIGH_SPEED_TRAIN High-speed train. * @property {string} INTERCITY_TRAIN Intercity train. * @property {string} INTER_REGIONAL_TRAIN Inter-regional train. * @property {string} REGIONAL_TRAIN Regional train. * @property {string} CITY_TRAIN City train. * @property {string} BUS Bus. * @property {string} FERRY Ferry or boat. * @property {string} SUBWAY Subway or metro. * @property {string} LIGHT_RAIL Light rail. * @property {string} PRIVATE_BUS Private bus. * @property {string} INCLINED Inclined elevator or Funicular. * @property {string} AERIAL Aerial leg (e.g. Cable car) * @property {string} BUS_RAPID Bus rapid. * @property {string} MONORAIL Monorail. * @property {string} WALK Walking leg. */ export type TransportMode = | "UNKNOWN" | "HIGH_SPEED_TRAIN" | "INTERCITY_TRAIN" | "INTER_REGIONAL_TRAIN" | "REGIONAL_TRAIN" | "CITY_TRAIN" | "BUS" | "FERRY" | "SUBWAY" | "LIGHT_RAIL" | "PRIVATE_BUS" | "INCLINED" | "AERIAL" | "BUS_RAPID" | "MONORAIL" | "WALK"; /** * Leg in the Public Transport Route. * @namespace PublicTransportRouteLeg * @property {TransportMode} transportMode The transport mode of this leg. * @property {number} estimatedDurationMs? The estimated duration of this leg, in milliseconds, if known. * @property {number} length? The length of the leg in meters, if known in advance. * @property {string} lineName? The name of the line. null if transportMode is {@link TransportMode#WALK|#transportmode}, otherwise always exist. * @property {string} operatorName? The operator of the line. * @property {Waypoint} origin The start point of the leg. * @property {number} estimatedDepartureTime? The estimated departure time, if known. Given in milliseconds since epoch. * @property {Waypoint} destination The end point of the leg. * @property {number} estimatedArrivalTime? The estimated arrival time, if known. Given in milliseconds since epoch. */ export type PublicTransportRouteLeg = { transportMode: TransportMode, estimatedDurationMs?: number, length?: number, lineName?: string, operatorName?: string, origin: Waypoint, estimatedDepartureTime?: number, destination: Waypoint, estimatedArrivalTime?: number }; /** * Ride Offer object. */ export class RideOffers { constructor(offers: Array<RideOfferBase>) { this.offers = offers; } /** * An array of rides offers. * @returns An array of ride offers. */ all(): Array<RideOfferBase> { return this.offers; } /** * An array of taxi ride offer. * @returns An array of taxi offers. */ taxiOffers(): Array<TaxiRideOffer> { return this.offers.filter(offer => offer.type === "TAXI"); } /** * An array of public transport ride offer. * @returns An array of public transport ride offers. */ publicTransportOffers(): Array<PublicTransportRideOffer> { return this.offers.filter(offer => offer.type === "PUBLIC_TRANSPORT"); } }