README
Rattrapages Dominguez
Installation
Run npm install dominguez
in a fresh repository to install the module and all the dependencies.
You will also need to run this command in order to perform further tests npm install -g mocha
.
Usage
Run
cd node_module/dominguez/
npm test
npm start
in your folder to lunch the app, and then go to localhost:3000/
on your navigator.
Architecture
Functions
Get user current position & send it to the server & display temperatures in response
function getPosition() {
navigator.geolocation.getCurrentPosition((position) => {
console.log(position.coords.latitude + " " + position.coords.longitude)
let url = "/weather/" + position.coords.latitude + "/" + position.coords.longitude
// retrieve data from server
fetch(url).then(res => res.json()).then(response => {
// clear list
document.getElementById('temperatures').innerHTML = ""
for (var i = 0 ; i < response.weatherTerms.length ; i++) {
// displays retrieved data
document.getElementById('temperatures').innerHTML += '<li class="list-group-item">' + response.weatherTerms[i] + '</li>'
}
})
})
}
Initialize & return tab containing days and hours to retrieve in api's data
initTabTerms: function (hours) {
let terms = []
let day = new Date()
dayStr = date.format(day, 'YYYY-MM-DD')
for(let i=0 ; i < 3 ; i++){
for(let j=0 ; j < 3 ; j++){
terms.push(dayStr + hours[j])
}
day = date.addDays(day, 1)
dayStr = date.format(day, 'YYYY-MM-DD')
}
return terms
},
Contact url api & return deserialized data into json format
getJSONWeatherData: function(urlWeather) {
return fetch(urlWeather).then(res => res.json())
}
Return tab with the 8 next available date
getAvailableDate: function(){
let terms = []
let day = new Date()
dayStr = date.format(day, 'YYYY-MM-DD')
for(let i=0 ; i < 8 ; i++){
terms.push(dayStr)
day = date.addDays(day, 1)
dayStr = date.format(day, 'YYYY-MM-DD')
}
return terms
}
Routes
localhost:3000/rawData
returns raw data display
localhost:3000/temperature/
returns the temperature for the next 3 days on current location
localhost:3000/previsions/:localisation/echeances/
displays available dates
localhost:3000/previsions/:localisation/:echeance/items/
displays all available items ( temperature, pluie, etc. )
localhost:3000/previsions/:localisation/:echeance/:item/
returns selected informations