Skip to content

Commit

Permalink
Merge pull request entur#236 from entur/feature/mobility.getStationsById
Browse files Browse the repository at this point in the history
Added new function mobility.getStationsById()
  • Loading branch information
draperunner authored Sep 13, 2021
2 parents be780cc + b4bd729 commit b6b502a
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/bikes/getBikeRentalStations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ async function example() {
try {
const bikeRentalStations = await enturClient.getBikeRentalStations([
'YBE:VehicleSharingParkingArea:368',
'YBE:VehicleSharingParkingArea:83',
'YOS:VehicleSharingParkingArea:495',
])
console.log(bikeRentalStation)
console.log(bikeRentalStations)
} catch (error) {
console.error(error)
}
Expand Down
30 changes: 30 additions & 0 deletions src/mobility/getStationsById/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { RequestOptions } from '../../http'
import { getServiceConfig, ArgumentConfig } from '../../config'
import { mobilityQuery } from '../../api'

import { Station } from '../types'

import getStationsQuery from './query'

export interface GetStationsByIdParams {
/** Return only stations with the given IDs. */
stationIds: string[]
}

export default function createGetStationsById(argConfig: ArgumentConfig) {
const config = getServiceConfig(argConfig)

return async function getStationsById(
params: GetStationsByIdParams,
options?: RequestOptions,
): Promise<Station[]> {
const data = await mobilityQuery<{ stationsById: Station[] }>(
getStationsQuery,
params,
config,
options,
)

return data?.stationsById || []
}
}
105 changes: 105 additions & 0 deletions src/mobility/getStationsById/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
export default `
query ($stationIds: [String]!) {
stationsById(
ids: $stationIds
) {
id
name {
translation {
language
value
}
}
lat
lon
address
capacity
rentalUris {
android
ios
web
}
numBikesAvailable
numDocksAvailable
isInstalled
isRenting
isReturning
lastReported
system {
id
language
name {
translation {
language
value
}
}
shortName {
translation {
language
value
}
}
operator {
id
name {
translation {
language
value
}
}
}
url
purchaseUrl
startDate
phoneNumber
email
feedContactEmail
timezone
licenseUrl
rentalApps {
ios {
storeUri
discoveryUri
}
android {
storeUri
discoveryUri
}
}
}
pricingPlans {
id
url
name {
translation {
language
value
}
}
currency
price
isTaxable
description {
translation {
language
value
}
}
perKmPricing {
start
rate
interval
end
}
perMinPricing {
start
rate
interval
end
}
surgePricing
}
}
}
`
3 changes: 3 additions & 0 deletions src/mobility/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { ArgumentConfig } from '../config'

import { default as createGetStations } from './getStations'
import { default as createGetStationsById } from './getStationsById'
import { default as createGetVehicles } from './getVehicles'
import { default as createGetOperators } from './getOperators'

export interface MobilityClient {
getOperators: ReturnType<typeof createGetOperators>
getStations: ReturnType<typeof createGetStations>
getStationsById: ReturnType<typeof createGetStationsById>
getVehicles: ReturnType<typeof createGetVehicles>
}

export default function createClient(config: ArgumentConfig): MobilityClient {
return {
getOperators: createGetOperators(config),
getStations: createGetStations(config),
getStationsById: createGetStationsById(config),
getVehicles: createGetVehicles(config),
}
}

0 comments on commit b6b502a

Please sign in to comment.