ojp-sdk-next
TypeScript icon, indicating that this package has built-in type declarations

0.20.21 • Public • Published

OJP Javascript SDK

The OJP Javascript SDK is a Javascript/Typescript package used for communication with OJP APIs.

Current Development Status

Javascript SDK branches

Branch NPM Demo App Description
ojp-js#ojp-sdk-legacy ojp-sdk-legacy original SDK, contains dual code for OJP 1.0,2.0
ojp-js#ojp-sdk-next ojp-sdk-next - temporarely, long-term will be published under ojp-sdk under development new SDK code with models derived from XSD schema, this will be the main development reference for OJP JS SDK

Code / Demo App Implementation

Code Place LIR SER TR TIR FR TRR Comments
ojp-sdk-legacy (legacy SDK) - - - TRR is only available for OJP v2.0
ojp-sdk-next (new SDK)
DemoApp Beta legacy legacy legacy ojp-sdk-next ojp-sdk-next ojp-sdk-next legacy is the old SDK (OJP v1 and v2, see above)
  • LIR - LocationInformationRequest
  • SER - StopEventRequest
  • TR - TripRequest
  • TIR - TripInfoRequest
  • FR - FareRequest
  • TRR - TripRefineRequest

Resources

Usage

Note: 26.Mar - a different package name is used for test purpose: ojp-sdk-next. This package will replace the current ojp-sdk package.

  "dependencies": {
    "ojp-shared-types": "0.0.11",
    "ojp-sdk-next": "0.20.21",
  }
import * as OJP from 'ojp-sdk-next';

// ...

// declare the stage config, PROD example below
const httpConfig: OJP.HTTPConfig = {
  url: 'https://api.opentransportdata.swiss/ojp20',
  authToken: 'TOKEN_FROM_opentransportdata.swiss',
};

// define a requestorRef that describes the client
const requestorRef = 'MyExampleTransportApp.v1';

// define the SDK i18n language
const language = 'de'; // de, fr, it, en
const ojpSDK = new OJP.SDK(requestorRef, httpConfig, language);

// build LIR by Name
const searchTerm = 'Bern';
const request1 = OJP.LocationInformationRequest.initWithLocationName(searchTerm);

// build LIR by StopRef
const stopRef = '8507000'; // Bern
const request2 = OJP.LocationInformationRequest.initWithPlaceRef(stopRef);

// build LIR by BBOX
// these are equivalent
let bbox: string | number[] = '7.433259,46.937798,7.475252,46.954805';
bbox = [7.433259, 46.937798, 7.475252, 46.954805];

const request3 =  OJP.LocationInformationRequest.initWithBBOX(bbox, ['stop']);

// fetch the results
async myMethod() {
  // ...
  const response = await this.ojpSDK.fetchLocationInformationRequestResponse(request1);

  if (!response.ok) {
    // handle error
    console.log(response.error);
    return;
  }

  // do something with the value
  comnst placeResults = response.value.placeResult ?? [];
  placeResults.forEach(placeResult => {

  });
}

TBA

License

The project is released under a MIT license.

Copyright (c) 2021 - 2025 Open Data Platform Mobility Switzerland - opentransportdata.swiss.

Readme

Keywords

Package Sidebar

Install

npm i ojp-sdk-next

Weekly Downloads

139

Version

0.20.21

License

MIT

Unpacked Size

119 kB

Total Files

7

Last publish

Collaborators

  • vasile.cotovanu