diff --git a/.gitignore b/.gitignore index 35d328e6d61fa10cf76e954c16d272bb6dd0b0f5..b0e61e149d3f1e22de3c1780d094f7d0f4cc9514 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ desktop.ini # Default # /!\ KEEP THIS SECTION THE LAST ONE !.gitkeep +params.md diff --git a/src/index.js b/src/index.js index 3167c381acc85d20f84b575748f6ca3796cd810e..2c461ae7b55aaa27d447ab3d6a3f78f381cf162f 100644 --- a/src/index.js +++ b/src/index.js @@ -11,23 +11,28 @@ const moment = require('moment') //const moment = require('moment') //require('request-debug')(rp) -const baseUrl = process.env.COZY_PARAMETERS.eglBaseURL -const apiAuthKey = process.env.COZY_PARAMETERS.eglAPIAuthKey - module.exports = new BaseKonnector(start) // The start function is run by the BaseKonnector instance only when it got all the account // information (fields). When you run this connector yourself in "standalone" mode or "dev" mode, // the account information come from ./konnector-dev-config.json file -async function start(fields) { +async function start(fields, cozyParameters) { try { // resetting data for demo only // await resetData() + const baseUrl = cozyParameters.secret.eglBaseURL + const apiAuthKey = cozyParameters.secret.eglAPIAuthKey + log('info', 'Authenticating ...') - const response = await authenticate(fields.login, fields.password) + const response = await authenticate( + fields.login, + fields.password, + baseUrl, + apiAuthKey + ) log('info', 'Successfully logged in') log('info', 'Getting data') - const loadProfile = await getData(response) + const loadProfile = await getData(response, baseUrl, apiAuthKey) log('info', 'Saving data to Cozy') storeLoadProfile(loadProfile) } catch (error) { @@ -35,7 +40,7 @@ async function start(fields) { } } -async function authenticate(login, password) { +async function authenticate(login, password, baseUrl, apiAuthKey) { const authRequest = { method: 'POST', uri: baseUrl + '/connect.aspx', @@ -61,7 +66,7 @@ async function authenticate(login, password) { } } -async function getData(response) { +async function getData(response, baseUrl, apiAuthKey) { const dataRequest = { method: 'POST', uri: baseUrl + '/getAllAgregatsByAbonnement.aspx',