nutritionix
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -0,1 +1,2 @@ | ||
'use strict'; | ||
require('colors'); | ||
@@ -25,7 +26,13 @@ | ||
request(opts, function (err, res, data) { | ||
if (err || res && res.statusCode >= 400) { | ||
var hasResp = res !== void 0 && res !== null; | ||
var hasError = err !== void 0 && err !== null; | ||
var statusCode = hasResp ? res.statusCode : 'no response from server'; | ||
var reqFailed = hasError || statusCode >= 400; | ||
if (reqFailed) { | ||
var error = err || data || new Error('Bad API Response'); | ||
console.debug('statusCode'.red,res.statusCode.toString().red); | ||
console.debug('statusCode'.red, statusCode.toString().red); | ||
console.debug(stringify(error).red); | ||
@@ -32,0 +39,0 @@ return callback(error, null); |
{ | ||
"name": "nutritionix", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Official Nutritionix NodeJS Client Library", | ||
@@ -23,3 +23,5 @@ "main": "index.js", | ||
], | ||
"author": "api@nutritionix.com", | ||
"author": { | ||
"name": "api@nutritionix.com" | ||
}, | ||
"license": "MIT", | ||
@@ -35,3 +37,7 @@ "bugs": { | ||
"request": "~2.33.0" | ||
} | ||
}, | ||
"readme": "Official Nutritionix NodeJS Client\n==================================\n\n#### NOTE This is still in beta and the API may change until version 1.0\n#### NOTE `v1` of the API is currently not yet implemented\n\n### Installation\n\n```shell\nnpm install nutritionix --save\n```\n\n\n```js\n// Require inside your project\nvar nutritionix = require('nutritionix')({\n appId: 'YOUR_APP_ID',\n appKey: 'YOUR_APP_KEY'\n}, false);\n\n// Second argument false can be changed to true\n// This will tell the library to enter debugging mode\n// and log additional data to the console\n```\n\n### UPC Scan\n\n```js\n// GET https://api.nutritionix.com/v1_1/item?upc=52200004265\nnutritionix.v1_1.item({\n upc: 52200004265\n}, function (err, item) {\n // ...\n});\n```\n\n### Get Item by id\n\n```js\n// GET https://api.nutritionix.com/v1_1/item?upc=52200004265\nnutritionix.v1_1.item({\n id: '5284ebc52504590000003f4a'\n}, function (err, item) {\n // ...\n});\n```\n\n### Get Brand By ID\n\n```js\n// GET https://api.nutritionix.com/v1_1/brand/51db37c3176fe9790a8991f6\nnutritionix.v1_1.brand({\n id: '51db37c3176fe9790a8991f6'\n}, function (err, brand){\n // ...\n});\n```\n\n\n### Standard Search\n\n```js\n// GET https://api.nutritionix.com/v1_1/search/mcdonalds?results=0:1\nnutritionix.v1_1.search.standard({\n phrase: 'mcdonalds',\n results: '0:1'\n}, function (err, results){\n // ...\n});\n```\n\n### NXQL Advanced Search\n\n```js\n// POST https://api.nutritionix.com/v1_1/search -d DATA\nnutritionix.v1_1.search.advanced({\n fields: ['item_name','brand_name'],\n query: 'mcdonalds',\n offset:0,\n limit:1\n}, function (err, results){\n // ...\n});\n```\n\n### Brand Search\n\n```js\n// GET https://api.nutritionix.com/v1_1/brand/search?query=just+salad&auto=true&type=1&min_score=1\nnutritionix.v1_1.search.brand({\n query:'just salad',\n auto:true,\n type:1,\n min_score:1\n}, function (err, results){\n // ...\n});\n```\n\n#### Special thanks\nThank you to [picsoung][1] for allowing us to take over the npm package and inspiring us to create an official nodejs client.\n\n[1]:https://www.npmjs.org/~picsoung", | ||
"readmeFilename": "README.md", | ||
"_id": "nutritionix@0.0.4", | ||
"_from": "nutritionix@" | ||
} |
11418
178