Skip to content

Instantly share code, notes, and snippets.

@mikecarroll
Created March 22, 2014 16:42
Show Gist options
  • Save mikecarroll/9710128 to your computer and use it in GitHub Desktop.
Save mikecarroll/9710128 to your computer and use it in GitHub Desktop.
Nutritionix Ruby API library
require 'net/http'
class Nutritionix
def initialize(app, key)
@app = app
@key = key
@url = URI.parse('https://api.nutritionix.com/v1_1/search')
end
def search(query)
params = {
appId: @app,
appKey: @key,
limit: 1,
query: query
}
response = JSON.parse Net::HTTP.post_form(@url, params).body
return [ response['max_score'], response['hits'].first ]
rescue
p "Connection error."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment