Class: Lita::Handlers::OnewheelAutomaticPancake

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_automatic_pancake.rb

Instance Method Summary collapse

Instance Method Details

#get_matches(search_term) ⇒ Object



66
67
68
69
70
71
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 66

def get_matches(search_term)
  Lita.logger.debug "searching #{config.pancake_server}/search for {query: #{search_term}}"
  response = RestClient.post "#{config.pancake_server}/search", {query: search_term}
  # Lita.logger.debug "Response: #{response}"
  JSON.parse response
end

#kill(response) ⇒ Object



43
44
45
46
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 43

def kill(response)
  Lita.logger.debug 'Killing'
  kill_sound
end

#kill_soundObject



60
61
62
63
64
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 60

def kill_sound
  uri = "#{config.pancake_server}/kill"
  Lita.logger.debug "Killing!  #{uri}"
  RestClient.post uri, {}
end

#play(response) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 33

def play(response)
  search_term = response.matches[0][0]
  Lita.logger.debug "Search term found #{search_term}"
  list_of_matches = get_matches(search_term)
  chosen_one = list_of_matches.sample
  Lita.logger.debug "#{list_of_matches.count} matches, chose #{chosen_one.to_s}"
  play_file(chosen_one)
  response.reply "Playing #{chosen_one['name']}!"
end

#play_file(chosen_one) ⇒ Object



73
74
75
76
77
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 73

def play_file(chosen_one)
  uri = "#{config.pancake_server}/play/#{chosen_one['id']}"
  Lita.logger.debug "POST to #{config.pancake_server}/play/#{chosen_one['id']}"
  RestClient.post uri, {}
end

#vol_down(response) ⇒ Object



52
53
54
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 52

def vol_down(response)
  RestClient.post "#{config.pancake_server}/vol/down", {}
end

#vol_up(response) ⇒ Object



48
49
50
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 48

def vol_up(response)
  RestClient.post "#{config.pancake_server}/vol/up", {}
end

#youtube(response) ⇒ Object



56
57
58
# File 'lib/lita/handlers/onewheel_automatic_pancake.rb', line 56

def youtube(response)
  RestClient.post "#{config.pancake_server}/youtube", {uri: response.matches[0][0]}
end