Project

ndb-ruby

0.0
No commit activity in last 3 years
No release in over 3 years
Gem to wrap NDB API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

Code Climate Test Coverage Build Status Gem Version

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

Search

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