function requestWorkoutsForMonth(date) {

	return new Promise((resolve, reject) => {
		let workoutMonth = new Date(date);

		options.path = `/workouts/dashboard.json?month=${date.getMonth() + 1}&year=${date.getFullYear()}`;

		let req = http.request(options, res => {
			//console.log(`STATUS: ${res.statusCode}`);
			//console.log(`HEADERS: ${JSON.stringify(res.headers)}`);

			let data = '';
			res.on('data', chunk => data += chunk);
			res.on('end', () => {
				let workoutData = JSON.parse(data);
				if (workoutData && workoutData.workout_data && Object.keys(workoutData.workout_data.workouts || {}).length) {
					let monthData = [];

					Object.keys(workoutData.workout_data.workouts).forEach(w => {
						monthData = monthData.concat(workoutData.workout_data.workouts[w]);
					});

					console.log(`${monthData.length} workouts found in ${workoutMonth.toDateString()}`);
					resolve(monthData);
				} else {
					reject(new Error(`Workout data not found for ${workoutMonth.toDateString()}`));
				}
			});
		});
		req.on('error', e => reject(e));
		req.end();
	});
}
/**
 * Uses a JSON API to request the workouts for an entire month.
 * @param {Date} date Date object representing the month.
 * @returns {Promise}
 */
Uses a JSON API to request the workouts for an entire month.
@param {Date} date Date object representing the month.
@returns {Promise}
Uses a JSON API to request the workouts for an entire month . @param { Date } date Date object representing the month . @returns { Promise }
function requestWorkoutsForMonth(date) {
	return new Promise((resolve, reject) => {
		let workoutMonth = new Date(date);
		options.path = `/workouts/dashboard.json?month=${date.getMonth() + 1}&year=${date.getFullYear()}`;
		let req = http.request(options, res => {
			let data = '';
			res.on('data', chunk => data += chunk);
			res.on('end', () => {
				let workoutData = JSON.parse(data);
				if (workoutData && workoutData.workout_data && Object.keys(workoutData.workout_data.workouts || {}).length) {
					let monthData = [];
					Object.keys(workoutData.workout_data.workouts).forEach(w => {
						monthData = monthData.concat(workoutData.workout_data.workouts[w]);
					});
					console.log(`${monthData.length} workouts found in ${workoutMonth.toDateString()}`);
					resolve(monthData);
				} else {
					reject(new Error(`Workout data not found for ${workoutMonth.toDateString()}`));
				}
			});
		});
		req.on('error', e => reject(e));
		req.end();
	});
}
function requestWorkoutsForMonth ( date ) { return new Promise ( ( resolve , reject ) => { let workoutMonth = new Date ( date ) ; options . path = ` ${ date . getMonth ( ) + 1 } ${ date . getFullYear ( ) } ` ; let req = http . request ( options , res => { let data = '' ; res . on ( 'data' , chunk => data += chunk ) ; res . on ( 'end' , ( ) => { let workoutData = JSON . parse ( data ) ; if ( workoutData && workoutData . workout_data && Object . keys ( workoutData . workout_data . workouts || { } ) . length ) { let monthData = [ ] ; Object . keys ( workoutData . workout_data . workouts ) . forEach ( w => { monthData = monthData . concat ( workoutData . workout_data . workouts [ w ] ) ; } ) ; console . log ( ` ${ monthData . length } ${ workoutMonth . toDateString ( ) } ` ) ; resolve ( monthData ) ; } else { reject ( new Error ( ` ${ workoutMonth . toDateString ( ) } ` ) ) ; } } ) ; } ) ; req . on ( 'error' , e => reject ( e ) ) ; req . end ( ) ; } ) ; }
Uses a JSON API to request the workouts for an entire month.
Uses a JSON API to request the workouts for an entire month .
//console.log(`STATUS: ${res.statusCode}`); //console.log(`HEADERS: ${JSON.stringify(res.headers)}`);