mfp
v0.7.0
Published
A third-party API for accessing MyFitnessPal diary data
Downloads
19
Readme
mfp
A third-party API for accessing MyFitnessPal diary data.
For it to work, you should set your diary privacy status to "public".
Installation
npm install mfp --save
Usage
var mfp = require('mfp');
mfp.fetchSingleDate(username, date, [fields], callback)
Asynchronously scrapes nutrient data from a user's food diary on a given date.
- username
String
- date
String
with format YYYY-MM-DD - fields
String
orArray
String
'all', which will fetch data for all nutrient fieldsArray
of nutrient field names, each aString
. Allowable field names:- 'calories'
- 'carbs'
- 'fat'
- 'protein'
- 'cholesterol'
- 'sodium'
- 'fiber'
- 'sugar'
- callback
Function
- the callback is passed a single argument
data
, which will be anObject
whose keys are the nutrient field names and values are each aNumber
, as well as the date. Eg.{ 'date': '2014-10-05', 'calories': 2078, 'carbs': 98, 'fat': 119, 'saturated fat': 35, 'protein': 153 }
- the callback is passed a single argument
Example 1:
mfp.fetchSingleDate('username', '2014-09-15', 'all', function(data){
console.log(data);
});
Example 2:
mfp.fetchSingleDate('username', '2014-09-15', ['calories', 'protein', 'carbs', 'fat'], function(data){
console.log(data);
});
mfp.fetchDateRange(username, dateStart, dateEnd, [fields], callback)
Asynchronously scrapes nutrient data from a user's food diary on a given date.
- username
String
- dateStart
String
with format YYYY-MM-DD - dateEnd
String
with format YYYY-MM-DD - fields
String
orArray
String
'all', which will fetch data for all nutrient fieldsArray
of nutrient field names, each aString
. Allowable field names:- 'calories'
- 'carbs'
- 'fat'
- 'protein'
- 'cholesterol'
- 'sodium'
- 'fiber'
- 'sugar'
- 'water'
- callback
Function
- the callback is passed a single argument
data
, which will be anObject
with the following format: Eg.
{ username: 'exampleUser', data: [ { 'date': '2014-07-05', 'calories': 2078, 'carbs': 98, 'fat': 119, 'saturated fat': 35, 'protein': 153 }, { 'date': '2014-07-06', 'calories': 2078, 'carbs': 98, 'fat': 119, 'saturated fat': 35, 'protein': 153 }, { 'date': '2014-07-07', 'calories': 2078, 'carbs': 98, 'fat': 119, 'saturated fat': 35, 'protein': 153 } ] }
- the callback is passed a single argument
Example 1:
mfp.fetchDateRange('username', '2014-09-15', '2014-09-18', 'all', function(data){
console.log(data);
});
Example 2:
mfp.fetchDateRange('username', '2014-09-15', '2014-09-18', ['calories', 'protein', 'carbs', 'fat'], function(data){
console.log(data);
});
mfp.diaryStatusCheck(username, callback)
Asynchronously checks the privacy status of a user's food diary.
- username
String
- callback
Function
- the callback is passed a single argument
status
, which will be aString
with the following possible values:- 'public'
- 'private'
- 'invalid user'
- the callback is passed a single argument
Example:
mfp.diaryStatusCheck('username', function(status) {
console.log(status);
});
mfp.apiStatusCheck(callback)
Asynchronously checks to see if all the API functions work correctly. They may cease to work because MyFitnessPal can change the way they present data on their site at any time.
- callback
Function
- the callback is passed a single argument
errors
, which will be anarray
containing the following possiblestring
s:- 'diaryStatusCheck isn't working correctly for public profiles'
- 'diaryStatusCheck isn't working correctly for private profiles'
- 'diaryStatusCheck isn't working correctly for invalid usernames'
- 'fetchSingleDate with all nutrients isn't working correctly'
- 'fetchSingleDate with user-specified nutrients isn't working correctly'
- the callback is passed a single argument
Example:
mfp.apiStatusCheck(function(errors) {
if (errors.length !== 0) {
errors.forEach(function(error){
console.log(error);
});
} else {
console.log("There aren't any errors!");
}
});
Local Dependencies
- request (latest)
- cheerio (latest)
- chai (latest)
Contributing
Feel free to contribute with any of the items in the backlog.
To Contribute via Issue Notice:
- Write up a description of the problem
- I will write a fix correspondingly
To Contribute via Pull Request:
Fork the repo
In lieu of a formal styleguide, take care to maintain the existing coding style.
- Global "strict mode" is enabled for this project.
- Commits should be prefixed appropriately:
- New Features: (feat)
- Bug Fixes: (fix)
- Documentation: (doc)
- Refactoring and Code Cleanup: (refact)
Add unit tests for any new or changed functionality. Write tests in the appropriate spec file in the
test
directorySubmit a pull request to master branch
Development Dependencies
Global
- gulp (latest)
Local
- mocha (latest)
- coveralls (latest)
- gulp (latest)
- gulp-mocha (latest)
- gulp-istanbul (latest)
- gulp-jshint (latest)
- jshint-stylish (latest)
Tests
Run JSHint Linting
gulp lint
Run Tests
gulp test
Automatically lint and test on source file changes
gulp watch
Release History
Currently Using Github Releases since 0.5.5
- 0.1.0 Initial release, diaryStatusCheck()
- 0.1.1 Update documentation, badges/shields
- 0.2.0 Add fetchSingleDate function
- 0.3.0 Add fetchDateRange function. Add 'date' parameter to fetchSingleDate results.
- 0.4.0 Add apiStatusCheck function
- 0.4.1 Fix Critical Bug: add fetchDateRange function and apiStatusCheck to index.js
- 0.4.2 Fix Critical Bug: add chai as local dependency
- 0.5.0 Multiple Enhancements and Fixes:
- Refactored fetchSingleDate - 1.6x faster
- Refactored fetchDateRange - 3.88x faster for 5 days, 6.9x faster for 20 days
- Removed unsupported nutrient fields from fetchSingleDate and fetchDateRange:
- 'saturated fat'
- 'polyunsaturated fat'
- 'monounsaturated fat'
- 'trans fat'
- 'potassium'
- 'carbohydrates'
- 'vitamin a'
- 'vitamin c'
- 'calcium'
- 'iron'
- Fixed occasionally failing apiStatusCheck spec
- 0.5.1 Fix Critical Bug: failing CircleCI build due to file naming issue
- 0.5.2 Update documentation
- 0.5.3 Fix Bug: diaryStatusCheck correctly returns 'invalid user' when hitting 404 page
- 0.5.4 Update dependencies, update tests to use mocha's done() for async tests
- 0.5.5+ (Using Github Releases)
Known Issues
Backlog
- add
exportCSV
function