ctucx.git: nimhafas

[nimlang] hafas-client library

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
import ../types
import json

proc parseRemark*(rem: JsonNode): Remark =
  let typeStr = rem{"type"}.getStr()
  if typeStr == "M" or typeStr == "P":
    return (%* {
      "type": %* "status",
      "summary": rem{"txtS"},
      "code": rem{"code"},
      "text": rem{"txtN"},
    }).to(Remark)
  elif typeStr == "L":
    return (%* {
      "type": %* "status",
      "code": %* "alternative-trip",
      "text": rem{"txtN"},
      "tripId": rem{"jid"},
    }).to(Remark)
  elif typeStr == "A" or typeStr == "I" or typeStr == "H":
    return (%* {
      "type": %* "hint",
      "code": rem{"code"},
      "text": rem{"txtN"},
    }).to(Remark)
  else:
    # TODO: parse more accurately
    return (%* {
      "type": %* "status",
      "code": rem{"code"},
      "text": rem{"txtN"},
    }).to(Remark)