Class: Grubber::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/grubber/command.rb

Instance Method Summary collapse

Instance Method Details

#authObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/grubber/command.rb', line 24

def auth
  config = Grubber::Config.load

  say("\nGrubber requires Yelp API v2 credentials")
  say("To learn more go to: http://www.yelp.com/developers")
  if config.has_auth?
    say("\nYelp authentication already set:")
    say("Consumer Key:    #{config.consumer_key}")
    say("Consumer Secret: #{config.consumer_secret}\n")
    say("Token Key:       #{config.token_key}\n")
    say("Token Sec:       #{config.token_secret}\n")
    overwrite = ask('Overwrite? (y,n)')
    return unless overwrite.downcase == 'y'
  end

  c_key = ask("\nConsumer Key: ")
  c_sec = ask('Consumer Secret: ')
  t_key = ask('Token Key: ')
  t_sec = ask('Token Sec: ')

  if Grubber::Config.update_auth(c_key, c_sec, t_key, t_sec)
    say("Complete!", :green)
  else
    say("Failed", :red)
  end
end

#listObject



13
14
15
# File 'lib/grubber/command.rb', line 13

def list
  Presenter.new( Restaurant.all ).present
end

#locateObject



18
19
20
21
# File 'lib/grubber/command.rb', line 18

def locate
  lat, lng = Grubber::Config.update_location
  say "Updated coordinates to: #{lat}, #{lng}", :green
end

#pickObject



8
9
10
# File 'lib/grubber/command.rb', line 8

def pick
  Presenter.new( Restaurant.random ).present
end