Skip to content

Instantly share code, notes, and snippets.

module Spoonacular
class Recipe < Base
attr_accessor :aggregate_likes,
:dairy_free,
:gluten_free,
:id,
:image,
:ingredients,
:instructions,
:ready_in_minutes,
module Spoonacular
class Recipe < Base
attr_accessor :aggregate_likes,
:dairy_free,
:gluten_free,
:id,
:image,
:ingredients,
:instructions,
:ready_in_minutes,
class Request
class << self
def where(resource_path, cache_params, query = {}, options = {})
response, status = get_json(resource_path, cache_params, query)
status == 200 ? response : errors(response)
end
def get(id, cache_params)
response, status = get_json(id, cache_params)
status == 200 ? response : errors(response)
class RecipesController < ApplicationController
def index
@tag = query.fetch(:tags, 'all')
@recipes, @errors = Spoonacular::Recipe.random(query)
end
def show
@recipe = Spoonacular::Recipe.find(params[:id])
end
module Spoonacular
class Ingredient < Base
attr_accessor :id,
:image,
:name,
:amount,
:unit,
:original_string
end
end
module Spoonacular
class Base
attr_accessor :errors
def initialize(args = {})
args.each do |name, value|
attr_name = name.to_s.underscore
send("#{attr_name}=", value) if respond_to?("#{attr_name}=")
end
end
module Spoonacular
class Instruction < Base
attr_accessor :number, :step
end
end
module Spoonacular
class Recipe < Base
attr_accessor :aggregate_likes,
:dairy_free,
:gluten_free,
:id,
:image,
:ingredients,
:instructions,
:ready_in_minutes,
require 'faraday'
require 'json'
class Connection
BASE = 'https://spoonacular-recipe-food-nutrition-v1.p.mashape.com'
def self.api
Faraday.new(url: BASE) do |faraday|
faraday.response :logger
faraday.adapter Faraday.default_adapter
class Request
class << self
def where(resource_path, query = {}, options = {})
response, status = get_json(resource_path, query)
status == 200 ? response : errors(response)
end
def get(id)
response, status = get_json(id)
status == 200 ? response : errors(response)