class CookbookClient::Recipe

Attributes

cook_method[RW]
cook_time[RW]
created_at[RW]
cuisine[RW]
cuisine_id[RW]
difficulty[RW]
id[RW]
ingredients[RW]
recipe_type[RW]
recipe_type_id[RW]
title[RW]
updated_at[RW]
user_id[RW]

Public Class Methods

all() click to toggle source

rubocop:enable Metrics/AbcSize, Metrics/MethodLength

# File lib/cookbook_client/recipe.rb, line 25
def self.all
  CookbookClient.format_recipes(
    recipes: JSON.parse(CookbookClient.http.get('/api/v1/recipes/all').body),
    content_class: self
  )
end
destroy(id) click to toggle source
# File lib/cookbook_client/recipe.rb, line 45
def self.destroy(id)
  response = CookbookClient.http.delete("/api/v1/recipes/#{id}")

  if response.status != 200
    raise StandardError, "Error #{response.status} - #{response.body}"
  end

  CookbookClient.format_recipes(
    recipes: JSON.parse(response.body),
    content_class: self
  ).first
end
find(id) click to toggle source
# File lib/cookbook_client/recipe.rb, line 32
def self.find(id)
  response = CookbookClient.http.get("/api/v1/recipes/#{id}/search")

  if response.status != 200
    raise StandardError, "Error #{response.status} - #{response.body}"
  end

  CookbookClient.format_recipes(
    recipes: JSON.parse(response.body),
    content_class: self
  ).first
end
new(info:) click to toggle source

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

# File lib/cookbook_client/recipe.rb, line 7
def initialize(info:)
  @title = info['title']
  @cook_time = info['cook_time']
  @cook_method = info['cook_method']
  @ingredients = info['ingredients']
  @difficulty = info['difficulty']
  @recipe_type = info['recipe_type']
  @cuisine = info['cuisine']
  @id = info['id']
  @created_at = info['created_at']
  @updated_at = info['updated_at']
  @cuisine_id = info['cuisine_id']
  @recipe_type_id = info['recipe_type_id']
  @featured = info['featured']
  @user_id = info['user_id']
end