hjespers / teslams

Tesla node.js apps and javascript libraries using Tesla's HTTP interfaces
BSD 3-Clause "New" or "Revised" License
417 stars 106 forks source link

exports.token never utilized #84

Closed kyrios closed 8 years ago

kyrios commented 9 years ago

Looking at teslams.js it seems to me as if the Authorization token should be accessible from outside the library and is therefore defined as an export. This is very useful to me since it allows caching and therefore avoiding an additional request to the TESLA API when only polling for example /charge_state.

However:

    var portal = 'https://owner-api.teslamotors.com/api/1';
    exports.portal = portal;
    var owner_api = 'https://owner-api.teslamotors.com';
    exports.portal = owner_api;
    var token = '';
    exports.token = token;

Unfortunately I think the '=' copies by value and not by reference. So when accessing the token from outside it is always an empty string.

I would submit a pull request that fixes the issue but wanted to make sure it is not intended behavior.

hjespers commented 8 years ago

The intended behavior is to make the token available from outside the library. The token is not set until the first call to the vehicles() function so it has to be initialized as a null and then updated once the initial login occurs within the function called all(). I added another line to explicitly assign the retrieved token to export.token. I had assumed that the this happened automatically but I guess now. Should work now once I push the 1.0.3 version of Teslams.