Class: Client

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

Overview

Encapsulate all the main functionality and represents the client using the user database and Yummly API

Instance Method Summary collapse

Instance Method Details

#lastObject

Provides the last recipe of logged user



37
38
39
40
41
42
43
# File 'lib/client.rb', line 37

def last
  user = User.new
  user.read_creddentials
  user.
  last_food = YumConnector.food_by_id user.last
  puts last_food.to_str
end

#login(email, password) ⇒ Object

Login the user using Backendless

Parameters:

  • email (String)

    email of the user

  • password (String)

    password of the user



31
32
33
34
# File 'lib/client.rb', line 31

def (email, password)
  user = User.new
  puts user. email, password
end

#recipe(parameters) ⇒ Object

Provides the recipe for the logged user according to his level and searching parameters

Parameters:

  • parameters (Hash)

    searching parameters from from the command line



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

def recipe(parameters)
  user = User.new
  user.read_creddentials
  user.
  generated_food = YumConnector.search parameters, user.xp
  abort("Sorry, I can't find food for you like that") if generated_food.nil?
  user.update_last_food_id generated_food.id
  puts generated_food.to_str
end

#register(email, password) ⇒ Object

Register the user using Backendless

Parameters:

  • email (String)

    email of the user

  • password (String)

    password of the user



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

def register(email, password)
  user = User.new
  puts user.register email, password
end

#review(rating) ⇒ Object

Reviews the cooked food of the last recipe of logged user



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/client.rb', line 46

def review(rating)
  user = User.new
  user.read_creddentials
  user.
  response = user.review rating
  if response
    puts 'Last food reviewed!'
  else
    puts 'Nothing to review'
  end
end

#userObject

Provides the stats of the user



59
60
61
62
63
64
# File 'lib/client.rb', line 59

def user
  user = User.new
  user.read_creddentials
  user.
  puts user.to_str
end