From 27085d1db075566be9dd124a521c2eecf4960443 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 24 Mar 2018 18:18:34 +0100 Subject: [PATCH] add simple profile boilerplate --- docs/profile-boilerplate.js | 44 +++++++++++++++++++++++++++++++++++++ docs/writing-a-profile.md | 2 ++ 2 files changed, 46 insertions(+) create mode 100644 docs/profile-boilerplate.js diff --git a/docs/profile-boilerplate.js b/docs/profile-boilerplate.js new file mode 100644 index 00000000..6b8ae7b0 --- /dev/null +++ b/docs/profile-boilerplate.js @@ -0,0 +1,44 @@ +'use strict' + +// see the ./writing-a-profile.md guide +const products = [ + { + id: 'nationalExp', + mode: 'train', + bitmasks: [1], + name: 'InterCityExpress', + short: 'ICE', + default: true + }, + { + id: 'national', + mode: 'train', + bitmasks: [2], + name: 'InterCity & EuroCity', + short: 'IC/EC', + default: true + } +] + +const transformReqBody = (body) => { + // get these from the recorded app requests + // body.client = { … } + // body.ver = … + // body.auth = { … } + // body.lang = … + return body +} + +const insaProfile = { + // locale: …, + // timezone: …, + // endpoint: …, + transformReqBody, + + products: products, + + journeyLeg: false, + radar: false +} + +module.exports = insaProfile diff --git a/docs/writing-a-profile.md b/docs/writing-a-profile.md index 8bba7cfd..d05caebb 100644 --- a/docs/writing-a-profile.md +++ b/docs/writing-a-profile.md @@ -78,6 +78,8 @@ If you pass this profile into `hafas-client`, the `parseLine` method will overri - Add a function `transformReqBody(body)` to your profile, which assigns them to `body`. - Some profiles have a `checksum` parameter (like [here](https://gist.github.com/derhuerst/2a735268bd82a0a6779633f15dceba33#file-journey-details-1-http-L1)) or two `mic` & `mac` parameters (like [here](https://gist.github.com/derhuerst/5fa86ed5aec63645e5ae37e23e555886#file-1-http-L1)). If you see one of them in your requests, jump to [*Appendix A: checksum, mic, mac*](#appendix-a-checksum-mic-mac). Unfortunately, this is necessary to get the profile working. +You may want to use the [profile boilerplate code](profile-boilerplate.js). + ## 3. Products In `hafas-client`, there's a difference between the `mode` and the `product` field: