| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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('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;
- }
- }
- });
- }]);
|