evgenTraytyak / goeuro-api

:train2: :oncoming_bus: :airplane: :car: A Node.js API for the GoEuro.com
7 stars 1 forks source link

Missing search parameters example #1

Open remidomingues opened 7 years ago

remidomingues commented 7 years ago

The current README do not mention what are the params sent to the search method.

Based on the comments in the code, we should expect something close to the following example, though this code snippet will only get an error 500 from the GoEuro API when sending the request.

Also, the types PositionObject (arrivalPosition, departurePosition) and Array (passengers[].rebates) do not allow us to understand what are the specified types required.

var params = { arrivalPosition: 'Stockholm, Sweden', currency: 'EUR', departurePosition: 'Paris, France', domain: 'com', inboundDate: '2016-12-05T08:00:00.000', locale: 'en', outboundDate: '2016-12-06T08:00:00.000', passengers: [ { age: 32, rebates: [] } ], resultFormat: { splitRoundTrip: true }, searchModes: 'multimode' };

evgenTraytyak commented 7 years ago

@remidomingues I'll try to update README and add some methods asap. But if you need more information about GoEuro API, you can do ARP spoofing for GoEuro mobile app using ettercap and wireshark.

remidomingues commented 7 years ago

Thanks for the advice! We have limited resources of this project, so I'm not sure if we will manage to get some information by spoofing on time. I really appreciate your help on this.

remidomingues commented 7 years ago

Thanks again for advising the ARP spoofing on the mobile app, it gave excellent results. The POST request takes the params below.

Now that we have the structure of the position objects (arrivalPosition and departurePosition) the values of its fields are obtained from the GoEuro position API, e.g. http://api.goeuro.com/api/v2/position/suggest/en/Paris,%20France from which we can extract all relevant information (latitude, longitude, positionId...).

   {
   "arrivalPosition":{
      "fullName":"Nice, France",
      "latitude":43.70313,
      "longitude":7.26608,
      "type":"location",
      "coreCountry":true,
      "countryCode":"FR",
      "positionId":379691,
      "primaryName":"Nice",
      "secondaryName":null
   },
   "currency":"EUR",
   "departurePosition":{
      "fullName":"Paris, France",
      "latitude":48.85341,
      "longitude":2.3488,
      "type":"location",
      "coreCountry":true,
      "countryCode":"FR",
      "positionId":379727,
      "primaryName":"Paris",
      "secondaryName":null
   },
   "domain":"com",
   "inboundDate":"2016-09-18T00:00:00.000",
   "locale":"en",
   "outboundDate":"2016-09-17T00:00:00.000",
   "passengers":[
      {
         "age":18,
         "rebates":[]
      }
   ],
   "resultFormat":{
      "splitRoundTrip":true
   },
   "searchModes":[
      "directtrain",
      "directbus",
      "multimode"
   ]
}
evgenTraytyak commented 7 years ago

@remidomingues if my memory doesn't fail me, in PositionObject only positionId field is required.

remidomingues commented 7 years ago

That's possible, but I tried with positionId only and got an error 500. I had to add most of the parameters for the request to be accepted.

Regarding the methods trains, buses and flights, I observed that the API could return empty results with response.searchModes.(flight|bus|train).status = 'inprogress' when it is still computing the request on the server side. It could be interesting to query the API as long as the computation is not over to get the final results, pulling data like they do on their app. But then we would mostly redevelop all their back-end :')

Here are two methods that might interest you, they retrieve the GoEuro position from a string and update the search parameters with the field obtained:

position.txt