Module: Spoonacular

Defined in:
lib/spoonacular/request.rb,
lib/spoonacular/version.rb,
lib/spoonacular/api/base.rb,
lib/spoonacular/api/data.rb,
lib/spoonacular/api/search.rb,
lib/spoonacular/api/compute.rb,
lib/spoonacular/api/extract.rb

Defined Under Namespace

Classes: API

Constant Summary collapse

BASE_PATH =
"https://spoonacular-recipe-food-nutrition-v1.p.mashape.com"
VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_endpoint(method, query) ⇒ Object



5
6
7
# File 'lib/spoonacular/request.rb', line 5

def self.build_endpoint(method, query)
	return "#{BASE_PATH}#{method}?#{query}"
end

.get(options) ⇒ Object



9
10
11
12
13
14
# File 'lib/spoonacular/request.rb', line 9

def self.get(options)
	headers = {"X-Mashape-Key" => options[:key]}
	headers["Accept"] = "application/json" if options[:accept_json]
	response = Unirest.get options[:uri], headers: headers
	return response
end

.post(options) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/spoonacular/request.rb', line 16

def self.post(options)
	headers = {"X-Mashape-Key" => options[:key]}
	headers["Accept"] = "application/json" if options[:accept_json]
	headers["Content-Type"] = "application/json" if options[:content_json]
	headers["Content-Type"] = "application/x-www-form-urlencoded" if options[:content_form]
	params = options[:params]
	response = Unirest.post options[:uri], headers: headers, parameters: params
	return response
end

Instance Method Details

#get_food_information(id, amount, unit) ⇒ Object



19
20
21
22
23
# File 'lib/spoonacular/api/data.rb', line 19

def get_food_information(id, amount, unit)
	method = "/food/ingredients/#{id}/information?amount=#{amount}, unit=#{unit}"
	uri = Spoonacular.build_endpoint(method, "")
	response = Spoonacular.get({key: @key, uri: uri})
end