Class: YumConnector

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

Overview

Handles connection using Requests and provides the results to client

Class Method Summary collapse

Class Method Details

.food_by_id(food_id) ⇒ Food

Provides the food from Yummly by its id

Parameters:

  • food_id (String)

    the id of the food on Yummly

Returns:

  • (Food)

    the food recipe from Yummly



21
22
23
24
25
# File 'lib/yum_connector.rb', line 21

def self.food_by_id(food_id)
  return food_id if food_id.eql? 'Empty plate'
  food_json = JSON.parse Request.get_recipe food_id
  Food.new food_json
end

.search(parameters, xp) ⇒ Food

Searches the food according to search parameters from command line

Parameters:

  • parameters (Hash)

    parameters from the command line

  • xp (Integer)

    the XP points of the user

Returns:

  • (Food)

    new food randomly chosen from searched results



8
9
10
11
12
13
14
15
# File 'lib/yum_connector.rb', line 8

def self.search(parameters, xp)
  result = Request.search parameters, xp
  return nil if result.nil?
  searched_result = JSON.parse result
  id = Parser.food_id searched_result['matches'].sample
  food_json = JSON.parse Request.get_recipe id
  Food.new food_json
end