user7425470
user7425470

Reputation: 905

Using a special API call

I wanted to checkout the GoEuro-Api, but I get:

GoEuroAPI is not a constructor

You can give it a try here:

https://runkit.com/npm/goeuro-api

My code:

var GoEuroAPI = require("goeuro-api");

const GoEuroClient = new GoEuroAPI();

var params = {
    "searchOptions": {
        "departurePosition": { "id": 376217 },
        "arrivalPosition": { "id": 377001 },
        "travelModes": ["Flight", "Train", "Bus"],
        "departureDate": "2017-04-08",
        "returnDate": null,
        "passengers": [{ "age": 12 }],
        "userInfo": {
            "identifier": "0.dj87mh4f039",
            "domain": ".com", "locale": "en", "currency": "EUR"
        },
        "abTestParameters": []
    }
};

// Init the search and get flights, trains and buses.
GoEuroClient.search(params)
  .then((response) => {
      GoEuroClient.flights()
        .then(flights => console.log(flights));

      GoEuroClient.trains()
        .then(trains => console.log(trains));

      GoEuroClient.buses()
        .then(buses => console.log(buses));
  })
  .catch((error) => console.log(error));

// Get buses by search_id
GoEuroClient
  .buses({ search_id: id })
  .then(buses => console.log(buses))
  .catch(error => console.log(error));

What is wrong here, what should it be instead ?

Thanks for any help.

Upvotes: 1

Views: 96

Answers (1)

parwatcodes
parwatcodes

Reputation: 6798

while only importing goeuro-api

var GoEuroAPI = require("goeuro-api");

It exposes an object { default: [Function: GoEuroAPI] }

Instead to use the Constructor Function

Do

var GoEuroAPI = require("goeuro-api").default; // exposes a function 
                                               // [Function: GoEuroAPI]

const GoEuroClient = new GoEuroAPI();

Upvotes: 2

Related Questions