Class: Miles::Audio

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/miles/audio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 80) ⇒ Audio

Returns a new instance of Audio.



10
11
12
13
14
15
# File 'lib/miles/audio.rb', line 10

def initialize(host, port=80)
	@host = host
	@port = port
	@base_uri = "#{host}#{port != 80 ? ':' + @port.to_s : ''}"
	self.class.base_uri @base_uri
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



8
9
10
# File 'lib/miles/audio.rb', line 8

def base_uri
  @base_uri
end

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/miles/audio.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/miles/audio.rb', line 8

def port
  @port
end

Instance Method Details

#pauseObject



50
51
52
53
# File 'lib/miles/audio.rb', line 50

def pause
	response = self.class.get('/pause')
	return true
end

#pause_spotifyObject



39
40
41
42
43
# File 'lib/miles/audio.rb', line 39

def pause_spotify
	query = {'action' => 'pause'}
	response = self.class.post('/spotify', :body => query.to_json)
	return JSON.parse(response)
end

#playObject



45
46
47
48
# File 'lib/miles/audio.rb', line 45

def play
	response = self.class.get('/play')
	return true
end

#play_spotify(track_link = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/miles/audio.rb', line 29

def play_spotify(track_link=nil)
	query = {'action' => 'play'}
	if not track_link.nil?
		query['link'] = track_link
	end

	response = self.class.post('/spotify', :body => query.to_json)
	return JSON.parse(response)
end

#say(text) ⇒ Object



17
18
19
20
21
# File 'lib/miles/audio.rb', line 17

def say(text)
	req = {'text' => text}
	response = self.class.post('/say', :body => req.to_json)
	return JSON.parse(response)
end

#search_spotify(query) ⇒ Object



23
24
25
26
27
# File 'lib/miles/audio.rb', line 23

def search_spotify(query)
	query['service'] = 'spotify'
	response = self.class.post('/search', :body => query.to_json)
	return JSON.parse(response)
end

#statusObject



55
56
57
58
# File 'lib/miles/audio.rb', line 55

def status
	response = self.class.get('/status')
	return JSON.parse(response)
end