| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- angular.module('ndbDatabase', ['ngResource'])
- .factory('NDBSearch', ['$resource', '$q', function($resource, $q) {
- return $resource('https://api.nal.usda.gov/ndb/search?'+
- 'q=:query&ds=Standard+Reference&api_key=:key&fg=:groups&max=:max&offset=:offset', {}, {
- get: {method: "GET",
- isArray: true,
- transformRequest: function(data, headers) {
- return angular.extend({}, headers, {'Content-Type': 'application/json'});
- },
- headers: {
- 'Content-Type': 'application/json'
- },
- transformResponse: function(data, headersGetter, status) {
- var json = angular.fromJson(data);
- return status < 400 && json.list? json.list.item : json.errors.error;
- }
- }
- });
- }]).factory('NDBList', ['$resource', '$q', function($resource, $q) {
- return $resource('https://api.nal.usda.gov/ndb/list?' +
- 'api_key=:key<=:type&nutrients=:nutrients&fg=:groups&max=:max&offset=:offset', {}, {
- get: {method: "GET",
- isArray: true,
- transformRequest: function(data, headers) {
- return angular.extend({}, headers, {'Content-Type': 'application/json'});
- },
- headers: {
- 'Content-Type': 'application/json'
- },
- transformResponse: function(data, headersGetter, status) {
- var json = angular.fromJson(data);
- return status < 400 && json.list? json.list.item : json.errors.error;
- }
- }
- });
- }]).factory('NDBReport', ['$resource', '$q', function($resource, $q) {
- return $resource('https://api.nal.usda.gov/ndb/reports/?api_key=:key&ndbno=:ndbno', {}, {
- get: {method: "GET",
- transformRequest: function(data, headers) {
- return angular.extend({}, headers, {
- 'Content-Type': 'application/json'
- });
- },
- headers: {
- 'Content-Type': 'application/json'
- },
- transformResponse: function(data, headersGetter, status) {
- var json = angular.fromJson(data);
- return status < 400 && json.report.food? json.report.food : json.errors.error;
- }
- }
- });
- }]).factory('NDBNutrients', ['$resource', '$q', function($resource, $q) {
- return $resource('https://api.nal.usda.gov/ndb/nutrients?'+
- 'api_key=:key&nbno=:nums&nutrients=:nutrients&fg=:groups&max=:max&offset=:offset', {}, {
- get: {method: "GET",
- isArray: true,
- transformRequest: function(data, headers) {
- return angular.extend({}, headers, {'Content-Type': 'application/json'});
- },
- headers: {
- 'Content-Type': 'application/json'
- },
- transformResponse: function(data, headersGetter, status) {
- var json = angular.fromJson(data);
- return status < 400 && json.list? json.list.item : json.errors.error;
- }
- }
- });
- }]);
|