Code Climate Test Coverage Build Status

NDB-Ruby

This is a simple Ruby wrapper around the National Nutrient Database REST API provided by the United States Department of Agriculture. In general, all of the parameters accepted by the API can be specified through the methods in this gem.

This gem assumes that you want data returned in JSON format. There may be support for XML in the future.

Getting started

Add the gem to your Gemfile:

gem 'ndb-ruby', '~> 0.2.0'

Setting the API Key

All calls to the API require a registered data.gov api_key. If you're using Rails, you can set up your API in an initializer like this:

# config/initializer/ndb-api.rb
NDB.configure do |config|
  config.api_key = ENV["OPEN_GOV_API_KEY"]
end

The Search request is wrapped in a simple .perform method on NDB::Search and can be used like so:

NDB::Search.perform(q: "butter")

Full list of options can be found in the Search Documentation

List

The List request is wrapped in a simple .retrieve method on NDB::List and can be used like so:

NDB::List.retrieve(lt: "n")

Full list of options can be found in the List Documentation

Food Report

The Food Report request is wrapped in a simple .retrieve method on NDB::FoodReport and can be used like so:

NDB::FoodReport.retrieve(ndbno: "01009", type: "b")

Full list of options can be found in the Food Report Documentation

Nutrient Report

The Nutrient Report request is wrapped in a simple .retrieve method on NDB::NutrientReport and can be used like so:

NDB::NutrientReport.retrieve(nutrients: ["205", "204])

Full list of options can be found in the Nutrient Report Documentation