class CookbookClient::Cuisine
Attributes
id[RW]
name[RW]
Public Class Methods
all()
click to toggle source
# File lib/cookbook_client/cuisine.rb, line 9 def self.all response = CookbookClient.http.get('/api/v1/cuisines') if response.status != 200 raise StandardError, "Error #{response.status} - #{response.body}" end format_cuisines cuisines: JSON.parse(response.body) end
find_by_name(name)
click to toggle source
# File lib/cookbook_client/cuisine.rb, line 19 def self.find_by_name(name) response = CookbookClient.http.get('/api/v1/cuisines/name', name: name) if response.status != 200 raise StandardError, "Error #{response.status} - #{response.body}" end format_cuisines(cuisines: JSON.parse(response.body)).first end
format_cuisines(cuisines:)
click to toggle source
# File lib/cookbook_client/cuisine.rb, line 29 def self.format_cuisines(cuisines:) cuisines = [cuisines] unless cuisines.is_a? Array cuisines.map do |c| new info: c end end
new(info:)
click to toggle source
# File lib/cookbook_client/cuisine.rb, line 4 def initialize(info:) @id = info['id'] @name = info['name'] end