This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Spoonacular | |
| class Recipe < Base | |
| attr_accessor :aggregate_likes, | |
| :dairy_free, | |
| :gluten_free, | |
| :id, | |
| :image, | |
| :ingredients, | |
| :instructions, | |
| :ready_in_minutes, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Spoonacular | |
| class Instruction < Base | |
| attr_accessor :number, :step | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Spoonacular | |
| class Ingredient < Base | |
| attr_accessor :id, | |
| :image, | |
| :name, | |
| :amount, | |
| :unit, | |
| :original_string | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Spoonacular | |
| class Recipe < Base | |
| attr_accessor :aggregate_likes, | |
| :dairy_free, | |
| :gluten_free, | |
| :id, | |
| :image, | |
| :ingredients, | |
| :instructions, | |
| :ready_in_minutes, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Spoonacular | |
| class Recipe < Base | |
| attr_accessor :aggregate_likes, | |
| :dairy_free, | |
| :gluten_free, | |
| :id, | |
| :image, | |
| :ingredients, | |
| :instructions, | |
| :ready_in_minutes, |