ndbDatabase.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. angular.module('ndbDatabase', ['ngResource'])
  2. .factory('NDBSearch', ['$resource', '$q', function($resource, $q) {
  3. return $resource('https://api.nal.usda.gov/ndb/search?'+
  4. 'q=:query&ds=Standard+Reference&api_key=:key&fg=:groups&max=:max&offset=:offset', {}, {
  5. get: {method: "GET",
  6. isArray: true,
  7. transformRequest: function(data, headers) {
  8. return angular.extend({}, headers, {'Content-Type': 'application/json'});
  9. },
  10. headers: {
  11. 'Content-Type': 'application/json'
  12. },
  13. transformResponse: function(data, headersGetter, status) {
  14. var json = angular.fromJson(data);
  15. return status < 400 && json.list? json.list.item : json.errors.error;
  16. }
  17. }
  18. });
  19. }]).factory('NDBList', ['$resource', '$q', function($resource, $q) {
  20. return $resource('https://api.nal.usda.gov/ndb/list?'+
  21. 'api_key=:key&lt=:type&nutrients=:nutrients&fg=:groups&max=:max&offset=:offset', {}, {
  22. get: {method: "GET",
  23. isArray: true,
  24. transformRequest: function(data, headers) {
  25. return angular.extend({}, headers, {'Content-Type': 'application/json'});
  26. },
  27. headers: {
  28. 'Content-Type': 'application/json'
  29. },
  30. transformResponse: function(data, headersGetter, status) {
  31. var json = angular.fromJson(data);
  32. return status < 400 && json.list? json.list.item : json.errors.error;
  33. }
  34. }
  35. });
  36. }]).factory('NDBNutrients', ['$resource', '$q', function($resource, $q) {
  37. return $resource('https://api.nal.usda.gov/ndb/nutrients?'+
  38. 'api_key=:key&nbno=:nums&nutrients=:nutrients&fg=:groups&max=:max&offset=:offset', {}, {
  39. get: {method: "GET",
  40. isArray: true,
  41. transformRequest: function(data, headers) {
  42. return angular.extend({}, headers, {'Content-Type': 'application/json'});
  43. },
  44. headers: {
  45. 'Content-Type': 'application/json'
  46. },
  47. transformResponse: function(data, headersGetter, status) {
  48. var json = angular.fromJson(data);
  49. return status < 400 && json.list? json.list.item : json.errors.error;
  50. }
  51. }
  52. });
  53. }]);