Class: Mat::API
- Inherits:
-
Object
- Object
- Mat::API
- Defined in:
- lib/mat/api.rb,
lib/mat/api/config.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #foodstuff(number, nutrient = nil) ⇒ Object
- #foodstuffs(query = nil) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(config = nil) {|@config| ... } ⇒ API
constructor
A new instance of API.
- #nutrient(slug) ⇒ Object
- #nutrients ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/mat/api.rb', line 9 def config @config end |
Instance Method Details
#foodstuff(number, nutrient = nil) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/mat/api.rb', line 17 def foodstuff(number, nutrient = nil) endpoint = "foodstuff/#{number}" endpoint += "?nutrient=#{nutrient}" if nutrient get(endpoint) end |
#foodstuffs(query = nil) ⇒ Object
24 25 26 |
# File 'lib/mat/api.rb', line 24 def foodstuffs(query = nil) query.nil?? get("foodstuff") : get("foodstuff?query=#{URI::encode(query)}") end |
#get(path) ⇒ Object
36 37 38 39 |
# File 'lib/mat/api.rb', line 36 def get(path) response = http_get(path) load_json(response.body) if response && response.body end |
#nutrient(slug) ⇒ Object
28 29 30 |
# File 'lib/mat/api.rb', line 28 def nutrient(slug) get("nutrient/#{slug}") end |
#nutrients ⇒ Object
32 33 34 |
# File 'lib/mat/api.rb', line 32 def nutrients get("nutrient") end |