https://github.com/zokioki/usda_fdc
A Ruby interface to the USDA FoodData Central API
https://github.com/zokioki/usda_fdc
Last synced: about 1 year ago
JSON representation
A Ruby interface to the USDA FoodData Central API
- Host: GitHub
- URL: https://github.com/zokioki/usda_fdc
- Owner: zokioki
- License: mit
- Created: 2022-01-27T08:19:53.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-19T07:44:49.000Z (over 2 years ago)
- Last Synced: 2025-03-15T23:57:31.525Z (about 1 year ago)
- Language: Ruby
- Size: 40 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# UsdaFdc
[](https://badge.fury.io/rb/usda_fdc)
A Ruby interface to the USDA [FoodData Central](https://fdc.nal.usda.gov) API.
## Installation
To install the latest release:
$ gem install usda_fdc
To include in a Rails project, add it to the Gemfile:
```ruby
gem 'usda_fdc'
```
## Usage
An API key is required to access the service. You can find details on how to obtain a key [here](https://fdc.nal.usda.gov/api-guide.html#bkmk-3).
Once you have an API key, you're able to make API calls via the client object:
```ruby
client = UsdaFdc::Client.new('your_api_key')
client.food(534358)
#=> { "dataType" => "Branded", "description" => "NUT 'N BERRY MIX", "fdcId" => 534358, ... }
```
You can also configure the default API key globally for all `UsdaFdc::Client` instances:
```ruby
UsdaFdc.configure do |config|
config.api_key = 'your_api_key'
end
```
For more information on interacting with the API, including accepted parameters and response formats, check out the official USDA FDC [API guide](https://fdc.nal.usda.gov/api-guide.html).
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).