Class: CookbookClient::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/cookbook_client/recipe.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info:) ⇒ Recipe

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#cook_methodObject

Returns the value of attribute cook_method.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def cook_method
  @cook_method
end

#cook_timeObject

Returns the value of attribute cook_time.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def cook_time
  @cook_time
end

#created_atObject

Returns the value of attribute created_at.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def created_at
  @created_at
end

#cuisineObject

Returns the value of attribute cuisine.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def cuisine
  @cuisine
end

#cuisine_idObject

Returns the value of attribute cuisine_id.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def cuisine_id
  @cuisine_id
end

#difficultyObject

Returns the value of attribute difficulty.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def difficulty
  @difficulty
end

Returns the value of attribute featured.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def featured
  @featured
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def id
  @id
end

#ingredientsObject

Returns the value of attribute ingredients.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def ingredients
  @ingredients
end

#recipe_typeObject

Returns the value of attribute recipe_type.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def recipe_type
  @recipe_type
end

#recipe_type_idObject

Returns the value of attribute recipe_type_id.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def recipe_type_id
  @recipe_type_id
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def updated_at
  @updated_at
end

#user_idObject

Returns the value of attribute user_id.



2
3
4
# File 'lib/cookbook_client/recipe.rb', line 2

def user_id
  @user_id
end

Class Method Details

.allObject

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



25
26
27
28
29
30
# 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) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# 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